Socket
Socket
Sign inDemoInstall

parse-glob

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-glob

Parse a glob pattern into an object of tokens.


Version published
Weekly downloads
1.8M
decreased by-0.23%
Maintainers
1
Weekly downloads
 
Created
Source

parse-glob NPM version Build Status

Parse a glob pattern into an object of tokens.

BREAKING CHANGES in 2.0

  • all path-related properties are now on the path object
  • all boolean properties are now on the is object
  • adds base property

See the properties section for details.

Install with npm

npm i parse-glob --save
  • parses 1,000+ glob patterns in 29ms (2.3 GHz Intel Core i7)
  • Extensive unit tests (more than 1,000 lines), covering wildcards, globstars, character classes, brace patterns, extglobs, dotfiles and other complex patterns.

See the tests for hundreds of examples.

Usage

var parseGlob = require('parse-glob');
parseGlob('a/b/{c,d}/*.js');

Returns:

{ path:
   { dirname: 'a/b/{c,d}/',
     filename: '*.js',
     basename: '*',
     extname: '.js',
     ext: 'js' },
  is: { glob: true, braces: true, negated: false, globstar: false, 
    dotfile: false, dotdir: false },
  original: 'a/b/{c,d}/*.js',
  pattern: 'a/b/{c,d}/*.js' }

Properties

The object returned by parseGlob has the following properties:

  • pattern: the glob pattern
  • base: when true is passed as the second argument, a base path is extracted and stripped from pattern. See more below
  • original: a copy of the original, unmodified glob pattern
  • path: file path segments
    • path.dirname: directory
    • path.filename: filename, including extension
    • path.basename: filename, without extension
    • path.extname: file extension, with dot
    • path.ext: file extension, without dot
  • is: an object with boolean information about the glob:
    • is.glob: true if the pattern actually a glob pattern
    • is.negated: true if it's a negation pattern (!**/foo.js)
    • is.globstar: true if the pattern has a double star (**)
    • is.dotfile: true if the pattern should match dotfiles
    • is.dotdir: true if the pattern should match dot-directories (like .git)

base property

The base property is created by taking any leading dirname segments in the pattern that do not contain any glob symbols (!*{}?(|)[]). If a base cannot be extracted, the value of base will be an empty string.

Examples

Without base defined:

var tokens = parseGlob('a/b/{c,d}/*.js');
// tokens.base => 'undefined'
// tokens.pattern => 'a/b/{c,d}/*.js'

With base defined:

var tokens = parseGlob('a/b/{c,d}/*.js', true);
// tokens.base => 'a/b'
// tokens.pattern => '{c,d}/*.js'

The resulting object would be:

{ path:
   { dirname: 'a/b/{c,d}/',
     filename: '*.js',
     basename: '*',
     extname: '.js',
     ext: 'js' },
  is: { glob: true, negated: false, globstar: false, 
    dotfile: false, dotdir: false },
  original: 'a/b/{c,d}/*.js',
  pattern: '{c,d}/*.js',
  base: 'a/b' }
  • glob-base: Split a glob into a base path and a pattern.
  • glob-parent: Strips glob magic from a string to provide the parent path
  • is-glob: Returns true if the given string looks like a glob pattern.
  • glob-path-regex: Regular expression for matching the parts of glob pattern.
  • micromatch: Glob matching for javascript/node.js. A faster alternative to minimatch (10-45x faster on avg), with all the features you're used to using in your Grunt and gulp tasks.

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Tests

Install dev dependencies.

npm i -d && npm test

Author

Jon Schlinkert

License

Copyright (c) 2014-2015 Jon Schlinkert
Released under the MIT license


This file was generated by verb-cli on March 04, 2015.

FAQs

Package last updated on 04 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc