@thi.ng/compare 2.4.40 → 2.5.2
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 -1
- package/compose.d.ts +10 -0
- package/compose.js +17 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -40,6 +40,7 @@ interface.
|
|
|
40
40
|
|
|
41
41
|
### Additional comparators
|
|
42
42
|
|
|
43
|
+
- [`composeComparators()`](https://docs.thi.ng/umbrella/compare/functions/composeComparators.html)
|
|
43
44
|
- [`compareByKey()`](https://docs.thi.ng/umbrella/compare/functions/compareByKey.html)
|
|
44
45
|
- [`compareByKeys2()`](https://docs.thi.ng/umbrella/compare/functions/compareByKeys2.html)
|
|
45
46
|
- [`compareByKeys3()`](https://docs.thi.ng/umbrella/compare/functions/compareByKeys3.html)
|
|
@@ -94,7 +95,7 @@ For Node.js REPL:
|
|
|
94
95
|
const cmp = await import("@thi.ng/compare");
|
|
95
96
|
```
|
|
96
97
|
|
|
97
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
98
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 870 bytes
|
|
98
99
|
|
|
99
100
|
## Dependencies
|
|
100
101
|
|
package/compose.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Comparator } from "@thi.ng/api";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a comparator which applies given comparators in given order for as
|
|
4
|
+
* long as the current comparator returns 0. In other words, returns the result
|
|
5
|
+
* of the first comparator with non-zero result, or if none does, returns zero.
|
|
6
|
+
*
|
|
7
|
+
* @param cmp
|
|
8
|
+
*/
|
|
9
|
+
export declare const composeComparators: <T = any>(cmp: Comparator<T>, ...xs: Comparator<T>[]) => Comparator<T>;
|
|
10
|
+
//# sourceMappingURL=compose.d.ts.map
|
package/compose.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const composeComparators = (cmp, ...xs) => {
|
|
2
|
+
if (xs.length) {
|
|
3
|
+
const fns = [cmp, ...xs];
|
|
4
|
+
const n = fns.length;
|
|
5
|
+
return (a, b) => {
|
|
6
|
+
for (let i = 0; i < n; i++) {
|
|
7
|
+
const res = fns[i](a, b);
|
|
8
|
+
if (res !== 0) return res;
|
|
9
|
+
}
|
|
10
|
+
return 0;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return cmp;
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
composeComparators
|
|
17
|
+
};
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/compare",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.2",
|
|
4
4
|
"description": "Comparators with support for types implementing the @thi.ng/api/ICompare interface",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@thi.ng/api": "^8.12.
|
|
43
|
+
"@thi.ng/api": "^8.12.16"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"esbuild": "^0.27.2",
|
|
@@ -69,6 +69,9 @@
|
|
|
69
69
|
"./compare": {
|
|
70
70
|
"default": "./compare.js"
|
|
71
71
|
},
|
|
72
|
+
"./compose": {
|
|
73
|
+
"default": "./compose.js"
|
|
74
|
+
},
|
|
72
75
|
"./keys": {
|
|
73
76
|
"default": "./keys.js"
|
|
74
77
|
},
|
|
@@ -91,5 +94,5 @@
|
|
|
91
94
|
"thi.ng": {
|
|
92
95
|
"alias": "cmp"
|
|
93
96
|
},
|
|
94
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "411adbeeb5c03da1cf0c86e567c80942a6b875e7\n"
|
|
95
98
|
}
|