Upgrade Ava to v4
This commit is contained in:
parent
9a40cc5274
commit
ce89f1b611
1153 changed files with 27264 additions and 95308 deletions
181
node_modules/matcher/index.d.ts
generated
vendored
181
node_modules/matcher/index.d.ts
generated
vendored
|
|
@ -1,85 +1,144 @@
|
|||
declare namespace matcher {
|
||||
interface Options {
|
||||
/**
|
||||
Treat uppercase and lowercase characters as being the same.
|
||||
export interface Options {
|
||||
/**
|
||||
Treat uppercase and lowercase characters as being the same.
|
||||
|
||||
Ensure you use this correctly. For example, files and directories should be matched case-insensitively, while most often, object keys should be matched case-sensitively.
|
||||
Ensure you use this correctly. For example, files and directories should be matched case-insensitively, while most often, object keys should be matched case-sensitively.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly caseSensitive?: boolean;
|
||||
}
|
||||
@default false
|
||||
|
||||
@example
|
||||
```
|
||||
import {isMatch} from 'matcher';
|
||||
|
||||
isMatch('UNICORN', 'UNI*', {caseSensitive: true});
|
||||
//=> true
|
||||
|
||||
isMatch('UNICORN', 'unicorn', {caseSensitive: true});
|
||||
//=> false
|
||||
|
||||
isMatch('unicorn', ['tri*', 'UNI*'], {caseSensitive: true});
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
readonly caseSensitive?: boolean;
|
||||
/**
|
||||
Require all negated patterns to not match and any normal patterns to match at least once. Otherwise, it will be a no-match condition.
|
||||
|
||||
@default false
|
||||
|
||||
@example
|
||||
```
|
||||
import {matcher} from 'matcher';
|
||||
|
||||
// Find text strings containing both "edge" and "tiger" in arbitrary order, but not "stunt".
|
||||
const demo = (strings) => matcher(strings, ['*edge*', '*tiger*', '!*stunt*'], {allPatterns: true});
|
||||
|
||||
demo(['Hey, tiger!', 'tiger has edge over hyenas', 'pushing a tiger over the edge is a stunt']);
|
||||
//=> ['tiger has edge over hyenas']
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import {matcher} from 'matcher';
|
||||
|
||||
matcher(['foo', 'for', 'bar'], ['f*', 'b*', '!x*'], {allPatterns: true});
|
||||
//=> ['foo', 'for', 'bar']
|
||||
|
||||
matcher(['foo', 'for', 'bar'], ['f*'], {allPatterns: true});
|
||||
//=> []
|
||||
```
|
||||
*/
|
||||
readonly allPatterns?: boolean;
|
||||
}
|
||||
|
||||
declare const matcher: {
|
||||
/**
|
||||
Simple [wildcard](https://en.wikipedia.org/wiki/Wildcard_character) matching.
|
||||
/**
|
||||
Simple [wildcard](https://en.wikipedia.org/wiki/Wildcard_character) matching.
|
||||
|
||||
It matches even across newlines. For example, `foo*r` will match `foo\nbar`.
|
||||
It matches even across newlines. For example, `foo*r` will match `foo\nbar`.
|
||||
|
||||
@param inputs - Strings to match.
|
||||
@param patterns - Use `*` to match zero or more characters. A pattern starting with `!` will be negated.
|
||||
@returns The `inputs` filtered based on the `patterns`.
|
||||
@param inputs - The string or array of strings to match.
|
||||
@param patterns - The string or array of string patterns. Use `*` to match zero or more characters. A leading `!` negates the pattern.
|
||||
@returns An array of `inputs` filtered based on the `patterns`.
|
||||
|
||||
@example
|
||||
```
|
||||
import matcher = require('matcher');
|
||||
@example
|
||||
```
|
||||
import {matcher} from 'matcher';
|
||||
|
||||
matcher(['foo', 'bar', 'moo'], ['*oo', '!foo']);
|
||||
//=> ['moo']
|
||||
matcher(['foo', 'bar', 'moo'], ['*oo', '!foo']);
|
||||
//=> ['moo']
|
||||
|
||||
matcher(['foo', 'bar', 'moo'], ['!*oo']);
|
||||
//=> ['bar']
|
||||
```
|
||||
*/
|
||||
(inputs: readonly string[], patterns: readonly string[], options?: matcher.Options): string[];
|
||||
matcher(['foo', 'bar', 'moo'], ['!*oo']);
|
||||
//=> ['bar']
|
||||
|
||||
/**
|
||||
It matches even across newlines. For example, `foo*r` will match `foo\nbar`.
|
||||
matcher('moo', ['']);
|
||||
//=> []
|
||||
|
||||
@param input - String or array of strings to match.
|
||||
@param pattern - String or array of string patterns. Use `*` to match zero or more characters. A pattern starting with `!` will be negated.
|
||||
@returns Whether any given `input` matches every given `pattern`.
|
||||
matcher('moo', []);
|
||||
//=> []
|
||||
|
||||
@example
|
||||
```
|
||||
import matcher = require('matcher');
|
||||
matcher([''], ['']);
|
||||
//=> ['']
|
||||
```
|
||||
*/
|
||||
export function matcher(
|
||||
inputs: string | readonly string[],
|
||||
patterns: string | readonly string[],
|
||||
options?: Options,
|
||||
): string[];
|
||||
|
||||
matcher.isMatch('unicorn', 'uni*');
|
||||
//=> true
|
||||
/**
|
||||
It matches even across newlines. For example, `foo*r` will match `foo\nbar`.
|
||||
|
||||
matcher.isMatch('unicorn', '*corn');
|
||||
//=> true
|
||||
@param inputs - The string or array of strings to match.
|
||||
@param patterns - The string or array of string patterns. Use `*` to match zero or more characters. A leading `!` negates the pattern.
|
||||
@returns A `boolean` of whether any of given `inputs` matches all the `patterns`.
|
||||
|
||||
matcher.isMatch('unicorn', 'un*rn');
|
||||
//=> true
|
||||
@example
|
||||
```
|
||||
import {isMatch} from 'matcher';
|
||||
|
||||
matcher.isMatch('rainbow', '!unicorn');
|
||||
//=> true
|
||||
isMatch('unicorn', 'uni*');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch('foo bar baz', 'foo b* b*');
|
||||
//=> true
|
||||
isMatch('unicorn', '*corn');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch('unicorn', 'uni\\*');
|
||||
//=> false
|
||||
isMatch('unicorn', 'un*rn');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch('UNICORN', 'UNI*', {caseSensitive: true});
|
||||
//=> true
|
||||
isMatch('rainbow', '!unicorn');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch('UNICORN', 'unicorn', {caseSensitive: true});
|
||||
//=> false
|
||||
isMatch('foo bar baz', 'foo b* b*');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch(['foo', 'bar'], 'f*');
|
||||
//=> true
|
||||
isMatch('unicorn', 'uni\\*');
|
||||
//=> false
|
||||
|
||||
matcher.isMatch(['foo', 'bar'], ['a*', 'b*']);
|
||||
//=> true
|
||||
isMatch(['foo', 'bar'], 'f*');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch('unicorn', ['tri*', 'UNI*'], {caseSensitive: true});
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
isMatch: (input: string | readonly string[], pattern: string | readonly string[], options?: matcher.Options) => boolean;
|
||||
};
|
||||
isMatch(['foo', 'bar'], ['a*', 'b*']);
|
||||
//=> true
|
||||
|
||||
export = matcher;
|
||||
isMatch('unicorn', ['']);
|
||||
//=> false
|
||||
|
||||
isMatch('unicorn', []);
|
||||
//=> false
|
||||
|
||||
isMatch([], 'bar');
|
||||
//=> false
|
||||
|
||||
isMatch([], []);
|
||||
//=> false
|
||||
|
||||
isMatch([''], ['']);
|
||||
//=> true
|
||||
```
|
||||
*/
|
||||
export function isMatch(
|
||||
inputs: string | readonly string[],
|
||||
patterns: string | readonly string[],
|
||||
options?: Options,
|
||||
): boolean;
|
||||
|
|
|
|||
91
node_modules/matcher/index.js
generated
vendored
91
node_modules/matcher/index.js
generated
vendored
|
|
@ -1,12 +1,38 @@
|
|||
'use strict';
|
||||
const escapeStringRegexp = require('escape-string-regexp');
|
||||
import escapeStringRegexp from 'escape-string-regexp';
|
||||
|
||||
const regexpCache = new Map();
|
||||
|
||||
function makeRegexp(pattern, options) {
|
||||
const sanitizeArray = (input, inputName) => {
|
||||
if (!Array.isArray(input)) {
|
||||
switch (typeof input) {
|
||||
case 'string':
|
||||
input = [input];
|
||||
break;
|
||||
case 'undefined':
|
||||
input = [];
|
||||
break;
|
||||
default:
|
||||
throw new TypeError(`Expected '${inputName}' to be a string or an array, but got a type of '${typeof input}'`);
|
||||
}
|
||||
}
|
||||
|
||||
return input.filter(string => {
|
||||
if (typeof string !== 'string') {
|
||||
if (typeof string === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new TypeError(`Expected '${inputName}' to be an array of strings, but found a type of '${typeof string}' in the array`);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
const makeRegexp = (pattern, options) => {
|
||||
options = {
|
||||
caseSensitive: false,
|
||||
...options
|
||||
...options,
|
||||
};
|
||||
|
||||
const cacheKey = pattern + JSON.stringify(options);
|
||||
|
|
@ -28,50 +54,61 @@ function makeRegexp(pattern, options) {
|
|||
regexpCache.set(cacheKey, regexp);
|
||||
|
||||
return regexp;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = (inputs, patterns, options) => {
|
||||
if (!(Array.isArray(inputs) && Array.isArray(patterns))) {
|
||||
throw new TypeError(`Expected two arrays, got ${typeof inputs} ${typeof patterns}`);
|
||||
}
|
||||
const baseMatcher = (inputs, patterns, options, firstMatchOnly) => {
|
||||
inputs = sanitizeArray(inputs, 'inputs');
|
||||
patterns = sanitizeArray(patterns, 'patterns');
|
||||
|
||||
if (patterns.length === 0) {
|
||||
return inputs;
|
||||
return [];
|
||||
}
|
||||
|
||||
const isFirstPatternNegated = patterns[0][0] === '!';
|
||||
|
||||
patterns = patterns.map(pattern => makeRegexp(pattern, options));
|
||||
|
||||
const {allPatterns} = options || {};
|
||||
const result = [];
|
||||
|
||||
for (const input of inputs) {
|
||||
// If first pattern is negated we include everything to match user expectation.
|
||||
let matches = isFirstPatternNegated;
|
||||
// String is included only if it matches at least one non-negated pattern supplied.
|
||||
// Note: the `allPatterns` option requires every non-negated pattern to be matched once.
|
||||
// Matching a negated pattern excludes the string.
|
||||
let matches;
|
||||
const didFit = [...patterns].fill(false);
|
||||
|
||||
for (const pattern of patterns) {
|
||||
for (const [index, pattern] of patterns.entries()) {
|
||||
if (pattern.test(input)) {
|
||||
didFit[index] = true;
|
||||
matches = !pattern.negated;
|
||||
|
||||
if (!matches) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (matches) {
|
||||
if (
|
||||
!(
|
||||
matches === false
|
||||
|| (matches === undefined && patterns.some(pattern => !pattern.negated))
|
||||
|| (allPatterns && didFit.some((yes, index) => !yes && !patterns[index].negated))
|
||||
)
|
||||
) {
|
||||
result.push(input);
|
||||
|
||||
if (firstMatchOnly) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports.isMatch = (input, pattern, options) => {
|
||||
const inputArray = Array.isArray(input) ? input : [input];
|
||||
const patternArray = Array.isArray(pattern) ? pattern : [pattern];
|
||||
export function matcher(inputs, patterns, options) {
|
||||
return baseMatcher(inputs, patterns, options, false);
|
||||
}
|
||||
|
||||
return inputArray.some(input => {
|
||||
return patternArray.every(pattern => {
|
||||
const regexp = makeRegexp(pattern, options);
|
||||
const matches = regexp.test(input);
|
||||
return regexp.negated ? !matches : matches;
|
||||
});
|
||||
});
|
||||
};
|
||||
export function isMatch(inputs, patterns, options) {
|
||||
return baseMatcher(inputs, patterns, options, true).length > 0;
|
||||
}
|
||||
|
|
|
|||
6
node_modules/matcher/node_modules/escape-string-regexp/index.d.ts
generated
vendored
6
node_modules/matcher/node_modules/escape-string-regexp/index.d.ts
generated
vendored
|
|
@ -5,7 +5,7 @@ You can also use this to escape a string that is inserted into the middle of a r
|
|||
|
||||
@example
|
||||
```
|
||||
import escapeStringRegexp = require('escape-string-regexp');
|
||||
import escapeStringRegexp from 'escape-string-regexp';
|
||||
|
||||
const escapedString = escapeStringRegexp('How much $ for a 🦄?');
|
||||
//=> 'How much \\$ for a 🦄\\?'
|
||||
|
|
@ -13,6 +13,4 @@ const escapedString = escapeStringRegexp('How much $ for a 🦄?');
|
|||
new RegExp(escapedString);
|
||||
```
|
||||
*/
|
||||
declare const escapeStringRegexp: (string: string) => string;
|
||||
|
||||
export = escapeStringRegexp;
|
||||
export default function escapeStringRegexp(string: string): string;
|
||||
|
|
|
|||
8
node_modules/matcher/node_modules/escape-string-regexp/index.js
generated
vendored
8
node_modules/matcher/node_modules/escape-string-regexp/index.js
generated
vendored
|
|
@ -1,13 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = string => {
|
||||
export default function escapeStringRegexp(string) {
|
||||
if (typeof string !== 'string') {
|
||||
throw new TypeError('Expected a string');
|
||||
}
|
||||
|
||||
// Escape characters with special meaning either inside or outside character sets.
|
||||
// Use a simple backslash escape when it’s always valid, and a \unnnn escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
|
||||
// Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
|
||||
return string
|
||||
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
|
||||
.replace(/-/g, '\\x2d');
|
||||
};
|
||||
}
|
||||
|
|
|
|||
12
node_modules/matcher/node_modules/escape-string-regexp/package.json
generated
vendored
12
node_modules/matcher/node_modules/escape-string-regexp/package.json
generated
vendored
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "escape-string-regexp",
|
||||
"version": "4.0.0",
|
||||
"version": "5.0.0",
|
||||
"description": "Escape RegExp special characters",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/escape-string-regexp",
|
||||
|
|
@ -10,8 +10,10 @@
|
|||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
"node": ">=12"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
|
|
@ -31,8 +33,8 @@
|
|||
"characters"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"tsd": "^0.11.0",
|
||||
"xo": "^0.28.3"
|
||||
"ava": "^3.15.0",
|
||||
"tsd": "^0.14.0",
|
||||
"xo": "^0.38.2"
|
||||
}
|
||||
}
|
||||
4
node_modules/matcher/node_modules/escape-string-regexp/readme.md
generated
vendored
4
node_modules/matcher/node_modules/escape-string-regexp/readme.md
generated
vendored
|
|
@ -1,4 +1,4 @@
|
|||
# escape-string-regexp [](https://travis-ci.org/sindresorhus/escape-string-regexp)
|
||||
# escape-string-regexp
|
||||
|
||||
> Escape RegExp special characters
|
||||
|
||||
|
|
@ -11,7 +11,7 @@ $ npm install escape-string-regexp
|
|||
## Usage
|
||||
|
||||
```js
|
||||
const escapeStringRegexp = require('escape-string-regexp');
|
||||
import escapeStringRegexp from 'escape-string-regexp';
|
||||
|
||||
const escapedString = escapeStringRegexp('How much $ for a 🦄?');
|
||||
//=> 'How much \\$ for a 🦄\\?'
|
||||
|
|
|
|||
20
node_modules/matcher/package.json
generated
vendored
20
node_modules/matcher/package.json
generated
vendored
|
|
@ -1,16 +1,19 @@
|
|||
{
|
||||
"name": "matcher",
|
||||
"version": "3.0.0",
|
||||
"version": "5.0.0",
|
||||
"description": "Simple wildcard matching",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/matcher",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd",
|
||||
|
|
@ -38,17 +41,12 @@
|
|||
"minimatch"
|
||||
],
|
||||
"dependencies": {
|
||||
"escape-string-regexp": "^4.0.0"
|
||||
"escape-string-regexp": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^2.4.0",
|
||||
"ava": "^3.15.0",
|
||||
"matcha": "^0.7.0",
|
||||
"tsd": "^0.11.0",
|
||||
"xo": "^0.30.0"
|
||||
},
|
||||
"xo": {
|
||||
"rules": {
|
||||
"@typescript-eslint/member-ordering": "off"
|
||||
}
|
||||
"tsd": "^0.17.0",
|
||||
"xo": "^0.45.0"
|
||||
}
|
||||
}
|
||||
117
node_modules/matcher/readme.md
generated
vendored
117
node_modules/matcher/readme.md
generated
vendored
|
|
@ -1,4 +1,4 @@
|
|||
# matcher [](https://travis-ci.com/sindresorhus/matcher)
|
||||
# matcher
|
||||
|
||||
> Simple [wildcard](https://en.wikipedia.org/wiki/Wildcard_character) matching
|
||||
|
||||
|
|
@ -6,14 +6,14 @@ Useful when you want to accept loose string input and regexes/globs are too conv
|
|||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install matcher
|
||||
```sh
|
||||
npm install matcher
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const matcher = require('matcher');
|
||||
import {matcher, isMatch} from 'matcher';
|
||||
|
||||
matcher(['foo', 'bar', 'moo'], ['*oo', '!foo']);
|
||||
//=> ['moo']
|
||||
|
|
@ -21,38 +21,53 @@ matcher(['foo', 'bar', 'moo'], ['*oo', '!foo']);
|
|||
matcher(['foo', 'bar', 'moo'], ['!*oo']);
|
||||
//=> ['bar']
|
||||
|
||||
matcher.isMatch('unicorn', 'uni*');
|
||||
matcher('moo', ['']);
|
||||
//=> []
|
||||
|
||||
matcher('moo', []);
|
||||
//=> []
|
||||
|
||||
matcher([''], ['']);
|
||||
//=> ['']
|
||||
|
||||
isMatch('unicorn', 'uni*');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch('unicorn', '*corn');
|
||||
isMatch('unicorn', '*corn');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch('unicorn', 'un*rn');
|
||||
isMatch('unicorn', 'un*rn');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch('rainbow', '!unicorn');
|
||||
isMatch('rainbow', '!unicorn');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch('foo bar baz', 'foo b* b*');
|
||||
isMatch('foo bar baz', 'foo b* b*');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch('unicorn', 'uni\\*');
|
||||
isMatch('unicorn', 'uni\\*');
|
||||
//=> false
|
||||
|
||||
matcher.isMatch('UNICORN', 'UNI*', {caseSensitive: true});
|
||||
isMatch(['foo', 'bar'], 'f*');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch('UNICORN', 'unicorn', {caseSensitive: true});
|
||||
isMatch(['foo', 'bar'], ['a*', 'b*']);
|
||||
//=> true
|
||||
|
||||
isMatch('unicorn', ['']);
|
||||
//=> false
|
||||
|
||||
matcher.isMatch(['foo', 'bar'], 'f*');
|
||||
//=> true
|
||||
|
||||
matcher.isMatch(['foo', 'bar'], ['a*', 'b*']);
|
||||
//=> true
|
||||
|
||||
matcher.isMatch('unicorn', ['tri*', 'UNI*'], {caseSensitive: true});
|
||||
isMatch('unicorn', []);
|
||||
//=> false
|
||||
|
||||
isMatch([], 'bar');
|
||||
//=> false
|
||||
|
||||
isMatch([], []);
|
||||
//=> false
|
||||
|
||||
isMatch('', '');
|
||||
//=> true
|
||||
```
|
||||
|
||||
## API
|
||||
|
|
@ -61,21 +76,21 @@ It matches even across newlines. For example, `foo*r` will match `foo\nbar`.
|
|||
|
||||
### matcher(inputs, patterns, options?)
|
||||
|
||||
Accepts an array of `input`'s and `pattern`'s.
|
||||
Accepts a string or an array of strings for both `inputs` and `patterns`.
|
||||
|
||||
Returns an array of `inputs` filtered based on the `patterns`.
|
||||
|
||||
### matcher.isMatch(input, pattern, options?)
|
||||
### isMatch(inputs, patterns, options?)
|
||||
|
||||
Accepts either a string or array of strings for both `input` and `pattern`.
|
||||
Accepts a string or an array of strings for both `inputs` and `patterns`.
|
||||
|
||||
Returns a `boolean` of whether any given `input` matches every given `pattern`.
|
||||
Returns a `boolean` of whether any of given `inputs` matches all the `patterns`.
|
||||
|
||||
#### input
|
||||
#### inputs
|
||||
|
||||
Type: `string | string[]`
|
||||
|
||||
String or array of strings to match.
|
||||
The string or array of strings to match.
|
||||
|
||||
#### options
|
||||
|
||||
|
|
@ -90,16 +105,60 @@ Treat uppercase and lowercase characters as being the same.
|
|||
|
||||
Ensure you use this correctly. For example, files and directories should be matched case-insensitively, while most often, object keys should be matched case-sensitively.
|
||||
|
||||
#### pattern
|
||||
```js
|
||||
import {isMatch} from 'matcher';
|
||||
|
||||
isMatch('UNICORN', 'UNI*', {caseSensitive: true});
|
||||
//=> true
|
||||
|
||||
isMatch('UNICORN', 'unicorn', {caseSensitive: true});
|
||||
//=> false
|
||||
|
||||
isMatch('unicorn', ['tri*', 'UNI*'], {caseSensitive: true});
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### allPatterns
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Require all negated patterns to not match and any normal patterns to match at least once. Otherwise, it will be a no-match condition.
|
||||
|
||||
```js
|
||||
import {matcher} from 'matcher';
|
||||
|
||||
// Find text strings containing both "edge" and "tiger" in arbitrary order, but not "stunt".
|
||||
const demo = (strings) => matcher(strings, ['*edge*', '*tiger*', '!*stunt*'], {allPatterns: true});
|
||||
|
||||
demo(['Hey, tiger!', 'tiger has edge over hyenas', 'pushing a tiger over the edge is a stunt']);
|
||||
//=> ['tiger has edge over hyenas']
|
||||
```
|
||||
|
||||
```js
|
||||
import {matcher} from 'matcher';
|
||||
|
||||
matcher(['foo', 'for', 'bar'], ['f*', 'b*', '!x*'], {allPatterns: true});
|
||||
//=> ['foo', 'for', 'bar']
|
||||
|
||||
matcher(['foo', 'for', 'bar'], ['f*'], {allPatterns: true});
|
||||
//=> []
|
||||
```
|
||||
|
||||
#### patterns
|
||||
|
||||
Type: `string | string[]`
|
||||
|
||||
Use `*` to match zero or more characters. A pattern starting with `!` will be negated.
|
||||
Use `*` to match zero or more characters.
|
||||
|
||||
A leading `!` negates the pattern.
|
||||
|
||||
An input string will be omitted, if it does not match any non-negated patterns present, or if it matches a negated pattern, or if no pattern is present.
|
||||
|
||||
## Benchmark
|
||||
|
||||
```
|
||||
$ npm run bench
|
||||
```sh
|
||||
npm run bench
|
||||
```
|
||||
|
||||
## Related
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue