source: trip-planner-front/node_modules/anymatch/README.md@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.9 KB
Line 
1anymatch [![Build Status](https://travis-ci.org/micromatch/anymatch.svg?branch=master)](https://travis-ci.org/micromatch/anymatch) [![Coverage Status](https://img.shields.io/coveralls/micromatch/anymatch.svg?branch=master)](https://coveralls.io/r/micromatch/anymatch?branch=master)
2======
3Javascript module to match a string against a regular expression, glob, string,
4or function that takes the string as an argument and returns a truthy or falsy
5value. The matcher can also be an array of any or all of these. Useful for
6allowing a very flexible user-defined config to define things like file paths.
7
8__Note: This module has Bash-parity, please be aware that Windows-style backslashes are not supported as separators. See https://github.com/micromatch/micromatch#backslashes for more information.__
9
10
11Usage
12-----
13```sh
14npm install anymatch
15```
16
17#### anymatch(matchers, testString, [returnIndex], [options])
18* __matchers__: (_Array|String|RegExp|Function_)
19String to be directly matched, string with glob patterns, regular expression
20test, function that takes the testString as an argument and returns a truthy
21value if it should be matched, or an array of any number and mix of these types.
22* __testString__: (_String|Array_) The string to test against the matchers. If
23passed as an array, the first element of the array will be used as the
24`testString` for non-function matchers, while the entire array will be applied
25as the arguments for function matchers.
26* __options__: (_Object_ [optional]_) Any of the [picomatch](https://github.com/micromatch/picomatch#options) options.
27 * __returnIndex__: (_Boolean [optional]_) If true, return the array index of
28the first matcher that that testString matched, or -1 if no match, instead of a
29boolean result.
30
31```js
32const anymatch = require('anymatch');
33
34const matchers = [ 'path/to/file.js', 'path/anyjs/**/*.js', /foo.js$/, string => string.includes('bar') && string.length > 10 ] ;
35
36anymatch(matchers, 'path/to/file.js'); // true
37anymatch(matchers, 'path/anyjs/baz.js'); // true
38anymatch(matchers, 'path/to/foo.js'); // true
39anymatch(matchers, 'path/to/bar.js'); // true
40anymatch(matchers, 'bar.js'); // false
41
42// returnIndex = true
43anymatch(matchers, 'foo.js', {returnIndex: true}); // 2
44anymatch(matchers, 'path/anyjs/foo.js', {returnIndex: true}); // 1
45
46// any picomatc
47
48// using globs to match directories and their children
49anymatch('node_modules', 'node_modules'); // true
50anymatch('node_modules', 'node_modules/somelib/index.js'); // false
51anymatch('node_modules/**', 'node_modules/somelib/index.js'); // true
52anymatch('node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // false
53anymatch('**/node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // true
54
55const matcher = anymatch(matchers);
56['foo.js', 'bar.js'].filter(matcher); // [ 'foo.js' ]
57anymatch master* ❯
58
59```
60
61#### anymatch(matchers)
62You can also pass in only your matcher(s) to get a curried function that has
63already been bound to the provided matching criteria. This can be used as an
64`Array#filter` callback.
65
66```js
67var matcher = anymatch(matchers);
68
69matcher('path/to/file.js'); // true
70matcher('path/anyjs/baz.js', true); // 1
71
72['foo.js', 'bar.js'].filter(matcher); // ['foo.js']
73```
74
75Changelog
76----------
77[See release notes page on GitHub](https://github.com/micromatch/anymatch/releases)
78
79- **v3.0:** Removed `startIndex` and `endIndex` arguments. Node 8.x-only.
80- **v2.0:** [micromatch](https://github.com/jonschlinkert/micromatch) moves away from minimatch-parity and inline with Bash. This includes handling backslashes differently (see https://github.com/micromatch/micromatch#backslashes for more information).
81- **v1.2:** anymatch uses [micromatch](https://github.com/jonschlinkert/micromatch)
82for glob pattern matching. Issues with glob pattern matching should be
83reported directly to the [micromatch issue tracker](https://github.com/jonschlinkert/micromatch/issues).
84
85License
86-------
87[ISC](https://raw.github.com/micromatch/anymatch/master/LICENSE)
Note: See TracBrowser for help on using the repository browser.