873484c45ebf5c82861f90b59fb0e3b436ac723d8ee6e5783b34f547e46630940835757f445edb0bf98193bb255394ffaf0cbe774e9008c9252d5279e57956 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # globby [![Build Status](https://travis-ci.org/sindresorhus/globby.svg?branch=master)](https://travis-ci.org/sindresorhus/globby)
  2. > Extends [glob](https://github.com/isaacs/node-glob) with support for multiple patterns and exposes a Promise API
  3. ## Install
  4. ```
  5. $ npm install --save globby
  6. ```
  7. ## Usage
  8. ```
  9. ├── unicorn
  10. ├── cake
  11. └── rainbow
  12. ```
  13. ```js
  14. const globby = require('globby');
  15. globby(['*', '!cake']).then(paths => {
  16. console.log(paths);
  17. //=> ['unicorn', 'rainbow']
  18. });
  19. ```
  20. ## API
  21. ### globby(patterns, [options])
  22. Returns a Promise for an array of matching paths.
  23. ### globby.sync(patterns, [options])
  24. Returns an array of matching paths.
  25. ### globby.generateGlobTasks(patterns, [options])
  26. Returns an array of objects in the format `{ pattern: string, opts: Object }`, which can be passed as arguments to [`node-glob`](https://github.com/isaacs/node-glob). This is useful for other globbing-related packages.
  27. Note that you should avoid running the same tasks multiple times as they contain a file system cache. Instead, run this method each time to ensure file system changes are taken into consideration.
  28. ### globby.hasMagic(patterns, [options])
  29. Returns a `boolean` of whether there are any special glob characters in the `patterns`.
  30. Note that the options affect the results. If `noext: true` is set, then `+(a|b)` will not be considered a magic pattern. If the pattern has a brace expansion, like `a/{b/c,x/y}`, then that is considered magical, unless `nobrace: true` is set.
  31. #### patterns
  32. Type: `string` `Array`
  33. See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage).
  34. #### options
  35. Type: `Object`
  36. See the `node-glob` [options](https://github.com/isaacs/node-glob#options).
  37. ## Globbing patterns
  38. Just a quick overview.
  39. - `*` matches any number of characters, but not `/`
  40. - `?` matches a single character, but not `/`
  41. - `**` matches any number of characters, including `/`, as long as it's the only thing in a path part
  42. - `{}` allows for a comma-separated list of "or" expressions
  43. - `!` at the beginning of a pattern will negate the match
  44. [Various patterns and expected matches.](https://github.com/sindresorhus/multimatch/blob/master/test.js)
  45. ## Related
  46. - [multimatch](https://github.com/sindresorhus/multimatch) - Match against a list instead of the filesystem
  47. - [glob-stream](https://github.com/wearefractal/glob-stream) - Streaming alternative
  48. - [matcher](https://github.com/sindresorhus/matcher) - Simple wildcard matching
  49. ## License
  50. MIT © [Sindre Sorhus](https://sindresorhus.com)