@weborigami/async-tree 0.0.68 → 0.0.70
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/package.json +2 -2
- package/src/utilities.d.ts +1 -0
- package/src/utilities.js +13 -0
- package/test/utilities.test.js +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/async-tree",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.70",
|
|
4
4
|
"description": "Asynchronous tree drivers based on standard JavaScript classes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./main.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"typescript": "5.6.2"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@weborigami/types": "0.0.
|
|
14
|
+
"@weborigami/types": "0.0.70"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"test": "node --test --test-reporter=spec",
|
package/src/utilities.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export function isStringLike(obj: any): obj is StringLike;
|
|
|
11
11
|
export function isUnpackable(obj): obj is { unpack: () => any };
|
|
12
12
|
export function keysFromPath(path: string): string[];
|
|
13
13
|
export const naturalOrder: (a: string, b: string) => number;
|
|
14
|
+
export function pathFromKeys(keys: string[]): string;
|
|
14
15
|
export function pipeline(start: any, ...functions: Function[]): Promise<any>;
|
|
15
16
|
export function setParent(child: any, parent: AsyncTree): void;
|
|
16
17
|
export function toPlainValue(object: any): Promise<any>;
|
package/src/utilities.js
CHANGED
|
@@ -210,6 +210,19 @@ export const naturalOrder = new Intl.Collator(undefined, {
|
|
|
210
210
|
numeric: true,
|
|
211
211
|
}).compare;
|
|
212
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Return a slash-separated path for the given keys.
|
|
215
|
+
*
|
|
216
|
+
* This takes care to avoid adding consecutive slashes if they keys themselves
|
|
217
|
+
* already have trailing slashes.
|
|
218
|
+
*
|
|
219
|
+
* @param {string[]} keys
|
|
220
|
+
*/
|
|
221
|
+
export function pathFromKeys(keys) {
|
|
222
|
+
const normalized = keys.map((key) => trailingSlash.remove(key));
|
|
223
|
+
return normalized.join("/");
|
|
224
|
+
}
|
|
225
|
+
|
|
213
226
|
/**
|
|
214
227
|
* Apply a series of functions to a value, passing the result of each function
|
|
215
228
|
* to the next one.
|
package/test/utilities.test.js
CHANGED
|
@@ -55,6 +55,12 @@ describe("utilities", () => {
|
|
|
55
55
|
assert.deepEqual(strings, ["file1", "file9", "file10"]);
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
+
test("pathFromKeys() returns a slash-separated path from keys", () => {
|
|
59
|
+
assert.equal(utilities.pathFromKeys([]), "");
|
|
60
|
+
assert.equal(utilities.pathFromKeys(["a", "b", "c"]), "a/b/c");
|
|
61
|
+
assert.equal(utilities.pathFromKeys(["a/", "b/", "c"]), "a/b/c");
|
|
62
|
+
});
|
|
63
|
+
|
|
58
64
|
test("pipeline applies a series of functions to a value", async () => {
|
|
59
65
|
const addOne = (n) => n + 1;
|
|
60
66
|
const double = (n) => n * 2;
|