@weborigami/async-tree 0.3.2 → 0.3.3-jse.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/package.json +2 -2
- package/shared.js +1 -1
- package/src/operations/deepText.js +23 -19
- package/src/operations/text.js +25 -0
- package/test/operations/deepText.test.js +27 -5
- package/test/operations/text.test.js +12 -0
- package/src/operations/concat.js +0 -29
- package/test/operations/concat.test.js +0 -34
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/async-tree",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3-jse.1",
|
|
4
4
|
"description": "Asynchronous tree drivers based on standard JavaScript classes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./main.js",
|
|
7
7
|
"browser": "./browser.js",
|
|
8
8
|
"types": "./index.ts",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@weborigami/types": "0.3.
|
|
10
|
+
"@weborigami/types": "0.3.3-jse.1"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@types/node": "22.13.13",
|
package/shared.js
CHANGED
|
@@ -14,7 +14,6 @@ export * as jsonKeys from "./src/jsonKeys.js";
|
|
|
14
14
|
export { default as addNextPrevious } from "./src/operations/addNextPrevious.js";
|
|
15
15
|
export { default as cache } from "./src/operations/cache.js";
|
|
16
16
|
export { default as cachedKeyFunctions } from "./src/operations/cachedKeyFunctions.js";
|
|
17
|
-
export { default as concat } from "./src/operations/concat.js";
|
|
18
17
|
export { default as deepMerge } from "./src/operations/deepMerge.js";
|
|
19
18
|
export { default as deepReverse } from "./src/operations/deepReverse.js";
|
|
20
19
|
export { default as deepTake } from "./src/operations/deepTake.js";
|
|
@@ -34,6 +33,7 @@ export { default as reverse } from "./src/operations/reverse.js";
|
|
|
34
33
|
export { default as scope } from "./src/operations/scope.js";
|
|
35
34
|
export { default as sort } from "./src/operations/sort.js";
|
|
36
35
|
export { default as take } from "./src/operations/take.js";
|
|
36
|
+
export { default as text } from "./src/operations/text.js";
|
|
37
37
|
export * as symbols from "./src/symbols.js";
|
|
38
38
|
export * as trailingSlash from "./src/trailingSlash.js";
|
|
39
39
|
export { default as TraverseError } from "./src/TraverseError.js";
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import concat from "./concat.js";
|
|
1
|
+
import { assertIsTreelike, toString } from "../utilities.js";
|
|
2
|
+
import deepValuesIterator from "./deepValuesIterator.js";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
* tree. Any treelike values will be concatenated using `concat`.
|
|
5
|
+
* Concatenate the deep text values in a tree.
|
|
8
6
|
*
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {...any} values
|
|
7
|
+
* @param {import("../../index.ts").Treelike} treelike
|
|
11
8
|
*/
|
|
12
|
-
export default async function deepText(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
export default async function deepText(treelike) {
|
|
10
|
+
assertIsTreelike(treelike, "text");
|
|
11
|
+
|
|
12
|
+
const strings = [];
|
|
13
|
+
for await (const value of deepValuesIterator(treelike, { expand: true })) {
|
|
14
|
+
let string;
|
|
15
|
+
if (value === null) {
|
|
16
|
+
string = "null";
|
|
17
|
+
} else if (value === undefined) {
|
|
18
|
+
string = "undefined";
|
|
19
|
+
} else {
|
|
20
|
+
string = toString(value);
|
|
21
|
+
}
|
|
22
|
+
if (value === null || value === undefined) {
|
|
23
|
+
const message = `Warning: a template encountered a ${string} value. To locate where this happened, build your project and search your build output for the text "${string}".`;
|
|
24
|
+
console.warn(message);
|
|
25
|
+
}
|
|
26
|
+
strings.push(string);
|
|
23
27
|
}
|
|
24
|
-
return
|
|
28
|
+
return strings.join("");
|
|
25
29
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Tree } from "../internal.js";
|
|
2
|
+
import { toString } from "../utilities.js";
|
|
3
|
+
import deepText from "./deepText.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A tagged template literal function that concatenate the deep text values in a
|
|
7
|
+
* tree. Any treelike values will be concatenated using `deepText`.
|
|
8
|
+
*
|
|
9
|
+
* @param {TemplateStringsArray} strings
|
|
10
|
+
* @param {...any} values
|
|
11
|
+
*/
|
|
12
|
+
export default async function text(strings, ...values) {
|
|
13
|
+
// Convert all the values to strings
|
|
14
|
+
const valueTexts = await Promise.all(
|
|
15
|
+
values.map((value) =>
|
|
16
|
+
Tree.isTreelike(value) ? deepText(value) : toString(value)
|
|
17
|
+
)
|
|
18
|
+
);
|
|
19
|
+
// Splice all the strings together
|
|
20
|
+
let result = strings[0];
|
|
21
|
+
for (let i = 0; i < valueTexts.length; i++) {
|
|
22
|
+
result += valueTexts[i] + strings[i + 1];
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
+
import FunctionTree from "../../src/drivers/FunctionTree.js";
|
|
4
|
+
import { Tree } from "../../src/internal.js";
|
|
3
5
|
import deepText from "../../src/operations/deepText.js";
|
|
4
6
|
|
|
5
7
|
describe("deepText", () => {
|
|
6
|
-
test("
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
test("concatenates deep tree values", async () => {
|
|
9
|
+
const tree = Tree.from({
|
|
10
|
+
a: "A",
|
|
11
|
+
b: "B",
|
|
12
|
+
c: "C",
|
|
13
|
+
more: {
|
|
14
|
+
d: "D",
|
|
15
|
+
e: "E",
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
const result = await deepText(tree);
|
|
19
|
+
assert.equal(result, "ABCDE");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("concatenates deep tree-like values", async () => {
|
|
23
|
+
const letters = ["a", "b", "c"];
|
|
24
|
+
const specimens = new FunctionTree(
|
|
25
|
+
(letter) => ({
|
|
26
|
+
lowercase: letter,
|
|
27
|
+
uppercase: letter.toUpperCase(),
|
|
28
|
+
}),
|
|
29
|
+
letters
|
|
30
|
+
);
|
|
31
|
+
const result = await deepText(specimens);
|
|
32
|
+
assert.equal(result, "aAbBcC");
|
|
11
33
|
});
|
|
12
34
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { describe, test } from "node:test";
|
|
3
|
+
import text from "../../src/operations/text.js";
|
|
4
|
+
|
|
5
|
+
describe("text template literal function", () => {
|
|
6
|
+
test("joins strings and values together", async () => {
|
|
7
|
+
const array = [1, 2, 3];
|
|
8
|
+
const object = { person1: "Alice", person2: "Bob" };
|
|
9
|
+
const result = await text`a ${array} b ${object} c`;
|
|
10
|
+
assert.equal(result, "a 123 b AliceBob c");
|
|
11
|
+
});
|
|
12
|
+
});
|
package/src/operations/concat.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { assertIsTreelike, toString } from "../utilities.js";
|
|
2
|
-
import deepValuesIterator from "./deepValuesIterator.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Concatenate the deep text values in a tree.
|
|
6
|
-
*
|
|
7
|
-
* @param {import("../../index.ts").Treelike} treelike
|
|
8
|
-
*/
|
|
9
|
-
export default async function concat(treelike) {
|
|
10
|
-
assertIsTreelike(treelike, "concat");
|
|
11
|
-
|
|
12
|
-
const strings = [];
|
|
13
|
-
for await (const value of deepValuesIterator(treelike, { expand: true })) {
|
|
14
|
-
let string;
|
|
15
|
-
if (value === null) {
|
|
16
|
-
string = "null";
|
|
17
|
-
} else if (value === undefined) {
|
|
18
|
-
string = "undefined";
|
|
19
|
-
} else {
|
|
20
|
-
string = toString(value);
|
|
21
|
-
}
|
|
22
|
-
if (value === null || value === undefined) {
|
|
23
|
-
const message = `Warning: Origami template encountered a ${string} value. To locate where this happened, build your project and search your build output for the text "${string}".`;
|
|
24
|
-
console.warn(message);
|
|
25
|
-
}
|
|
26
|
-
strings.push(string);
|
|
27
|
-
}
|
|
28
|
-
return strings.join("");
|
|
29
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert";
|
|
2
|
-
import { describe, test } from "node:test";
|
|
3
|
-
import FunctionTree from "../../src/drivers/FunctionTree.js";
|
|
4
|
-
import { Tree } from "../../src/internal.js";
|
|
5
|
-
import concat from "../../src/operations/concat.js";
|
|
6
|
-
|
|
7
|
-
describe("concat", () => {
|
|
8
|
-
test("concatenates deep tree values", async () => {
|
|
9
|
-
const tree = Tree.from({
|
|
10
|
-
a: "A",
|
|
11
|
-
b: "B",
|
|
12
|
-
c: "C",
|
|
13
|
-
more: {
|
|
14
|
-
d: "D",
|
|
15
|
-
e: "E",
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
const result = await concat.call(null, tree);
|
|
19
|
-
assert.equal(result, "ABCDE");
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test("concatenates deep tree-like values", async () => {
|
|
23
|
-
const letters = ["a", "b", "c"];
|
|
24
|
-
const specimens = new FunctionTree(
|
|
25
|
-
(letter) => ({
|
|
26
|
-
lowercase: letter,
|
|
27
|
-
uppercase: letter.toUpperCase(),
|
|
28
|
-
}),
|
|
29
|
-
letters
|
|
30
|
-
);
|
|
31
|
-
const result = await concat.call(null, specimens);
|
|
32
|
-
assert.equal(result, "aAbBcC");
|
|
33
|
-
});
|
|
34
|
-
});
|