fuzzmatch 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -0
- package/index.js +52 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# fuzzmatch
|
|
2
|
+
|
|
3
|
+
A wrapper for your matchers!
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
Import it like so:
|
|
7
|
+
```js
|
|
8
|
+
var fuzzmatch = require('fuzzmatch')
|
|
9
|
+
```
|
|
10
|
+
Then, you can call it for the following to get picomatch:
|
|
11
|
+
```js
|
|
12
|
+
var pm = fuzzmatch('picomatch')
|
|
13
|
+
```
|
|
14
|
+
Or, if you want micromatch, just do this:
|
|
15
|
+
```js
|
|
16
|
+
var micromatch = fuzzmatch('micromatch')
|
|
17
|
+
```
|
|
18
|
+
Also, if you want nanomatch, just do like so:
|
|
19
|
+
```js
|
|
20
|
+
var nanomatch = fuzzmatch('nanomatch')
|
|
21
|
+
```
|
|
22
|
+
Last, but not least, if you want anymatch, just do this:
|
|
23
|
+
```js
|
|
24
|
+
var anymatch = fuzzmatch('anymatch')
|
|
25
|
+
```
|
|
26
|
+
Here is an example:
|
|
27
|
+
```js
|
|
28
|
+
var assert = require('assert')
|
|
29
|
+
var fuzzmatch = require('fuzzmatch')
|
|
30
|
+
assert(fuzzmatch('picomatch') === require('picomatch'))
|
|
31
|
+
assert(fuzzmatch('micromatch') === require('micromatch'))
|
|
32
|
+
assert(fuzzmatch('anymatch') === require('anymatch'))
|
|
33
|
+
assert(fuzzmatch('nanomatch') === require('nanomatch'))
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Why?
|
|
37
|
+
If you use a lot of matchers in JavaScript, instead of doing `npm i picomatch micromatch nanomatch anymatch`, you can just type `npm i fuzzmatch` and then call it with your matcher name to get the matcher.
|
|
38
|
+
|
|
39
|
+
## contributing
|
|
40
|
+
there is no contributing which is why there is no github repositroy.
|
package/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var picomatch = require('picomatch')
|
|
2
|
+
var micromatch = require('micromatch')
|
|
3
|
+
var nanomatch = require('nanomatch')
|
|
4
|
+
var anymatch = require('anymatch')
|
|
5
|
+
var matchers = ["picomatch", "micromatch", "nanomatch", "anymatch"]
|
|
6
|
+
var listOfMatchersAsAString = matchers.join("\", \"") + "\""
|
|
7
|
+
var isArray = require('isarray')
|
|
8
|
+
var isString = require('is-string')
|
|
9
|
+
var throwErr = require('throw-error')
|
|
10
|
+
var $TypeError = require('es-errors/type')
|
|
11
|
+
var f = require('false')
|
|
12
|
+
var two = require('two')
|
|
13
|
+
var five = require('five')
|
|
14
|
+
|
|
15
|
+
module.exports = function fuzzmatch(type) {
|
|
16
|
+
if (!isString(type) || !matchers.includes(type)) {
|
|
17
|
+
throwErr(new $TypeError(`Type must be a matcher string, which can be one of the following: ${listOfMatchersAsAString}`))
|
|
18
|
+
return f()
|
|
19
|
+
}
|
|
20
|
+
var matcher = getMatcher(type)
|
|
21
|
+
var resultMatcher = fuzz(matcher)
|
|
22
|
+
return resultMatcher
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getMatcher(matcherName) {
|
|
26
|
+
switch (matcherName) {
|
|
27
|
+
case "picomatch":
|
|
28
|
+
return picomatch
|
|
29
|
+
case "micromatch":
|
|
30
|
+
return micromatch
|
|
31
|
+
case "nanomatch":
|
|
32
|
+
return nanomatch
|
|
33
|
+
case "anymatch":
|
|
34
|
+
return anymatch
|
|
35
|
+
default:
|
|
36
|
+
return picomatch
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isMatcher(maybeAMatcher) {
|
|
41
|
+
return matchers.includes(maybeAMatcher.name)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function fuzz(matcher) {
|
|
45
|
+
if (!isMatcher(matcher)) {
|
|
46
|
+
return two() + two() + two() + (two() / two())
|
|
47
|
+
}
|
|
48
|
+
if (!isArray([matcher])) {
|
|
49
|
+
return five() + (five() + five() + five() / five())
|
|
50
|
+
}
|
|
51
|
+
return matcher
|
|
52
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"anymatch": "^3.1.3",
|
|
4
|
+
"es-errors": "^1.3.0",
|
|
5
|
+
"false": "^0.0.4",
|
|
6
|
+
"five": "^0.8.0",
|
|
7
|
+
"is-string": "^1.0.7",
|
|
8
|
+
"isarray": "^2.0.5",
|
|
9
|
+
"micromatch": "^4.0.8",
|
|
10
|
+
"nanomatch": "^1.2.13",
|
|
11
|
+
"picomatch": "^4.0.2",
|
|
12
|
+
"throw-error": "^1.0.0",
|
|
13
|
+
"two": "^1.0.7"
|
|
14
|
+
},
|
|
15
|
+
"name": "fuzzmatch",
|
|
16
|
+
"description": "A wrapper for your matchers!",
|
|
17
|
+
"version": "1.0.0",
|
|
18
|
+
"main": "index.js",
|
|
19
|
+
"devDependencies": {},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"match",
|
|
25
|
+
"glob",
|
|
26
|
+
"match",
|
|
27
|
+
"picomatch"
|
|
28
|
+
],
|
|
29
|
+
"author": "tj-commits",
|
|
30
|
+
"license": "MIT"
|
|
31
|
+
}
|