Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wildcard-match

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wildcard-match - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

dist/index.d.ts

55

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc