diff options
author | RaindropsSys <raindrops@equestria.dev> | 2023-10-24 17:43:37 +0200 |
---|---|---|
committer | RaindropsSys <raindrops@equestria.dev> | 2023-10-24 17:43:37 +0200 |
commit | ae187b6d75c8079da0be1dc288613bad8466fe61 (patch) | |
tree | 5ea0d34185a2270f29ffaa65e1f5258028d7d5d0 /desktop/node_modules/matcher | |
download | mist-ae187b6d75c8079da0be1dc288613bad8466fe61.tar.gz mist-ae187b6d75c8079da0be1dc288613bad8466fe61.tar.bz2 mist-ae187b6d75c8079da0be1dc288613bad8466fe61.zip |
Initial commit
Diffstat (limited to 'desktop/node_modules/matcher')
-rw-r--r-- | desktop/node_modules/matcher/index.d.ts | 85 | ||||
-rw-r--r-- | desktop/node_modules/matcher/index.js | 77 | ||||
-rw-r--r-- | desktop/node_modules/matcher/license | 9 | ||||
-rw-r--r-- | desktop/node_modules/matcher/package.json | 54 | ||||
-rw-r--r-- | desktop/node_modules/matcher/readme.md | 120 |
5 files changed, 345 insertions, 0 deletions
diff --git a/desktop/node_modules/matcher/index.d.ts b/desktop/node_modules/matcher/index.d.ts new file mode 100644 index 0000000..3405f51 --- /dev/null +++ b/desktop/node_modules/matcher/index.d.ts @@ -0,0 +1,85 @@ +declare namespace matcher { + 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. + + @default false + */ + readonly caseSensitive?: boolean; + } +} + +declare const matcher: { + /** + Simple [wildcard](https://en.wikipedia.org/wiki/Wildcard_character) matching. + + 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`. + + @example + ``` + import matcher = require('matcher'); + + matcher(['foo', 'bar', 'moo'], ['*oo', '!foo']); + //=> ['moo'] + + matcher(['foo', 'bar', 'moo'], ['!*oo']); + //=> ['bar'] + ``` + */ + (inputs: readonly string[], patterns: readonly string[], options?: matcher.Options): string[]; + + /** + It matches even across newlines. For example, `foo*r` will match `foo\nbar`. + + @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`. + + @example + ``` + import matcher = require('matcher'); + + matcher.isMatch('unicorn', 'uni*'); + //=> true + + matcher.isMatch('unicorn', '*corn'); + //=> true + + matcher.isMatch('unicorn', 'un*rn'); + //=> true + + matcher.isMatch('rainbow', '!unicorn'); + //=> true + + matcher.isMatch('foo bar baz', 'foo b* b*'); + //=> true + + matcher.isMatch('unicorn', 'uni\\*'); + //=> false + + matcher.isMatch('UNICORN', 'UNI*', {caseSensitive: true}); + //=> true + + matcher.isMatch('UNICORN', 'unicorn', {caseSensitive: true}); + //=> false + + matcher.isMatch(['foo', 'bar'], 'f*'); + //=> true + + matcher.isMatch(['foo', 'bar'], ['a*', 'b*']); + //=> true + + matcher.isMatch('unicorn', ['tri*', 'UNI*'], {caseSensitive: true}); + //=> false + ``` + */ + isMatch: (input: string | readonly string[], pattern: string | readonly string[], options?: matcher.Options) => boolean; +}; + +export = matcher; diff --git a/desktop/node_modules/matcher/index.js b/desktop/node_modules/matcher/index.js new file mode 100644 index 0000000..bab0afc --- /dev/null +++ b/desktop/node_modules/matcher/index.js @@ -0,0 +1,77 @@ +'use strict'; +const escapeStringRegexp = require('escape-string-regexp'); + +const regexpCache = new Map(); + +function makeRegexp(pattern, options) { + options = { + caseSensitive: false, + ...options + }; + + const cacheKey = pattern + JSON.stringify(options); + + if (regexpCache.has(cacheKey)) { + return regexpCache.get(cacheKey); + } + + const negated = pattern[0] === '!'; + + if (negated) { + pattern = pattern.slice(1); + } + + pattern = escapeStringRegexp(pattern).replace(/\\\*/g, '[\\s\\S]*'); + + const regexp = new RegExp(`^${pattern}$`, options.caseSensitive ? '' : 'i'); + regexp.negated = negated; + 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}`); + } + + if (patterns.length === 0) { + return inputs; + } + + const isFirstPatternNegated = patterns[0][0] === '!'; + + patterns = patterns.map(pattern => makeRegexp(pattern, options)); + + const result = []; + + for (const input of inputs) { + // If first pattern is negated we include everything to match user expectation. + let matches = isFirstPatternNegated; + + for (const pattern of patterns) { + if (pattern.test(input)) { + matches = !pattern.negated; + } + } + + if (matches) { + result.push(input); + } + } + + return result; +}; + +module.exports.isMatch = (input, pattern, options) => { + const inputArray = Array.isArray(input) ? input : [input]; + const patternArray = Array.isArray(pattern) ? pattern : [pattern]; + + return inputArray.some(input => { + return patternArray.every(pattern => { + const regexp = makeRegexp(pattern, options); + const matches = regexp.test(input); + return regexp.negated ? !matches : matches; + }); + }); +}; diff --git a/desktop/node_modules/matcher/license b/desktop/node_modules/matcher/license new file mode 100644 index 0000000..fa7ceba --- /dev/null +++ b/desktop/node_modules/matcher/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/desktop/node_modules/matcher/package.json b/desktop/node_modules/matcher/package.json new file mode 100644 index 0000000..fe9c386 --- /dev/null +++ b/desktop/node_modules/matcher/package.json @@ -0,0 +1,54 @@ +{ + "name": "matcher", + "version": "3.0.0", + "description": "Simple wildcard matching", + "license": "MIT", + "repository": "sindresorhus/matcher", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "https://sindresorhus.com" + }, + "engines": { + "node": ">=10" + }, + "scripts": { + "test": "xo && ava && tsd", + "bench": "matcha bench.js" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "matcher", + "matching", + "match", + "regex", + "regexp", + "regular", + "expression", + "wildcard", + "pattern", + "string", + "filter", + "glob", + "globber", + "globbing", + "minimatch" + ], + "dependencies": { + "escape-string-regexp": "^4.0.0" + }, + "devDependencies": { + "ava": "^2.4.0", + "matcha": "^0.7.0", + "tsd": "^0.11.0", + "xo": "^0.30.0" + }, + "xo": { + "rules": { + "@typescript-eslint/member-ordering": "off" + } + } +} diff --git a/desktop/node_modules/matcher/readme.md b/desktop/node_modules/matcher/readme.md new file mode 100644 index 0000000..962070a --- /dev/null +++ b/desktop/node_modules/matcher/readme.md @@ -0,0 +1,120 @@ +# matcher [![Build Status](https://travis-ci.com/sindresorhus/matcher.svg?branch=master)](https://travis-ci.com/sindresorhus/matcher) + +> Simple [wildcard](https://en.wikipedia.org/wiki/Wildcard_character) matching + +Useful when you want to accept loose string input and regexes/globs are too convoluted. + +## Install + +``` +$ npm install matcher +``` + +## Usage + +```js +const matcher = require('matcher'); + +matcher(['foo', 'bar', 'moo'], ['*oo', '!foo']); +//=> ['moo'] + +matcher(['foo', 'bar', 'moo'], ['!*oo']); +//=> ['bar'] + +matcher.isMatch('unicorn', 'uni*'); +//=> true + +matcher.isMatch('unicorn', '*corn'); +//=> true + +matcher.isMatch('unicorn', 'un*rn'); +//=> true + +matcher.isMatch('rainbow', '!unicorn'); +//=> true + +matcher.isMatch('foo bar baz', 'foo b* b*'); +//=> true + +matcher.isMatch('unicorn', 'uni\\*'); +//=> false + +matcher.isMatch('UNICORN', 'UNI*', {caseSensitive: true}); +//=> true + +matcher.isMatch('UNICORN', 'unicorn', {caseSensitive: true}); +//=> false + +matcher.isMatch(['foo', 'bar'], 'f*'); +//=> true + +matcher.isMatch(['foo', 'bar'], ['a*', 'b*']); +//=> true + +matcher.isMatch('unicorn', ['tri*', 'UNI*'], {caseSensitive: true}); +//=> false +``` + +## API + +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. + +Returns an array of `inputs` filtered based on the `patterns`. + +### matcher.isMatch(input, pattern, options?) + +Accepts either a string or array of strings for both `input` and `pattern`. + +Returns a `boolean` of whether any given `input` matches every given `pattern`. + +#### input + +Type: `string | string[]` + +String or array of strings to match. + +#### options + +Type: `object` + +##### caseSensitive + +Type: `boolean`\ +Default: `false` + +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 + +Type: `string | string[]` + +Use `*` to match zero or more characters. A pattern starting with `!` will be negated. + +## Benchmark + +``` +$ npm run bench +``` + +## Related + +- [matcher-cli](https://github.com/sindresorhus/matcher-cli) - CLI for this module +- [multimatch](https://github.com/sindresorhus/multimatch) - Extends `minimatch.match()` with support for multiple patterns + +--- + +<div align="center"> + <b> + <a href="https://tidelift.com/subscription/pkg/npm-matcher?utm_source=npm-matcher&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> + </b> + <br> + <sub> + Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. + </sub> +</div> |