patroon 1.2.1 → 1.2.3
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 +2 -2
- package/package.json +2 -2
- package/src/index.test.js +11 -0
- package/src/walkable.js +2 -2
package/README.md
CHANGED
|
@@ -583,7 +583,7 @@ npx nyc npm t | npx tap-nyc
|
|
|
583
583
|
npx nyc check-coverage
|
|
584
584
|
```
|
|
585
585
|
```
|
|
586
|
-
> patroon@1.2.
|
|
586
|
+
> patroon@1.2.1 test
|
|
587
587
|
> tape ./src/index.test.js
|
|
588
588
|
-------------|---------|----------|---------|---------|-------------------
|
|
589
589
|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
@@ -597,7 +597,7 @@ npx nyc check-coverage
|
|
|
597
597
|
total: 28
|
|
598
598
|
passing: 28
|
|
599
599
|
|
|
600
|
-
duration:
|
|
600
|
+
duration: 9s
|
|
601
601
|
|
|
602
602
|
```
|
|
603
603
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "patroon",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Pattern matching library",
|
|
5
5
|
"repository": "github:bas080/patroon",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"author": "Bassim Huis",
|
|
28
28
|
"license": "GPL-3.0",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"tape": "^5.
|
|
30
|
+
"tape": "^5.x",
|
|
31
31
|
"tape-check": "^1.0.0-rc.0",
|
|
32
32
|
"testcheck": "^1.0.0-rc.2"
|
|
33
33
|
},
|
package/src/index.test.js
CHANGED
|
@@ -57,6 +57,17 @@ test('Matches always when pattern equals value', check(gen.any, (t, val) => {
|
|
|
57
57
|
patroon(val, () => t.end())(val)
|
|
58
58
|
}))
|
|
59
59
|
|
|
60
|
+
test('Matches when empty array matches with empty array', t => {
|
|
61
|
+
patroon([], () => t.end())([])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('May or may not match with any value', check(gen.any, gen.any, (t, a, b) => {
|
|
65
|
+
patroon(
|
|
66
|
+
a, () => t.end(),
|
|
67
|
+
_, () => t.end()
|
|
68
|
+
)(b)
|
|
69
|
+
}))
|
|
70
|
+
|
|
60
71
|
test('Matches none of the patterns and throws', t => {
|
|
61
72
|
t.plan(1)
|
|
62
73
|
t.throws(() =>
|
package/src/walkable.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { isEmpty, isFunction, isNil } = require('./helpers')
|
|
1
|
+
const { isEmpty, isFunction, isNil, isPrimitive } = require('./helpers')
|
|
2
2
|
|
|
3
3
|
function walk (config, transform, item, path = []) {
|
|
4
4
|
if (config.isLeafe(item)) { return transform(item, path) }
|
|
@@ -52,7 +52,7 @@ function path (pth, v, errorData) {
|
|
|
52
52
|
|
|
53
53
|
const [key, ...rest] = pth
|
|
54
54
|
|
|
55
|
-
if (
|
|
55
|
+
if (isPrimitive(v) || !(key in v)) {
|
|
56
56
|
const error = new PathError(
|
|
57
57
|
`Cannot read path ${pth}.`)
|
|
58
58
|
|