任意匹配

Javascript 模块将字符串匹配到正则表达式, glob, string, 或函数将字符串作为参数并返回真伪或虚伪 数值。 火柴也可以是其中任何一个或全部的数组. 用于 允许一个非常灵活的用户定义配置来定义文件路径等东西.
说明: 这个模块有 Bash-parity,请注意Windows 风格回鞭不支持作为分隔符. 见 https://github.com/micromatch/micromatch#后鞭打 更多信息.
使用量
npm install anymatch
任意匹配( 匹配者, 测试String, [返回Index], [选项])
- 匹配点: (中文(简体) )阵列 QQ 串列 REG ExpQ 功能(中文(简体) ) 要直接匹配的字符串, 有 glob 模式的字符串, 正则表达式 测试,以测试为参数并返回真伪的函数 值,如果它应该匹配,或者这些类型的任何数字和组合的数组.
- 测试: (中文(简体) )字符串QQ 箭头)取弦以试相克者. 若为
作为数组传递,数组的第一个元素将作为
testString用于非函数匹配器,同时将应用整个阵列 作为函数匹配者的参数. - 选项: (中文(简体) )对象 [可选] . 任何一个 缩写 选项.
- 返回内存: (中文(简体) )布尔 [可选]如果选中的话, 返回 测试匹配的第一个匹配者String,或者 -1 如果没有匹配,而不是一个 布尔结果.
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* ❯
任意匹配( 匹配)
您也可以只通过您的匹配者来获取一个具有
已绑定到提供的匹配标准 。 这可以用作
Array#filter 调用.
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']
更改日志
- v3.0 : 删除
startIndex财务报告和审定财务报表endIndex参数。 节点8.x只. - v2.0: (中文(简体) ) 微比对 远离小比分 并与巴什连接。 其中包括以不同方式处理回扣(见 https://github.com/micromatch/micromatch#后鞭打 更多信息).
- v1.2: 任意匹配的使用 微比对 用于 glob 模式匹配。 glob 模式匹配的问题应该是: 直接报告 微匹配问题跟踪器。 。 。 .