@weborigami/async-tree 0.6.2 → 0.6.3
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 +1 -1
- package/src/Tree.js +1 -0
- package/src/operations/visit.js +14 -0
- package/test/operations/visit.test.js +25 -0
package/package.json
CHANGED
package/src/Tree.js
CHANGED
|
@@ -67,4 +67,5 @@ export { default as traverse } from "./operations/traverse.js";
|
|
|
67
67
|
export { default as traverseOrThrow } from "./operations/traverseOrThrow.js";
|
|
68
68
|
export { default as traversePath } from "./operations/traversePath.js";
|
|
69
69
|
export { default as values } from "./operations/values.js";
|
|
70
|
+
export { default as visit } from "./operations/visit.js";
|
|
70
71
|
export { default as withKeys } from "./operations/withKeys.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import getMapArgument from "../utilities/getMapArgument.js";
|
|
2
|
+
import reduce from "./reduce.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Visit every node in the tree and return `undefined`.
|
|
6
|
+
*
|
|
7
|
+
* @typedef {import("../../index.ts").Maplike} Maplike
|
|
8
|
+
*
|
|
9
|
+
* @param {Maplike} source
|
|
10
|
+
*/
|
|
11
|
+
export default async function visit(source) {
|
|
12
|
+
const tree = await getMapArgument(source, "visit", { deep: true });
|
|
13
|
+
return reduce(tree, () => undefined);
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { describe, test } from "node:test";
|
|
3
|
+
import FunctionMap from "../../src/drivers/FunctionMap.js";
|
|
4
|
+
import visit from "../../src/operations/visit.js";
|
|
5
|
+
|
|
6
|
+
describe("visit", () => {
|
|
7
|
+
test("visits every node in the tree", async () => {
|
|
8
|
+
const values = [];
|
|
9
|
+
const map = new FunctionMap(
|
|
10
|
+
(key) => {
|
|
11
|
+
const value = `value for ${key}`;
|
|
12
|
+
values.push(value);
|
|
13
|
+
return value;
|
|
14
|
+
},
|
|
15
|
+
["a", "b", "c"]
|
|
16
|
+
);
|
|
17
|
+
const result = await visit(map);
|
|
18
|
+
assert.strictEqual(result, undefined);
|
|
19
|
+
assert.deepStrictEqual(values, [
|
|
20
|
+
"value for a",
|
|
21
|
+
"value for b",
|
|
22
|
+
"value for c",
|
|
23
|
+
]);
|
|
24
|
+
});
|
|
25
|
+
});
|