Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

‼️ Matches strings against configurable strings, globs, regular expressions, and/or functions

License

NotificationsYou must be signed in to change notification settings

micromatch/anymatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 falsyvalue. The matcher can also be an array of any or all of these. Useful forallowing 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. Seehttps://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 expressiontest, function that takes the testString as an argument and returns a truthyvalue 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. Ifpassed as an array, the first element of the array will be used as thetestString for non-function matchers, while the entire array will be appliedas the arguments for function matchers.
  • options: (Object [optional]_) Any of thepicomatch options.
    • returnIndex: (Boolean [optional]) If true, return the array index ofthe first matcher that that testString matched, or -1 if no match, instead of aboolean result.
constanymatch=require('anymatch');constmatchers=['path/to/file.js','path/anyjs/**/*.js',/foo.js$/,string=>string.includes('bar')&&string.length>10];anymatch(matchers,'path/to/file.js');// trueanymatch(matchers,'path/anyjs/baz.js');// trueanymatch(matchers,'path/to/foo.js');// trueanymatch(matchers,'path/to/bar.js');// trueanymatch(matchers,'bar.js');// false// returnIndex = trueanymatch(matchers,'foo.js',{returnIndex:true});// 2anymatch(matchers,'path/anyjs/foo.js',{returnIndex:true});// 1// any picomatc// using globs to match directories and their childrenanymatch('node_modules','node_modules');// trueanymatch('node_modules','node_modules/somelib/index.js');// falseanymatch('node_modules/**','node_modules/somelib/index.js');// trueanymatch('node_modules/**','/absolute/path/to/node_modules/somelib/index.js');// falseanymatch('**/node_modules/**','/absolute/path/to/node_modules/somelib/index.js');// trueconstmatcher=anymatch(matchers);['foo.js','bar.js'].filter(matcher);// [ 'foo.js' ]anymatchmaster*

anymatch(matchers)

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

varmatcher=anymatch(matchers);matcher('path/to/file.js');// truematcher('path/anyjs/baz.js',true);// 1['foo.js','bar.js'].filter(matcher);// ['foo.js']

Changelog

See release notes page on GitHub

License

ISC

About

‼️ Matches strings against configurable strings, globs, regular expressions, and/or functions

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp