GlobPattern

0.1.1

Swift package to parse and evaluate glob patterns
ChimeHQ/GlobPattern

What's New

v0.1.1

2023-06-26T11:07:11Z
  • Sendable conformances

Build Status License Platforms Documentation

GlobPattern

Swift package to parse and evaluate glob patterns

Why does this exist?

Glob patterns can be matched with the C function fnmatch, and files can be located with glob so why make this at all?

Well, it turns out that a bunch of systems use "glob" patterns that do not follow the actual syntax rules of glob. The most common one is grouping, which is all handled by the shell. I've encountered this in a number of places, notably Language Server Protocol. I'm not sure if this is just an oversight, but these patterns won't actually work right with the C library functions.

This provides both parsing and evaluation, making it much more efficient than relying on glob + shell expansion. It's also just more convenient.

Supported Modes:

  • strict: provides identical results to fnmatch
  • grouping: patterns with {} grouping (used by LSP)
  • editorconfig: patterns with {} grouping and {} ranges (see the editorconfig spec)

Usage

let pattern = Glob.pattern("file.{js,py}", mode: .grouping)

let result = pattern.match("file.js")

Contributing and Collaboration

I prefer collaboration, and would love to find ways to work together if you have a similar project.

I prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.

Suggestions and Feedback

I'd love to hear from you! Get in touch via an issue or pull request.

By participating in this project you agree to abide by the Contributor Code of Conduct.

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Apr 14 2024 00:54:04 GMT-0900 (Hawaii-Aleutian Daylight Time)