CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
README.md88 linesDownload Raw Back to anymatch
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 falsy5value. The matcher can also be an array of any or all of these. Useful for6allowing 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 11Usage12-----13```sh14npm install anymatch15```16 17#### anymatch(matchers, testString, [returnIndex], [options])18* __matchers__: (_Array|String|RegExp|Function_)19String to be directly matched, string with glob patterns, regular expression20test, function that takes the testString as an argument and returns a truthy21value 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. If23passed as an array, the first element of the array will be used as the24`testString` for non-function matchers, while the entire array will be applied25as 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 of28the first matcher that that testString matched, or -1 if no match, instead of a29boolean result.30 31```js32const 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'); // true37anymatch(matchers, 'path/anyjs/baz.js'); // true38anymatch(matchers, 'path/to/foo.js'); // true39anymatch(matchers, 'path/to/bar.js'); // true40anymatch(matchers, 'bar.js'); // false41 42// returnIndex = true43anymatch(matchers, 'foo.js', {returnIndex: true}); // 244anymatch(matchers, 'path/anyjs/foo.js', {returnIndex: true}); // 145 46// any picomatc47 48// using globs to match directories and their children49anymatch('node_modules', 'node_modules'); // true50anymatch('node_modules', 'node_modules/somelib/index.js'); // false51anymatch('node_modules/**', 'node_modules/somelib/index.js'); // true52anymatch('node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // false53anymatch('**/node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // true54 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 has63already been bound to the provided matching criteria. This can be used as an64`Array#filter` callback.65 66```js67var matcher = anymatch(matchers);68 69matcher('path/to/file.js'); // true70matcher('path/anyjs/baz.js', true); // 171 72['foo.js', 'bar.js'].filter(matcher); // ['foo.js']73```74 75Changelog76----------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 be83reported directly to the [micromatch issue tracker](https://github.com/jonschlinkert/micromatch/issues).84 85License86-------87[ISC](https://raw.github.com/micromatch/anymatch/master/LICENSE)88