3.1.3 • Published 1 year ago

anymatch v3.1.3

Weekly downloads
33,906,800
License
ISC
Repository
github
Last release
1 year ago

anymatch Build Status Coverage Status

Javascript module to match a string against a regular expression, glob, string, or function that takes the string as an argument and returns a truthy or falsy value. The matcher can also be an array of any or all of these. Useful for allowing a very flexible user-defined config to define things like file paths.

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.

Usage

npm install anymatch

anymatch(matchers, testString, returnIndex, options)

  • matchers: (Array|String|RegExp|Function) String to be directly matched, string with glob patterns, regular expression test, function that takes the testString as an argument and returns a truthy value if it should be matched, or an array of any number and mix of these types.
  • testString: (String|Array) The string to test against the matchers. If passed as an array, the first element of the array will be used as the testString for non-function matchers, while the entire array will be applied as the arguments for function matchers.
  • options: (Object optional) Any of the picomatch options. * returnIndex: (_Boolean optional) If true, return the array index of the first matcher that that testString matched, or -1 if no match, instead of a boolean result.
const anymatch = require('anymatch');

const matchers = [ 'path/to/file.js', 'path/anyjs/**/*.js', /foo.js$/, string => string.includes('bar') && string.length > 10 ] ;

anymatch(matchers, 'path/to/file.js'); // true
anymatch(matchers, 'path/anyjs/baz.js'); // true
anymatch(matchers, 'path/to/foo.js'); // true
anymatch(matchers, 'path/to/bar.js'); // true
anymatch(matchers, 'bar.js'); // false

// returnIndex = true
anymatch(matchers, 'foo.js', {returnIndex: true}); // 2
anymatch(matchers, 'path/anyjs/foo.js', {returnIndex: true}); // 1

// any picomatc

// using globs to match directories and their children
anymatch('node_modules', 'node_modules'); // true
anymatch('node_modules', 'node_modules/somelib/index.js'); // false
anymatch('node_modules/**', 'node_modules/somelib/index.js'); // true
anymatch('node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // false
anymatch('**/node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // true

const matcher = anymatch(matchers);
['foo.js', 'bar.js'].filter(matcher);  // [ 'foo.js' ]
anymatch master* ❯

anymatch(matchers)

You can also pass in only your matcher(s) to get a curried function that has already been bound to the provided matching criteria. This can be used as an Array#filter callback.

var matcher = anymatch(matchers);

matcher('path/to/file.js'); // true
matcher('path/anyjs/baz.js', true); // 1

['foo.js', 'bar.js'].filter(matcher); // ['foo.js']

Changelog

See release notes page on GitHub

License

ISC

chokidarjest-haste-mapsane@types/anymatchglob-stream@yattho/stylelint-config@modern-js/monorepo-tools@triplex/serverarchetype-librarycomponennentt@dinert/utils@agilebot/vite-plugin-javascript-obfuscatoreasy-select-rnvuedragdropuploadimagespopsmart-common-authreact-native-bluetooth2killi8n-react-native-fast-imagern-send-smsspecify-importsbabel-specify-imports@icanpm/api-master@arisageha/react-lazyload@arisageha/react-lazyload-fix@cashremit/cr-streamline-icons@metastack/indexereefserverreact-native-template-rfbaseairscanairscan-examplebb-chatreact-native-esc-pos-sahaab@ihikmawan/tailwindcss-multi-theme-l2@borisovart/atol-kkt-module@frxf/frxfphill@phil8795/pecuniarius-apideneme323112@texttree/demo-bsa-reference-rcl@fundefund/funde_ck@ntt_app/react-native-custom-notificationwenke-node-watchifyreact-native-custom-text-hwjames@sonammalhotra/lotide@smishra17/lotide@cheapthrills/lotidediscord-music-botsreact-native-covid-sdkgql_din_modmdt-libbitgetalex-frontend-sdk-stagingincrement-intreact-native-thanh-toast-libraryds-actions@thanhnguyen14797/react-native-thanh-toast-library@l1nyanm1ng/react-picture-viewercthpb-plugin-social@iobroker-community-adapters/iobroker.device-watcheruicompile@olivervorasai/sliderreact-native-printer-brothersrn-pdf-reader-offlineskri.besuperscore.stringcbmis-ai-toolbox@newhorizon-tech/dd-npm-package-templatereact-native-shekhar-bridge-testasterjscogoportutilsftp-sync-workslevibestliblevibestlib2levilibtest19levilibtest24levilibtest25levilibtest26levilibtest27levilibtest28levilibtest29levinodelibuinz-notification@nicholasjj/lotidewilscanner@oiti/documentoscopy-react-nativejs4cytoscape@mink-opn/build-tokensquoc-testreact-native-slider-kfhexa-node-common@prodam/prodam-typescclibyarntest@saaspe/componentshyperpass-sdkplginexpand-react-bridgeexpress-api-pack-tropea-bootstraapluminos-ui-corelit-tailwind-poc-2stylelint-config-primer
3.1.3

1 year ago

3.1.2

3 years ago

3.1.1

4 years ago

3.1.0

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.0

6 years ago

1.3.2

7 years ago

1.3.0

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago