assert-logic 1.0.0 → 1.1.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 +22 -4
- package/assertion/every.d.ts +5 -0
- package/assertion/every.js +11 -0
- package/assertion/every.js.map +1 -0
- package/assertion/some.d.ts +5 -0
- package/assertion/some.js +11 -0
- package/assertion/some.js.map +1 -0
- package/index.d.ts +5 -1
- package/index.js +7 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
    
|
|
4
4
|
|
|
5
|
-
This handy tool can be used to implement additional logic into your assertions, either using Chai, Jest, Assert, or
|
|
6
|
-
plain JavaScript.
|
|
5
|
+
This handy tool can be used to implement additional logic into your assertions, either using Chai, Jest, Assert, or plain JavaScript.
|
|
7
6
|
|
|
8
7
|
## Usage
|
|
9
8
|
|
|
@@ -50,8 +49,10 @@ In all other cases, the value is considered passed.
|
|
|
50
49
|
|
|
51
50
|
### Operations
|
|
52
51
|
|
|
53
|
-
The API contains the following functions: `and`, `or`, `not`, `xor`, `nand`, `nor`, `xnor`, and also the `evaluate`
|
|
54
|
-
function.
|
|
52
|
+
The API contains the following functions: `and`, `or`, `not`, `xor`, `nand`, `nor`, `xnor`, `every`, `some`, and also the `evaluate`
|
|
53
|
+
function.
|
|
54
|
+
|
|
55
|
+
The following ones accept any number of sync/async functions, Promises, or values as arguments.
|
|
55
56
|
|
|
56
57
|
| Operation | Description |
|
|
57
58
|
|-----------|---------------------------------------------------------|
|
|
@@ -63,6 +64,23 @@ function. All accept any number of sync/async functions, Promises, or values as
|
|
|
63
64
|
| nor | Passes if all of its arguments fail |
|
|
64
65
|
| xnor | Passes if all of its arguments pass or all of them fail |
|
|
65
66
|
|
|
67
|
+
The `every` and `some` functions are used to evaluate an array of values. The values must be the first parameter, but both functions accept a second parameter that is a function that will be called with each value. If the function is not passed as the second parameter, the value will be interpreted as boolean values.
|
|
68
|
+
|
|
69
|
+
The `every` function is a shorthand for `and` with the values as arguments, while the `some` function is a shorthand for `or` with the values as arguments.
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
const {every, some} = require('assert-logic');
|
|
73
|
+
const {expect} = require('expect');
|
|
74
|
+
|
|
75
|
+
const items = [{id: 1, name: 'Item 1', price: 10}, {id: 2, name: 'Item 2', price: -20}, /* ... */];
|
|
76
|
+
every(items, item => {
|
|
77
|
+
expect(item.id, "Item should have ID as positive number").toBeGreaterThan(0);
|
|
78
|
+
}).evaluate(); // will not throw
|
|
79
|
+
some(items, item => {
|
|
80
|
+
expect(item.price, "Item should have a positive price").toBeGreaterThan(0);
|
|
81
|
+
}).evaluate(); // will throw
|
|
82
|
+
```
|
|
83
|
+
|
|
66
84
|
#### Append
|
|
67
85
|
|
|
68
86
|
The `append` function can be used to append additional logic to an existing variadic logic (all except `pass`).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVERYAssertion = void 0;
|
|
4
|
+
const and_1 = require("./and");
|
|
5
|
+
class EVERYAssertion extends and_1.ANDAssertion {
|
|
6
|
+
constructor(items, fn) {
|
|
7
|
+
super(...(items ? items.map((item) => () => (fn || Boolean)(item)) : []));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.EVERYAssertion = EVERYAssertion;
|
|
11
|
+
//# sourceMappingURL=every.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"every.js","sourceRoot":"","sources":["../../src/assertion/every.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AAGnC,MAAa,cAAkB,SAAQ,kBAAY;IAC/C,YAAY,KAAU,EAAE,EAAiC;QACrD,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9E,CAAC;CACJ;AAJD,wCAIC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SOMEAssertion = void 0;
|
|
4
|
+
const or_1 = require("./or");
|
|
5
|
+
class SOMEAssertion extends or_1.ORAssertion {
|
|
6
|
+
constructor(items, fn) {
|
|
7
|
+
super(...(items ? items.map((item) => () => (fn || Boolean)(item)) : []));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.SOMEAssertion = SOMEAssertion;
|
|
11
|
+
//# sourceMappingURL=some.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"some.js","sourceRoot":"","sources":["../../src/assertion/some.ts"],"names":[],"mappings":";;;AAAA,6BAAiC;AAGjC,MAAa,aAAiB,SAAQ,gBAAW;IAC7C,YAAY,KAAU,EAAE,EAAiC;QACrD,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9E,CAAC;CACJ;AAJD,sCAIC"}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AssertionValue } from "./types";
|
|
1
|
+
import type { AssertionValue, AssertionGeneratorFunction } from "./types";
|
|
2
2
|
import { PASSAssertion } from "./assertion/pass";
|
|
3
3
|
import { NOTAssertion } from "./assertion/not";
|
|
4
4
|
import { ORAssertion } from "./assertion/or";
|
|
@@ -7,6 +7,8 @@ import { XORAssertion } from "./assertion/xor";
|
|
|
7
7
|
import { NORAssertion } from "./assertion/nor";
|
|
8
8
|
import { NANDAssertion } from "./assertion/nand";
|
|
9
9
|
import { XNORAssertion } from "./assertion/xnor";
|
|
10
|
+
import { EVERYAssertion } from "./assertion/every";
|
|
11
|
+
import { SOMEAssertion } from "./assertion/some";
|
|
10
12
|
export declare const pass: (value: AssertionValue) => PASSAssertion;
|
|
11
13
|
export declare const not: (value: AssertionValue) => NOTAssertion;
|
|
12
14
|
export declare const or: (...values: AssertionValue[]) => ORAssertion;
|
|
@@ -15,3 +17,5 @@ export declare const nor: (...values: AssertionValue[]) => NORAssertion;
|
|
|
15
17
|
export declare const nand: (...values: AssertionValue[]) => NANDAssertion;
|
|
16
18
|
export declare const xor: (...values: AssertionValue[]) => XORAssertion;
|
|
17
19
|
export declare const xnor: (...values: AssertionValue[]) => XNORAssertion;
|
|
20
|
+
export declare const every: <T>(items: T[], fn?: AssertionGeneratorFunction<T>) => EVERYAssertion<T>;
|
|
21
|
+
export declare const some: <T>(items: T[], fn?: AssertionGeneratorFunction<T>) => SOMEAssertion<T>;
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// import debug = require("debug");
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.xnor = exports.xor = exports.nand = exports.nor = exports.and = exports.or = exports.not = exports.pass = void 0;
|
|
4
|
+
exports.some = exports.every = exports.xnor = exports.xor = exports.nand = exports.nor = exports.and = exports.or = exports.not = exports.pass = void 0;
|
|
5
5
|
const pass_1 = require("./assertion/pass");
|
|
6
6
|
const not_1 = require("./assertion/not");
|
|
7
7
|
const or_1 = require("./assertion/or");
|
|
@@ -10,6 +10,8 @@ const xor_1 = require("./assertion/xor");
|
|
|
10
10
|
const nor_1 = require("./assertion/nor");
|
|
11
11
|
const nand_1 = require("./assertion/nand");
|
|
12
12
|
const xnor_1 = require("./assertion/xnor");
|
|
13
|
+
const every_1 = require("./assertion/every");
|
|
14
|
+
const some_1 = require("./assertion/some");
|
|
13
15
|
const lines_builder_1 = require("lines-builder");
|
|
14
16
|
(0, lines_builder_1.setDefaultOptions)({
|
|
15
17
|
// Need to force EOL to be Unix style, because Windows style is not supported by YAML
|
|
@@ -34,4 +36,8 @@ const xor = (...values) => new xor_1.XORAssertion(...values);
|
|
|
34
36
|
exports.xor = xor;
|
|
35
37
|
const xnor = (...values) => new xnor_1.XNORAssertion(...values);
|
|
36
38
|
exports.xnor = xnor;
|
|
39
|
+
const every = (items, fn) => new every_1.EVERYAssertion(items, fn);
|
|
40
|
+
exports.every = every;
|
|
41
|
+
const some = (items, fn) => new some_1.SOMEAssertion(items, fn);
|
|
42
|
+
exports.some = some;
|
|
37
43
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,mCAAmC;;;AAKnC,2CAA+C;AAC/C,yCAA6C;AAC7C,uCAA2C;AAC3C,yCAA6C;AAC7C,yCAA6C;AAC7C,yCAA6C;AAC7C,2CAA+C;AAC/C,2CAA+C;AAE/C,iDAAgD;AAEhD,IAAA,iCAAiB,EAAC;IAChB,qFAAqF;IACrF,GAAG,EAAE,IAAI;IACT,QAAQ,EAAE,KAAK;IACf,oBAAoB,EAAE,IAAI;IAC1B,MAAM,EAAE,CAAC;CACV,CAAC,CAAC;AAEI,MAAM,IAAI,GAAG,CAAC,KAAqB,EAAE,EAAE,CAAC,IAAI,oBAAa,CAAC,KAAK,CAAC,CAAC;AAA3D,QAAA,IAAI,QAAuD;AACjE,MAAM,GAAG,GAAG,CAAC,KAAqB,EAAE,EAAE,CAAC,IAAI,kBAAY,CAAC,KAAK,CAAC,CAAC;AAAzD,QAAA,GAAG,OAAsD;AAC/D,MAAM,EAAE,GAAG,CAAC,GAAG,MAAwB,EAAE,EAAE,CAAC,IAAI,gBAAW,CAAC,GAAG,MAAM,CAAC,CAA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