@lionweb/ts-utils 0.6.13-beta.5 → 0.7.0-beta.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/CHANGELOG.md +3 -1
- package/README.md +1 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/string-sorting.d.ts +8 -0
- package/dist/string-sorting.d.ts.map +1 -0
- package/dist/string-sorting.js +13 -0
- package/dist/string-sorting.js.map +1 -0
- package/dist/toposort.d.ts +6 -0
- package/dist/toposort.d.ts.map +1 -0
- package/dist/toposort.js +41 -0
- package/dist/toposort.js.map +1 -0
- package/package.json +2 -2
- package/dist/sorting.d.ts +0 -7
- package/dist/sorting.d.ts.map +0 -1
- package/dist/sorting.js +0 -7
- package/dist/sorting.js.map +0 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -12,9 +12,8 @@ An NPM package that can be added to a Node.js/NPM codebase as follows:
|
|
|
12
12
|
```shell
|
|
13
13
|
$ npm add @lionweb/ts-utils
|
|
14
14
|
```
|
|
15
|
-
It contains:
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
It contains general TypeScript utilities, e.g. for working with maps and such.
|
|
18
17
|
|
|
19
18
|
|
|
20
19
|
## Development
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./graphs.js";
|
|
|
4
4
|
export * from "./map-helpers.js";
|
|
5
5
|
export * from "./nested-map.js";
|
|
6
6
|
export * from "./recursion.js";
|
|
7
|
-
export * from "./sorting.js";
|
|
7
|
+
export * from "./string-sorting.js";
|
|
8
8
|
export * from "./string-mapping.js";
|
|
9
|
+
export * from "./toposort.js";
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./graphs.js";
|
|
|
4
4
|
export * from "./map-helpers.js";
|
|
5
5
|
export * from "./nested-map.js";
|
|
6
6
|
export * from "./recursion.js";
|
|
7
|
-
export * from "./sorting.js";
|
|
7
|
+
export * from "./string-sorting.js";
|
|
8
8
|
export * from "./string-mapping.js";
|
|
9
|
+
export * from "./toposort.js";
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Various functional utilities for sorting things.
|
|
3
|
+
*/
|
|
4
|
+
export declare const sortByStringKey: <T>(ts: T[], keyFunc: (t: T) => string) => T[];
|
|
5
|
+
export type StringSorter = (strings: string[]) => string[];
|
|
6
|
+
export declare const sortedStrings: StringSorter;
|
|
7
|
+
export declare const sortedStringsByUppercase: StringSorter;
|
|
8
|
+
//# sourceMappingURL=string-sorting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-sorting.d.ts","sourceRoot":"","sources":["../src/string-sorting.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,eAAO,MAAM,eAAe,kCAAmC,MAAM,QAC5B,CAAA;AAGzC,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAA;AAQ1D,eAAO,MAAM,aAAa,cAAkC,CAAA;AAE5D,eAAO,MAAM,wBAAwB,cAAgD,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Various functional utilities for sorting things.
|
|
3
|
+
*/
|
|
4
|
+
const stringCompare = (l, r) => l === r ? 0 : (l > r ? 1 : -1);
|
|
5
|
+
const stringyCompare = (keyFunc) => (l, r) => stringCompare(keyFunc(l), keyFunc(r));
|
|
6
|
+
export const sortByStringKey = (ts, keyFunc) => [...ts].sort(stringyCompare(keyFunc));
|
|
7
|
+
const sortedStringsWith = (strMap) => (strings) => {
|
|
8
|
+
strings.sort((l, r) => strMap(l).localeCompare(strMap(r)));
|
|
9
|
+
return strings;
|
|
10
|
+
};
|
|
11
|
+
export const sortedStrings = sortedStringsWith((str) => str);
|
|
12
|
+
export const sortedStringsByUppercase = sortedStringsWith((str) => str.toUpperCase());
|
|
13
|
+
//# sourceMappingURL=string-sorting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-sorting.js","sourceRoot":"","sources":["../src/string-sorting.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,MAAM,aAAa,GAAqB,CAAC,CAAC,EAAE,CAAC,EAAU,EAAE,CACrD,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAElC,MAAM,cAAc,GAAG,CAAI,OAAyB,EAAe,EAAE,CACjE,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AAEzD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAI,EAAO,EAAE,OAAyB,EAAE,EAAE,CACrE,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;AAKzC,MAAM,iBAAiB,GAAG,CAAC,MAA+B,EAAgB,EAAE,CACxE,CAAC,OAAO,EAAE,EAAE;IACR,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC1D,OAAO,OAAO,CAAA;AAClB,CAAC,CAAA;AAEL,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAA;AAE5D,MAAM,CAAC,MAAM,wBAAwB,GAAG,iBAAiB,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the topological order of the transitive closure of the graph with the given vertices and edges given by the edge function,
|
|
3
|
+
* or returns {@code false} if there's a cycle.
|
|
4
|
+
*/
|
|
5
|
+
export declare const dependencyOrderOf: <T>(vertices: T[], edgesOf: (vertex: T) => T[]) => false | T[];
|
|
6
|
+
//# sourceMappingURL=toposort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toposort.d.ts","sourceRoot":"","sources":["../src/toposort.ts"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,eAAO,MAAM,iBAAiB,gEA0B7B,CAAA"}
|
package/dist/toposort.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright 2025 TRUMPF Laser SE and other contributors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License")
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
/**
|
|
18
|
+
* Computes the topological order of the transitive closure of the graph with the given vertices and edges given by the edge function,
|
|
19
|
+
* or returns {@code false} if there's a cycle.
|
|
20
|
+
*/
|
|
21
|
+
export const dependencyOrderOf = (vertices, edgesOf) => {
|
|
22
|
+
const ordered = [];
|
|
23
|
+
const visit = (current, chain) => {
|
|
24
|
+
if (ordered.indexOf(current) > -1) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (chain.indexOf(current) > -1) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
const extendedChain = [...chain, current];
|
|
31
|
+
const hasCycle = edgesOf(current).some((edge) => visit(edge, extendedChain));
|
|
32
|
+
ordered.push(current);
|
|
33
|
+
if (hasCycle) {
|
|
34
|
+
console.dir(ordered);
|
|
35
|
+
}
|
|
36
|
+
return hasCycle;
|
|
37
|
+
};
|
|
38
|
+
const hasCycle = vertices.some((vertex) => visit(vertex, []));
|
|
39
|
+
return hasCycle ? false : ordered;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=toposort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toposort.js","sourceRoot":"","sources":["../src/toposort.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,EAAE;AACF,sEAAsE;AACtE,sCAAsC;AAEtC;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAI,QAAa,EAAE,OAA2B,EAAe,EAAE;IAC5F,MAAM,OAAO,GAAQ,EAAE,CAAA;IAEvB,MAAM,KAAK,GAAG,CAAC,OAAU,EAAE,KAAU,EAAE,EAAE;QACrC,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAChC,OAAO,KAAK,CAAA;QAChB,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAA;QACf,CAAC;QACD,MAAM,aAAa,GAAG,CAAE,GAAG,KAAK,EAAE,OAAO,CAAE,CAAA;QAC3C,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAClC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC,CACvC,CAAA;QACD,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACrB,IAAI,QAAQ,EAAE,CAAC;YACX,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QACxB,CAAC;QACD,OAAO,QAAQ,CAAA;IACnB,CAAC,CAAA;IAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAC1B,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,CAChC,CAAA;IAED,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAA;AACrC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lionweb/ts-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-beta.0",
|
|
4
4
|
"description": "Utilities for LionWeb JSON",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"url": "https://github.com/LionWeb-io/lionweb-typescript/issues"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
|
-
"clean": "rm -rf dist/ lionweb-ts-utils-*.tgz",
|
|
18
|
+
"clean": "rm -rf dist/ node_modules/ lionweb-ts-utils-*.tgz",
|
|
19
19
|
"build": "tsc",
|
|
20
20
|
"lint": "eslint src",
|
|
21
21
|
"pre-release-either": "npm run clean && npm install && npm run build",
|
package/dist/sorting.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Various functional utilities for sorting things.
|
|
3
|
-
*/
|
|
4
|
-
export type Comparer<T> = (l: T, r: T) => number;
|
|
5
|
-
export declare const stringyCompare: <T>(keyFunc: (t: T) => string) => Comparer<T>;
|
|
6
|
-
export declare const sortByStringKey: <T>(ts: T[], keyFunc: (t: T) => string) => T[];
|
|
7
|
-
//# sourceMappingURL=sorting.d.ts.map
|
package/dist/sorting.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sorting.d.ts","sourceRoot":"","sources":["../src/sorting.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,CAAA;AAKhD,eAAO,MAAM,cAAc,yBAA0B,MAAM,gBACF,CAAA;AAEzD,eAAO,MAAM,eAAe,kCAAmC,MAAM,QAC5B,CAAA"}
|
package/dist/sorting.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Various functional utilities for sorting things.
|
|
3
|
-
*/
|
|
4
|
-
const stringCompare = (l, r) => l === r ? 0 : (l > r ? 1 : -1);
|
|
5
|
-
export const stringyCompare = (keyFunc) => (l, r) => stringCompare(keyFunc(l), keyFunc(r));
|
|
6
|
-
export const sortByStringKey = (ts, keyFunc) => [...ts].sort(stringyCompare(keyFunc));
|
|
7
|
-
//# sourceMappingURL=sorting.js.map
|
package/dist/sorting.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sorting.js","sourceRoot":"","sources":["../src/sorting.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,MAAM,aAAa,GAAqB,CAAC,CAAC,EAAE,CAAC,EAAU,EAAE,CACrD,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAElC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAI,OAAyB,EAAe,EAAE,CACxE,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AAEzD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAI,EAAO,EAAE,OAAyB,EAAE,EAAE,CACrE,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA"}
|