/node_modules/minimatch/README.md

https://bitbucket.org/coleman333/smartsite · Markdown · 218 lines · 147 code · 71 blank · 0 comment · 0 complexity · 4a533f04622a9f84dc0a9782f3b8e2b4 MD5 · raw file

  1. # minimatch
  2. A minimal matching utility.
  3. [![Build Status](https://secure.travis-ci.org/isaacs/minimatch.png)](http://travis-ci.org/isaacs/minimatch)
  4. This is the matching library used internally by npm.
  5. Eventually, it will replace the C binding in node-glob.
  6. It works by converting glob expressions into JavaScript `RegExp`
  7. objects.
  8. ## Usage
  9. ```javascript
  10. var minimatch = require("minimatch")
  11. minimatch("bar.foo", "*.foo") // true!
  12. minimatch("bar.foo", "*.bar") // false!
  13. minimatch("bar.foo", "*.+(bar|foo)", { debug: true }) // true, and noisy!
  14. ```
  15. ## Features
  16. Supports these glob features:
  17. * Brace Expansion
  18. * Extended glob matching
  19. * "Globstar" `**` matching
  20. See:
  21. * `man sh`
  22. * `man bash`
  23. * `man 3 fnmatch`
  24. * `man 5 gitignore`
  25. ## Minimatch Class
  26. Create a minimatch object by instanting the `minimatch.Minimatch` class.
  27. ```javascript
  28. var Minimatch = require("minimatch").Minimatch
  29. var mm = new Minimatch(pattern, options)
  30. ```
  31. ### Properties
  32. * `pattern` The original pattern the minimatch object represents.
  33. * `options` The options supplied to the constructor.
  34. * `set` A 2-dimensional array of regexp or string expressions.
  35. Each row in the
  36. array corresponds to a brace-expanded pattern. Each item in the row
  37. corresponds to a single path-part. For example, the pattern
  38. `{a,b/c}/d` would expand to a set of patterns like:
  39. [ [ a, d ]
  40. , [ b, c, d ] ]
  41. If a portion of the pattern doesn't have any "magic" in it
  42. (that is, it's something like `"foo"` rather than `fo*o?`), then it
  43. will be left as a string rather than converted to a regular
  44. expression.
  45. * `regexp` Created by the `makeRe` method. A single regular expression
  46. expressing the entire pattern. This is useful in cases where you wish
  47. to use the pattern somewhat like `fnmatch(3)` with `FNM_PATH` enabled.
  48. * `negate` True if the pattern is negated.
  49. * `comment` True if the pattern is a comment.
  50. * `empty` True if the pattern is `""`.
  51. ### Methods
  52. * `makeRe` Generate the `regexp` member if necessary, and return it.
  53. Will return `false` if the pattern is invalid.
  54. * `match(fname)` Return true if the filename matches the pattern, or
  55. false otherwise.
  56. * `matchOne(fileArray, patternArray, partial)` Take a `/`-split
  57. filename, and match it against a single row in the `regExpSet`. This
  58. method is mainly for internal use, but is exposed so that it can be
  59. used by a glob-walker that needs to avoid excessive filesystem calls.
  60. All other methods are internal, and will be called as necessary.
  61. ## Functions
  62. The top-level exported function has a `cache` property, which is an LRU
  63. cache set to store 100 items. So, calling these methods repeatedly
  64. with the same pattern and options will use the same Minimatch object,
  65. saving the cost of parsing it multiple times.
  66. ### minimatch(path, pattern, options)
  67. Main export. Tests a path against the pattern using the options.
  68. ```javascript
  69. var isJS = minimatch(file, "*.js", { matchBase: true })
  70. ```
  71. ### minimatch.filter(pattern, options)
  72. Returns a function that tests its
  73. supplied argument, suitable for use with `Array.filter`. Example:
  74. ```javascript
  75. var javascripts = fileList.filter(minimatch.filter("*.js", {matchBase: true}))
  76. ```
  77. ### minimatch.match(list, pattern, options)
  78. Match against the list of
  79. files, in the style of fnmatch or glob. If nothing is matched, and
  80. options.nonull is set, then return a list containing the pattern itself.
  81. ```javascript
  82. var javascripts = minimatch.match(fileList, "*.js", {matchBase: true}))
  83. ```
  84. ### minimatch.makeRe(pattern, options)
  85. Make a regular expression object from the pattern.
  86. ## Options
  87. All options are `false` by default.
  88. ### debug
  89. Dump a ton of stuff to stderr.
  90. ### nobrace
  91. Do not expand `{a,b}` and `{1..3}` brace sets.
  92. ### noglobstar
  93. Disable `**` matching against multiple folder names.
  94. ### dot
  95. Allow patterns to match filenames starting with a period, even if
  96. the pattern does not explicitly have a period in that spot.
  97. Note that by default, `a/**/b` will **not** match `a/.d/b`, unless `dot`
  98. is set.
  99. ### noext
  100. Disable "extglob" style patterns like `+(a|b)`.
  101. ### nocase
  102. Perform a case-insensitive match.
  103. ### nonull
  104. When a match is not found by `minimatch.match`, return a list containing
  105. the pattern itself if this option is set. When not set, an empty list
  106. is returned if there are no matches.
  107. ### matchBase
  108. If set, then patterns without slashes will be matched
  109. against the basename of the path if it contains slashes. For example,
  110. `a?b` would match the path `/xyz/123/acb`, but not `/xyz/acb/123`.
  111. ### nocomment
  112. Suppress the behavior of treating `#` at the start of a pattern as a
  113. comment.
  114. ### nonegate
  115. Suppress the behavior of treating a leading `!` character as negation.
  116. ### flipNegate
  117. Returns from negate expressions the same as if they were not negated.
  118. (Ie, true on a hit, false on a miss.)
  119. ## Comparisons to other fnmatch/glob implementations
  120. While strict compliance with the existing standards is a worthwhile
  121. goal, some discrepancies exist between minimatch and other
  122. implementations, and are intentional.
  123. If the pattern starts with a `!` character, then it is negated. Set the
  124. `nonegate` flag to suppress this behavior, and treat leading `!`
  125. characters normally. This is perhaps relevant if you wish to start the
  126. pattern with a negative extglob pattern like `!(a|B)`. Multiple `!`
  127. characters at the start of a pattern will negate the pattern multiple
  128. times.
  129. If a pattern starts with `#`, then it is treated as a comment, and
  130. will not match anything. Use `\#` to match a literal `#` at the
  131. start of a line, or set the `nocomment` flag to suppress this behavior.
  132. The double-star character `**` is supported by default, unless the
  133. `noglobstar` flag is set. This is supported in the manner of bsdglob
  134. and bash 4.1, where `**` only has special significance if it is the only
  135. thing in a path part. That is, `a/**/b` will match `a/x/y/b`, but
  136. `a/**b` will not.
  137. If an escaped pattern has no matches, and the `nonull` flag is set,
  138. then minimatch.match returns the pattern as-provided, rather than
  139. interpreting the character escapes. For example,
  140. `minimatch.match([], "\\*a\\?")` will return `"\\*a\\?"` rather than
  141. `"*a?"`. This is akin to setting the `nullglob` option in bash, except
  142. that it does not resolve escaped pattern characters.
  143. If brace expansion is not disabled, then it is performed before any
  144. other interpretation of the glob pattern. Thus, a pattern like
  145. `+(a|{b),c)}`, which would not be valid in bash or zsh, is expanded
  146. **first** into the set of `+(a|b)` and `+(a|c)`, and those patterns are
  147. checked for validity. Since those two are valid, matching proceeds.