@thi.ng/compare 2.4.39 → 2.5.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/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 213 standalone projects, maintained as part
10
+ > This is one of 214 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -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: 804 bytes
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
@@ -1,4 +1,5 @@
1
1
  export * from "./compare.js";
2
+ export * from "./compose.js";
2
3
  export * from "./keys.js";
3
4
  export * from "./length.js";
4
5
  export * from "./numeric.js";
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./compare.js";
2
+ export * from "./compose.js";
2
3
  export * from "./keys.js";
3
4
  export * from "./length.js";
4
5
  export * from "./numeric.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/compare",
3
- "version": "2.4.39",
3
+ "version": "2.5.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",
@@ -8,7 +8,8 @@
8
8
  "sideEffects": false,
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/thi-ng/umbrella.git"
11
+ "url": "git+https://github.com/thi-ng/umbrella.git",
12
+ "directory": "packages/compare"
12
13
  },
13
14
  "homepage": "https://thi.ng/compare",
14
15
  "funding": [
@@ -39,7 +40,7 @@
39
40
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
40
41
  },
41
42
  "dependencies": {
42
- "@thi.ng/api": "^8.12.13"
43
+ "@thi.ng/api": "^8.12.15"
43
44
  },
44
45
  "devDependencies": {
45
46
  "esbuild": "^0.27.2",
@@ -68,6 +69,9 @@
68
69
  "./compare": {
69
70
  "default": "./compare.js"
70
71
  },
72
+ "./compose": {
73
+ "default": "./compose.js"
74
+ },
71
75
  "./keys": {
72
76
  "default": "./keys.js"
73
77
  },
@@ -90,5 +94,5 @@
90
94
  "thi.ng": {
91
95
  "alias": "cmp"
92
96
  },
93
- "gitHead": "828ec2e9ffde7307231b03cff46598c0915b1857\n"
97
+ "gitHead": "8f50352caab9ec7757d645c0afa605dfb5427abe\n"
94
98
  }