{"id":13396823,"url":"https://github.com/sindresorhus/matcher","last_synced_at":"2025-04-13T18:34:49.576Z","repository":{"id":46625659,"uuid":"51131322","full_name":"sindresorhus/matcher","owner":"sindresorhus","description":"Simple wildcard matching","archived":false,"fork":false,"pushed_at":"2021-10-03T09:29:45.000Z","size":60,"stargazers_count":537,"open_issues_count":3,"forks_count":29,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-10T23:27:49.604Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2016-02-05T06:58:04.000Z","updated_at":"2025-02-25T06:20:01.000Z","dependencies_parsed_at":"2022-08-02T18:16:08.209Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/matcher","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/matcher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248761172,"owners_count":21157505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:01:03.898Z","updated_at":"2025-04-13T18:34:49.551Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate","https://tidelift.com/subscription/pkg/npm-matcher?utm_source=npm-matcher\u0026utm_medium=referral\u0026utm_campaign=readme"],"categories":["字符串","Packages","JavaScript","Repository","包","目录","Text"],"sub_categories":["Text","RegExp/Glob","文本","文本处理"],"readme":"# matcher\n\n\u003e Simple [wildcard](https://en.wikipedia.org/wiki/Wildcard_character) matching\n\nUseful when you want to accept loose string input and regexes/globs are too convoluted.\n\n## Install\n\n```sh\nnpm install matcher\n```\n\n## Usage\n\n```js\nimport {matcher, isMatch} from 'matcher';\n\nmatcher(['foo', 'bar', 'moo'], ['*oo', '!foo']);\n//=\u003e ['moo']\n\nmatcher(['foo', 'bar', 'moo'], ['!*oo']);\n//=\u003e ['bar']\n\nmatcher('moo', ['']);\n//=\u003e []\n\nmatcher('moo', []);\n//=\u003e []\n\nmatcher([''], ['']);\n//=\u003e ['']\n\nisMatch('unicorn', 'uni*');\n//=\u003e true\n\nisMatch('unicorn', '*corn');\n//=\u003e true\n\nisMatch('unicorn', 'un*rn');\n//=\u003e true\n\nisMatch('rainbow', '!unicorn');\n//=\u003e true\n\nisMatch('foo bar baz', 'foo b* b*');\n//=\u003e true\n\nisMatch('unicorn', 'uni\\\\*');\n//=\u003e false\n\nisMatch(['foo', 'bar'], 'f*');\n//=\u003e true\n\nisMatch(['foo', 'bar'], ['a*', 'b*']);\n//=\u003e true\n\nisMatch('unicorn', ['']);\n//=\u003e false\n\nisMatch('unicorn', []);\n//=\u003e false\n\nisMatch([], 'bar');\n//=\u003e false\n\nisMatch([], []);\n//=\u003e false\n\nisMatch('', '');\n//=\u003e true\n```\n\n## API\n\nIt matches even across newlines. For example, `foo*r` will match `foo\\nbar`.\n\n### matcher(inputs, patterns, options?)\n\nAccepts a string or an array of strings for both `inputs` and `patterns`.\n\nReturns an array of `inputs` filtered based on the `patterns`.\n\n### isMatch(inputs, patterns, options?)\n\nAccepts a string or an array of strings for both `inputs` and `patterns`.\n\nReturns a `boolean` of whether any of given `inputs` matches all the `patterns`.\n\n#### inputs\n\nType: `string | string[]`\n\nThe string or array of strings to match.\n\n#### options\n\nType: `object`\n\n##### caseSensitive\n\nType: `boolean`\\\nDefault: `false`\n\nTreat uppercase and lowercase characters as being the same.\n\nEnsure you use this correctly. For example, files and directories should be matched case-insensitively, while most often, object keys should be matched case-sensitively.\n\n```js\nimport {isMatch} from 'matcher';\n\nisMatch('UNICORN', 'UNI*', {caseSensitive: true});\n//=\u003e true\n\nisMatch('UNICORN', 'unicorn', {caseSensitive: true});\n//=\u003e false\n\nisMatch('unicorn', ['tri*', 'UNI*'], {caseSensitive: true});\n//=\u003e false\n```\n\n##### allPatterns\n\nType: `boolean`\\\nDefault: `false`\n\nRequire all negated patterns to not match and any normal patterns to match at least once. Otherwise, it will be a no-match condition.\n\n```js\nimport {matcher} from 'matcher';\n\n// Find text strings containing both \"edge\" and \"tiger\" in arbitrary order, but not \"stunt\".\nconst demo = (strings) =\u003e matcher(strings, ['*edge*', '*tiger*', '!*stunt*'], {allPatterns: true});\n\ndemo(['Hey, tiger!', 'tiger has edge over hyenas', 'pushing a tiger over the edge is a stunt']);\n//=\u003e ['tiger has edge over hyenas']\n```\n\n```js\nimport {matcher} from 'matcher';\n\nmatcher(['foo', 'for', 'bar'], ['f*', 'b*', '!x*'], {allPatterns: true});\n//=\u003e ['foo', 'for', 'bar']\n\nmatcher(['foo', 'for', 'bar'], ['f*'], {allPatterns: true});\n//=\u003e []\n```\n\n#### patterns\n\nType: `string | string[]`\n\nUse `*` to match zero or more characters.\n\nA leading `!` negates the pattern.\n\nAn input string will be omitted, if it does not match any non-negated patterns present, or if it matches a negated pattern, or if no pattern is present.\n\n## Benchmark\n\n```sh\nnpm run bench\n```\n\n## Related\n\n- [matcher-cli](https://github.com/sindresorhus/matcher-cli) - CLI for this module\n- [multimatch](https://github.com/sindresorhus/multimatch) - Extends `minimatch.match()` with support for multiple patterns\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\t\u003cb\u003e\n\t\t\u003ca href=\"https://tidelift.com/subscription/pkg/npm-matcher?utm_source=npm-matcher\u0026utm_medium=referral\u0026utm_campaign=readme\"\u003eGet professional support for this package with a Tidelift subscription\u003c/a\u003e\n\t\u003c/b\u003e\n\t\u003cbr\u003e\n\t\u003csub\u003e\n\t\tTidelift helps make open source sustainable for maintainers while giving companies\u003cbr\u003eassurances about security, maintenance, and licensing for their dependencies.\n\t\u003c/sub\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fmatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fmatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fmatcher/lists"}