@thi.ng/compare 2.1.38 → 2.2.1
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/CHANGELOG.md +7 -1
- package/README.md +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/ops.d.ts +74 -0
- package/ops.js +99 -0
- package/package.json +10 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-
|
|
3
|
+
- **Last updated**: 2023-10-23T07:37:37Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/compare@2.2.0) (2023-09-15)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add comparison operators/predicates ([5a627b1](https://github.com/thi-ng/umbrella/commit/5a627b1))
|
|
17
|
+
|
|
12
18
|
## [2.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/compare@2.1.0) (2021-11-17)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/ops.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Predicate2 } from "@thi.ng/api";
|
|
2
|
+
export type Operator = "=" | "!=" | "<" | "<=" | ">=" | ">";
|
|
3
|
+
export declare const OPERATORS: Record<Operator, Predicate2<string> | Predicate2<number>>;
|
|
4
|
+
/**
|
|
5
|
+
* Takes a comparison operator (either as string alias or function) and the RHS arg
|
|
6
|
+
* for it, returns a new function for given operator which only takes a single
|
|
7
|
+
* arg (i.e. the LHS of the operator) and always coerces it to a string before
|
|
8
|
+
* applying the operator.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* See {@link numericOp} for related functionality.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const equalsABC = stringOp("=", "abc");
|
|
16
|
+
*
|
|
17
|
+
* ["xyz", "abc", "def"].map(equalsABC)
|
|
18
|
+
* // [ false, true, false ]
|
|
19
|
+
*
|
|
20
|
+
* class X {
|
|
21
|
+
* constructor(public body: string) {}
|
|
22
|
+
*
|
|
23
|
+
* toString() {
|
|
24
|
+
* return this.body;
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* equalsABC(new X("abc"))
|
|
29
|
+
* // true
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param op
|
|
33
|
+
* @param x
|
|
34
|
+
*/
|
|
35
|
+
export declare const stringOp: (op: Operator | Predicate2<string>, x: string) => (y: any) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Similar to {@link stringOp}, but for numeric args. Takes a comparison
|
|
38
|
+
* operator (either as string alias or function) and the RHS arg for it, returns
|
|
39
|
+
* a new function for given operator which only takes a single arg (i.e. the LHS
|
|
40
|
+
* of the operator) and then checks if that arg is a number before applying the
|
|
41
|
+
* operator. For non-numeric args, the returned function will always return
|
|
42
|
+
* false.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const lessThan42 = numericOp("<", 42);
|
|
47
|
+
*
|
|
48
|
+
* lessThan42(41)
|
|
49
|
+
* // true
|
|
50
|
+
*
|
|
51
|
+
* lessThan42("41")
|
|
52
|
+
* // false
|
|
53
|
+
*
|
|
54
|
+
* lessThan42([41])
|
|
55
|
+
* // false
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @param op
|
|
59
|
+
* @param x
|
|
60
|
+
*/
|
|
61
|
+
export declare const numericOp: (op: Operator | Predicate2<number>, x: number) => (y: any) => boolean;
|
|
62
|
+
export declare function eq(a: string, b: string): boolean;
|
|
63
|
+
export declare function eq(a: number, b: number): boolean;
|
|
64
|
+
export declare function neq(a: string, b: string): boolean;
|
|
65
|
+
export declare function neq(a: number, b: number): boolean;
|
|
66
|
+
export declare function lt(a: string, b: string): boolean;
|
|
67
|
+
export declare function lt(a: number, b: number): boolean;
|
|
68
|
+
export declare function lte(a: string, b: string): boolean;
|
|
69
|
+
export declare function lte(a: number, b: number): boolean;
|
|
70
|
+
export declare function gte(a: string, b: string): boolean;
|
|
71
|
+
export declare function gte(a: number, b: number): boolean;
|
|
72
|
+
export declare function gt(a: string, b: string): boolean;
|
|
73
|
+
export declare function gt(a: number, b: number): boolean;
|
|
74
|
+
//# sourceMappingURL=ops.d.ts.map
|
package/ops.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export const OPERATORS = {
|
|
2
|
+
"=": eq,
|
|
3
|
+
"!=": neq,
|
|
4
|
+
"<": lt,
|
|
5
|
+
"<=": lte,
|
|
6
|
+
">=": gte,
|
|
7
|
+
">": gt,
|
|
8
|
+
};
|
|
9
|
+
const __ensure = (op) => {
|
|
10
|
+
if (typeof op === "string") {
|
|
11
|
+
if (op in OPERATORS)
|
|
12
|
+
return OPERATORS[op];
|
|
13
|
+
else
|
|
14
|
+
throw new Error(`invalid operator: ${op}`);
|
|
15
|
+
}
|
|
16
|
+
return op;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Takes a comparison operator (either as string alias or function) and the RHS arg
|
|
20
|
+
* for it, returns a new function for given operator which only takes a single
|
|
21
|
+
* arg (i.e. the LHS of the operator) and always coerces it to a string before
|
|
22
|
+
* applying the operator.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* See {@link numericOp} for related functionality.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const equalsABC = stringOp("=", "abc");
|
|
30
|
+
*
|
|
31
|
+
* ["xyz", "abc", "def"].map(equalsABC)
|
|
32
|
+
* // [ false, true, false ]
|
|
33
|
+
*
|
|
34
|
+
* class X {
|
|
35
|
+
* constructor(public body: string) {}
|
|
36
|
+
*
|
|
37
|
+
* toString() {
|
|
38
|
+
* return this.body;
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* equalsABC(new X("abc"))
|
|
43
|
+
* // true
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @param op
|
|
47
|
+
* @param x
|
|
48
|
+
*/
|
|
49
|
+
export const stringOp = (op, x) => {
|
|
50
|
+
const impl = __ensure(op);
|
|
51
|
+
return (y) => impl(String(y), x);
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Similar to {@link stringOp}, but for numeric args. Takes a comparison
|
|
55
|
+
* operator (either as string alias or function) and the RHS arg for it, returns
|
|
56
|
+
* a new function for given operator which only takes a single arg (i.e. the LHS
|
|
57
|
+
* of the operator) and then checks if that arg is a number before applying the
|
|
58
|
+
* operator. For non-numeric args, the returned function will always return
|
|
59
|
+
* false.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const lessThan42 = numericOp("<", 42);
|
|
64
|
+
*
|
|
65
|
+
* lessThan42(41)
|
|
66
|
+
* // true
|
|
67
|
+
*
|
|
68
|
+
* lessThan42("41")
|
|
69
|
+
* // false
|
|
70
|
+
*
|
|
71
|
+
* lessThan42([41])
|
|
72
|
+
* // false
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @param op
|
|
76
|
+
* @param x
|
|
77
|
+
*/
|
|
78
|
+
export const numericOp = (op, x) => {
|
|
79
|
+
const impl = __ensure(op);
|
|
80
|
+
return (y) => typeof y === "number" && impl(y, x);
|
|
81
|
+
};
|
|
82
|
+
export function eq(a, b) {
|
|
83
|
+
return a === b;
|
|
84
|
+
}
|
|
85
|
+
export function neq(a, b) {
|
|
86
|
+
return a !== b;
|
|
87
|
+
}
|
|
88
|
+
export function lt(a, b) {
|
|
89
|
+
return a < b;
|
|
90
|
+
}
|
|
91
|
+
export function lte(a, b) {
|
|
92
|
+
return a <= b;
|
|
93
|
+
}
|
|
94
|
+
export function gte(a, b) {
|
|
95
|
+
return a >= b;
|
|
96
|
+
}
|
|
97
|
+
export function gt(a, b) {
|
|
98
|
+
return a > b;
|
|
99
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/compare",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Comparators with support for types implementing the @thi.ng/api/ICompare interface",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.9.
|
|
37
|
+
"@thi.ng/api": "^8.9.6"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@microsoft/api-extractor": "^7.
|
|
41
|
-
"@thi.ng/testament": "^0.3.
|
|
42
|
-
"rimraf": "^5.0.
|
|
40
|
+
"@microsoft/api-extractor": "^7.38.0",
|
|
41
|
+
"@thi.ng/testament": "^0.3.24",
|
|
42
|
+
"rimraf": "^5.0.5",
|
|
43
43
|
"tools": "^0.0.1",
|
|
44
|
-
"typedoc": "^0.25.
|
|
44
|
+
"typedoc": "^0.25.2",
|
|
45
45
|
"typescript": "^5.2.2"
|
|
46
46
|
},
|
|
47
47
|
"keywords": [
|
|
@@ -72,9 +72,12 @@
|
|
|
72
72
|
"./numeric": {
|
|
73
73
|
"default": "./numeric.js"
|
|
74
74
|
},
|
|
75
|
+
"./ops": {
|
|
76
|
+
"default": "./ops.js"
|
|
77
|
+
},
|
|
75
78
|
"./reverse": {
|
|
76
79
|
"default": "./reverse.js"
|
|
77
80
|
}
|
|
78
81
|
},
|
|
79
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "8d46d9326a9f9b81d65e7e274446f5964f9942ac\n"
|
|
80
83
|
}
|