Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # globule [![Build Status: Linux](https://travis-ci.org/cowboy/node-globule.svg?branch=master)](https://travis-ci.org/cowboy/node-globule) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/i9fnc38q952r9nc0/branch/master?svg=true)](https://ci.appveyor.com/project/gruntjs/node-globule/branch/master)
  2. An easy-to-use wildcard globbing library.
  3. ## Getting Started
  4. Install the module with: `npm install globule`
  5. ```javascript
  6. var globule = require('globule');
  7. var filepaths = globule.find('**/*.js');
  8. ```
  9. ## Documentation
  10. ### globule.find
  11. Returns a unique array of all file or directory paths that match the given globbing pattern(s). This method accepts either comma separated globbing patterns or an array of globbing patterns. Paths matching patterns that begin with `!` will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant. Patterns may be specified as function arguments or as a `src` property of the options object.
  12. ```js
  13. globule.find(patterns [, patterns [, ...]] [, options])
  14. globule.find({src: patterns, /* other options */})
  15. ```
  16. The `options` object supports all [glob][] library options, along with a few extras. These are the most commonly used:
  17. * `src` This property may be used instead of specifying patterns as function arguments.
  18. * `filter` Either a valid [fs.Stats method name](http://nodejs.org/docs/latest/api/fs.html#fs_class_fs_stats) or a function that will be passed the matched `src` filepath and `options` object as arguments. This function should return a `Boolean` value.
  19. * `nonull` Retain globbing patterns in result set even if they fail to match files.
  20. * `matchBase` Patterns without slashes will match just the basename part. Eg. this makes `*.js` work like `**/*.js`.
  21. * `srcBase` Patterns will be matched relative to the specified path instead of the current working directory. This is a synonym for `cwd`.
  22. * `prefixBase` Any specified `srcBase` will be prefixed to all returned filepaths.
  23. [glob]: https://github.com/isaacs/node-glob
  24. ### globule.match
  25. Match one or more globbing patterns against one or more file paths. Returns a uniqued array of all file paths that match any of the specified globbing patterns. Both the `patterns` and `filepaths` arguments can be a single string or array of strings. Paths matching patterns that begin with `!` will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant.
  26. ```js
  27. globule.match(patterns, filepaths [, options])
  28. ```
  29. ### globule.isMatch
  30. This method contains the same signature and logic as the `globule.match` method, but returns `true` if any files were matched, otherwise `false`.
  31. ```js
  32. globule.isMatch(patterns, filepaths [, options])
  33. ```
  34. ### globule.mapping
  35. Given a set of source file paths, returns an array of src-dest file mapping objects. Both src and dest paths may be renamed, depending on the options specified. Patterns may be specified as function arguments or as a `src` property of the options object.
  36. ```js
  37. globule.mapping(filepaths [, filepaths [, ...]] [, options])
  38. globule.mapping({src: filepaths, /* other options */})
  39. ```
  40. In addition to the options the `globule.find` method supports, the options object also supports these properties:
  41. * `srcBase` The directory from which patterns are matched. Any string specified as `srcBase` is effectively stripped from the beginning of all matched paths.
  42. * `destBase` The specified path is prefixed to all `dest` filepaths.
  43. * `ext` Remove anything after (and including) the first `.` in the destination path, then append this value.
  44. * `extDot` Change the behavior of `ext`, `"first"` and `"last"` will remove anything after the first or last `.` in the destination filename, respectively. Defaults to `"first"`.
  45. * `flatten` Remove the path component from all matched src files. The src file path is still joined to the specified destBase.
  46. * `rename` If specified, this function will be responsible for returning the final `dest` filepath. By default, it flattens paths (if specified), changes extensions (if specified) and joins the matched path to the `destBase`.
  47. ### globule.findMapping
  48. This method is a convenience wrapper around the `globule.find` and `globule.mapping` methods.
  49. ```js
  50. globule.findMapping(patterns [, options])
  51. ```
  52. ## Examples
  53. Given the files `foo/a.js` and `foo/b.js`:
  54. ### srcBase and destBase
  55. ```js
  56. globule.find("foo/*.js")
  57. // ["foo/a.js", "foo/b.js"]
  58. globule.find("*.js", {srcBase: "foo"})
  59. // ["a.js", "b.js"]
  60. globule.find({src: "*.js", srcBase: "foo", prefixBase: true})
  61. // ["foo/a.js", "foo/b.js"]
  62. ```
  63. ```js
  64. globule.findMapping("foo/*.js")
  65. // [{src: ["foo/a.js"], dest: "foo/a.js"}, {src: ["foo/b.js"], dest: "foo/b.js"}]
  66. globule.findMapping("foo/*.js", {destBase: "bar"})
  67. // [{src: ["foo/a.js"], dest: "bar/foo/a.js"}, {src: ["foo/b.js"], dest: "bar/foo/b.js"}]
  68. globule.findMapping({src: "*.js", srcBase: "foo", destBase: "bar"})
  69. // [{src: ["foo/a.js"], dest: "bar/a.js"}, {src: ["foo/b.js"], dest: "bar/b.js"}]
  70. ```
  71. ```js
  72. globule.mapping(["foo/a.js", "foo/b.js"])
  73. // [{src: ["foo/a.js"], dest: "foo/a.js"}, {src: ["foo/b.js"], dest: "foo/b.js"}]
  74. globule.mapping(["foo/a.js", "foo/b.js"], {destBase: "bar"})
  75. // [{src: ["foo/a.js"], dest: "bar/foo/a.js"}, {src: ["foo/b.js"], dest: "bar/foo/b.js"}]
  76. globule.mapping("foo/a.js", "foo/b.js", {destBase: "bar"})
  77. // [{src: ["foo/a.js"], dest: "bar/foo/a.js"}, {src: ["foo/b.js"], dest: "bar/foo/b.js"}]
  78. globule.mapping(["a.js", "b.js"], {srcBase: "foo", destBase: "bar"})
  79. // [{src: ["foo/a.js"], dest: "bar/a.js"}, {src: ["foo/b.js"], dest: "bar/b.js"}]
  80. globule.mapping({src: ["a.js", "b.js"], srcBase: "foo", destBase: "bar"})
  81. // [{src: ["foo/a.js"], dest: "bar/a.js"}, {src: ["foo/b.js"], dest: "bar/b.js"}]
  82. ```
  83. ## Contributing
  84. In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
  85. ## Release History
  86. 2020-02-12 - v1.3.1 - Update dependencies.
  87. 2018-05-29 - v1.2.1 - Update dependencies, lodash@4.17.10 to avoid errant security warnings.
  88. 2017-06-10 - v1.2.0 - Update dependencies, lodash@4.17.
  89. 2016-10-23 - v1.1.0 - Update dependencies, lodash@4.16, glob@7.1.
  90. 2016-04-14 - v1.0.0 - Update dependencies, lodash@4.9, glob@7.0, minimatch@3.0. Paths are unix-style with prefixBase enabled.
  91. 2014-01-07 - v0.2.0 - Updated dependencies. Added `src` option. Improved exclusion speed significantly.
  92. 2013-04-11 - v0.1.0 - Initial release.
  93. ## License
  94. Copyright (c) 2018 "Cowboy" Ben Alman
  95. Licensed under the MIT license.