wildcard-match
Advanced tools
Comparing version 1.1.0 to 2.0.0
{ | ||
"name": "wildcard-match", | ||
"version": "1.1.0", | ||
"description": "Match two glob-like patterns", | ||
"author": "Alex Shnayder <alex@shnayder.pro>", | ||
"version": "2.0.0", | ||
"description": "Check if a string matches a pattern containing * and ** wildcards", | ||
"author": "Alex Schneider <me@schneider.ax>", | ||
"repository": "https://github.com/axtgr/wildcard-match", | ||
"license": "ISC", | ||
"main": "src/index.js", | ||
"types": "src/index.d.ts", | ||
"scripts": { | ||
"lint": "eslint src test", | ||
"test": "mocha test/**/*" | ||
}, | ||
"keywords": [ | ||
@@ -19,15 +14,39 @@ "match", | ||
], | ||
"homepage": "https://github.com/alex-shnayder/wildcard-match", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/alex-shnayder/wildcard-match.git" | ||
"main": "dist/index.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"lint": "eslint src test", | ||
"test": "ts-mocha test/**" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/alex-shnayder/wildcard-match/issues" | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged && npm run test -- -b" | ||
} | ||
}, | ||
"lint-staged": { | ||
"(src|test)/**/*.ts": [ | ||
"eslint --cache --fix" | ||
], | ||
"*.md": "prettier --write" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"eslint": "^4.6.1", | ||
"mocha": "^3.5.3" | ||
"@types/mocha": "^7.0.2", | ||
"@types/node": "^14.0.14", | ||
"@typescript-eslint/eslint-plugin": "^3.4.0", | ||
"@typescript-eslint/parser": "^3.4.0", | ||
"eslint": "^7.3.1", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-config-problems": "^4.0.0", | ||
"eslint-plugin-prefer-let": "^1.0.1", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"husky": "^4.2.5", | ||
"lint-staged": "^10.2.11", | ||
"mocha": "^8.0.1", | ||
"prettier": "^2.0.5", | ||
"ts-mocha": "^7.0.0", | ||
"typescript": "^3.9.5" | ||
} | ||
} |
# wildcard-match | ||
A function that matches two glob-like patterns with each other. It has an advantage over other similar libraries in that it allows *both* samples to have wildcards. | ||
Check if a string matches a pattern containing `*` and `**` wildcards. | ||
## Install | ||
## Installation | ||
`npm install wildcard-match` | ||
`npm install --save wildcard-match` | ||
## Usage | ||
The default export is a function that takes a pattern and an optional separator (`/` by default). | ||
It compiles the pattern and returns a function for matching strings with it. | ||
## Usage | ||
```js | ||
const wcm = require('wildcard-match') | ||
const match = wcm('src/*/**/index.js') // Precompile the pattern-matching function | ||
match('src/lib/component/test/index.js') // Check if the string matches the pattern | ||
``` | ||
Wildcards will only match whole segments (`/*/`) and not arbitrary substrings (`/foo*/`): | ||
- `*` for exactly one segment | ||
- `**` for _any_ number of segments (including zero) | ||
## Examples | ||
```javascript | ||
const match = require('wildcard-match') | ||
const wcm = require('wildcard-match') | ||
match('one/**', 'one/two/three') // true | ||
match('.', ['one', '**', 'four'], 'one.two.three.four') // true | ||
match('one.two', 'one.two.*') // false because * matches exactly one segment | ||
const match = wcm('src/**/index.js') | ||
match('src/index.js') // true | ||
match('src/lib/index.js') // true | ||
match('src/lib/component/test/index.js') // true | ||
match('src') // false | ||
match('index.js') // false | ||
match('src/index.js/lib') // false | ||
``` | ||
Patterns can be either strings or arrays, and can have the following wildcards: | ||
```javascript | ||
const wcm = require('wildcard-match') | ||
* `*` for exactly one segment | ||
* `**` for any number of segments (including zero) | ||
const match = wcm('**.*.example.com', '.') | ||
If at least one of the samples is a string, a delimiter can be provided as the first argument. If the delimiter is not specified, `/` is used. | ||
match('example.com') // false | ||
match('foo.example.com') // true | ||
match('foo.bar.example.com') // true | ||
match('foo.bar.baz.qux.example.com') // true | ||
match('foo.example.com.bar') // false | ||
``` | ||
```javascript | ||
const wcm = require('wildcard-match') | ||
const match = wcm('**') // will match ANY string | ||
match('') // true | ||
match(' ') // true | ||
match('/') // true | ||
match('foo') // true | ||
match('foo/bar') // true | ||
match('foo/bar/baz/qux') // true | ||
``` | ||
## License | ||
[ISC](LICENSE) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7750
68
15
6
63
1
1
1
2