GithubHelp home page GithubHelp logo

globus's Introduction

Globus

Clojars Project cljdoc badge

Bash-like globbing patterns for Clojure(Script).

Supported pattern language constructs:

  • ?: matches any single character
  • *: matches any string, including the empty string
  • [qwe]: matches any single character in #{\q \w \e}
  • [^qwe] or [!qwe]: matches any single character not in #{\q \w \e}
  • [a-f]: matches any single character between \a and \f (inclusive)
  • {one,two,three}: matches anything that any of the patterns one, two and three would match. This one is has slightly different semantics than what e.g. bash does (because in bash curly braces are not actually a part of the matching engine)

See the tests for more details and examples.

Usage

(require '[globus.core :as glob])

;; check if a string is a glob pattern (contains special symbols)
(glob/glob? "abc") ; => false
(glob/glob? "ab?c") ; => true

;; filter a sequence of strings
(glob/glob "a*" ["aaa" "bb" "cccc" "defg"]) ; => ("aaa")
(glob/glob "[^a]???" ["aaa" "bb" "cccc" "defg"]) ; => ("cccc" "defg")

;; ignorecase
(glob/glob "A*" ["aaa" "bb" "cccc" "defg"]) ; => ()
(glob/glob "A*" ["aaa" "bb" "cccc" "defg"] {:ignorecase true}) ; => ("aaa")

;; convert a pattern to a (string representation of a) regular expression
(glob/pattern->regex "{a.*,*b}") ; => "(?:(?:a\\..*)|(?:.*b))"

;; enumerate all possible expansions of a pattern
(glob/explode "[ab]{cd,efg,hi[j-m]}")
; =>
; ["acd"
;  "aefg"
;  "ahij"
;  "ahik"
;  "ahil"
;  "ahim"
;  "bcd"
;  "befg"
;  "bhij"
;  "bhik"
;  "bhil"
;  "bhim"]

;; that fails for patterns that cannot be expanded (contain `*`, `?` or
;; `[^...])
(glob/explode "abc*") ; Exception is thrown

Contributing

Run the project's tests:

$ clojure -T:build test
$ clojure -T:build test-node # ClojureScript tests

License

Copyright © 2022-2024 Suprematic

Distributed under the Eclipse Public License.

globus's People

Contributors

aav avatar jsn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

jsn

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.