glob-regex
Tiny glob->regex converter
Last updated 7 years ago by aleclarson .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install glob-regex 
SYNC missed versions from official npm registry.

glob-regex

npm Bundle size Install size Donate

Convert a glob to a RegExp object.

  • Any periods are escaped (. -> \\.)
  • * and ** are replaced
  • Always start with ^ and end with $
  • All RegExp syntax is valid
  • Path separators are auto-escaped by new RegExp
const globRegex = require('glob-regex')

// Match no directory.
let re = globRegex('*.js')
re.test('a.js') // => true
re.test('a.css') // => false
re.test('a/b.js') // => false

// Use ? operator for optional character.
re = globRegex('*.jsx?')
re.test('a.js') // => true
re.test('b.jsx') // => true

// Match any directory.
re = globRegex('**.css')
re.test('a.css') // => true
re.test('a/b.css') // => true

// Match any directory and specific name.
re = globRegex('**/a.css')
re.test('a.css') // => true
re.test('b/a.css') // => true

// Use | operator to match multiple values.
re = globRegex('*.(js|css)')
re.test('a.js') // => true
re.test('a.css') // => true

Use globRegex.replace() to transform a glob into a RegExp-compatible string.

NOTE: It's not recommended to use globRegex(array) if you need the exec method, since the result will be difficult to make use of. Using the test method works great, though!

Current Tags

  • 0.3.2                                ...           latest (7 years ago)

9 Versions

  • 0.3.2                                ...           7 years ago
  • 0.3.1                                ...           7 years ago
  • 0.3.0                                ...           8 years ago
  • 0.2.2                                ...           8 years ago
  • 0.2.1                                ...           8 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.1                                ...           8 years ago
  • 0.1.0                                ...           8 years ago
  • 0.0.1                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |