0e05f0aef2b55d34ecec04e4b0fb18db8e63eb1c41fb5dc5831d1ea76a8e2659cd763423b0e5b1be0355d4fc7c8b7ca84ac702c326abc4c6b5f3c86f7802a7 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # parse-glob [![NPM version](https://badge.fury.io/js/parse-glob.svg)](http://badge.fury.io/js/parse-glob) [![Build Status](https://travis-ci.org/jonschlinkert/parse-glob.svg)](https://travis-ci.org/jonschlinkert/parse-glob)
  2. > Parse a glob pattern into an object of tokens.
  3. **Changes from v1.0.0 to v3.0.4**
  4. * all path-related properties are now on the `path` object
  5. * all boolean properties are now on the `is` object
  6. * adds `base` property
  7. See the [properties](#properties) section for details.
  8. Install with [npm](https://www.npmjs.com/)
  9. ```sh
  10. $ npm i parse-glob --save
  11. ```
  12. * parses 1,000+ glob patterns in 29ms (2.3 GHz Intel Core i7)
  13. * Extensive [unit tests](./test.js) (more than 1,000 lines), covering wildcards, globstars, character classes, brace patterns, extglobs, dotfiles and other complex patterns.
  14. See the tests for [hundreds of examples](./test.js).
  15. ## Usage
  16. ```js
  17. var parseGlob = require('parse-glob');
  18. ```
  19. **Example**
  20. ```js
  21. parseGlob('a/b/c/**/*.{yml,json}');
  22. ```
  23. **Returns:**
  24. ```js
  25. { orig: 'a/b/c/**/*.{yml,json}',
  26. is:
  27. { glob: true,
  28. negated: false,
  29. extglob: false,
  30. braces: true,
  31. brackets: false,
  32. globstar: true,
  33. dotfile: false,
  34. dotdir: false },
  35. glob: '**/*.{yml,json}',
  36. base: 'a/b/c',
  37. path:
  38. { dirname: 'a/b/c/**/',
  39. basename: '*.{yml,json}',
  40. filename: '*',
  41. extname: '.{yml,json}',
  42. ext: '{yml,json}' } }
  43. ```
  44. ## Properties
  45. The object returned by parseGlob has the following properties:
  46. * `orig`: a copy of the original, unmodified glob pattern
  47. * `is`: an object with boolean information about the glob:
  48. - `glob`: true if the pattern actually a glob pattern
  49. - `negated`: true if it's a negation pattern (`!**/foo.js`)
  50. - `extglob`: true if it has extglobs (`@(foo|bar)`)
  51. - `braces`: true if it has braces (`{1..2}` or `.{txt,md}`)
  52. - `brackets`: true if it has POSIX brackets (`[[:alpha:]]`)
  53. - `globstar`: true if the pattern has a globstar (double star, `**`)
  54. - `dotfile`: true if the pattern should match dotfiles
  55. - `dotdir`: true if the pattern should match dot-directories (like `.git`)
  56. * `glob`: the glob pattern part of the string, if any
  57. * `base`: the non-glob part of the string, if any
  58. * `path`: file path segments
  59. - `dirname`: directory
  60. - `basename`: file name with extension
  61. - `filename`: file name without extension
  62. - `extname`: file extension with dot
  63. - `ext`: file extension without dot
  64. ## Related
  65. * [glob-base](https://www.npmjs.com/package/glob-base): Returns an object with the (non-glob) base path and the actual pattern. | [homepage](https://github.com/jonschlinkert/glob-base)
  66. * [glob-parent](https://www.npmjs.com/package/glob-parent): Strips glob magic from a string to provide the parent path | [homepage](https://github.com/es128/glob-parent)
  67. * [glob-path-regex](https://www.npmjs.com/package/glob-path-regex): Regular expression for matching the parts of glob pattern. | [homepage](https://github.com/regexps/glob-path-regex)
  68. * [is-glob](https://www.npmjs.com/package/is-glob): Returns `true` if the given string looks like a glob pattern. | [homepage](https://github.com/jonschlinkert/is-glob)
  69. * [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just… [more](https://www.npmjs.com/package/micromatch) | [homepage](https://github.com/jonschlinkert/micromatch)
  70. ## Contributing
  71. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/parse-glob/issues/new).
  72. ## Tests
  73. Install dev dependencies:
  74. ```sh
  75. $ npm i -d && npm test
  76. ```
  77. ## Author
  78. **Jon Schlinkert**
  79. + [github/jonschlinkert](https://github.com/jonschlinkert)
  80. + [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
  81. ## License
  82. Copyright © 2014-2015 Jon Schlinkert
  83. Released under the MIT license.
  84. ***
  85. _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 22, 2015._