@weborigami/async-tree 0.5.7 → 0.6.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/browser.js +1 -1
- package/index.ts +31 -35
- package/main.js +1 -2
- package/package.json +4 -7
- package/shared.js +77 -12
- package/src/Tree.js +8 -2
- package/src/drivers/AsyncMap.js +210 -0
- package/src/drivers/{BrowserFileTree.js → BrowserFileMap.js} +36 -27
- package/src/drivers/{calendarTree.js → CalendarMap.js} +81 -62
- package/src/drivers/ConstantMap.js +30 -0
- package/src/drivers/DeepObjectMap.js +27 -0
- package/src/drivers/{ExplorableSiteTree.js → ExplorableSiteMap.js} +7 -7
- package/src/drivers/FileMap.js +245 -0
- package/src/drivers/{FunctionTree.js → FunctionMap.js} +19 -22
- package/src/drivers/ObjectMap.js +139 -0
- package/src/drivers/SetMap.js +13 -0
- package/src/drivers/{SiteTree.js → SiteMap.js} +16 -17
- package/src/drivers/SyncMap.js +245 -0
- package/src/jsonKeys.d.ts +2 -2
- package/src/jsonKeys.js +6 -5
- package/src/operations/addNextPrevious.js +35 -36
- package/src/operations/assign.js +30 -21
- package/src/operations/cache.js +29 -35
- package/src/operations/cachedKeyFunctions.js +1 -1
- package/src/operations/calendar.js +5 -0
- package/src/operations/clear.js +13 -12
- package/src/operations/constant.js +5 -0
- package/src/operations/deepEntries.js +23 -0
- package/src/operations/deepMap.js +9 -9
- package/src/operations/deepMerge.js +36 -25
- package/src/operations/deepReverse.js +23 -16
- package/src/operations/deepTake.js +7 -7
- package/src/operations/deepText.js +4 -4
- package/src/operations/deepValues.js +3 -6
- package/src/operations/deepValuesIterator.js +11 -11
- package/src/operations/delete.js +8 -12
- package/src/operations/entries.js +17 -10
- package/src/operations/filter.js +9 -7
- package/src/operations/first.js +12 -10
- package/src/operations/forEach.js +10 -13
- package/src/operations/from.js +31 -39
- package/src/operations/globKeys.js +22 -17
- package/src/operations/group.js +2 -2
- package/src/operations/groupBy.js +24 -22
- package/src/operations/has.js +7 -9
- package/src/operations/indent.js +2 -2
- package/src/operations/inners.js +19 -15
- package/src/operations/invokeFunctions.js +22 -10
- package/src/operations/isAsyncMutableTree.js +5 -12
- package/src/operations/isAsyncTree.js +5 -20
- package/src/operations/isMap.js +39 -0
- package/src/operations/isMaplike.js +34 -0
- package/src/operations/isReadOnlyMap.js +14 -0
- package/src/operations/isTraversable.js +3 -3
- package/src/operations/isTreelike.js +5 -30
- package/src/operations/json.js +4 -12
- package/src/operations/keys.js +17 -8
- package/src/operations/length.js +9 -8
- package/src/operations/map.js +27 -30
- package/src/operations/mapExtension.js +20 -16
- package/src/operations/mapReduce.js +22 -17
- package/src/operations/mask.js +31 -22
- package/src/operations/match.js +13 -9
- package/src/operations/merge.js +43 -35
- package/src/operations/paginate.js +26 -18
- package/src/operations/parent.js +7 -7
- package/src/operations/paths.js +8 -8
- package/src/operations/plain.js +6 -6
- package/src/operations/regExpKeys.js +21 -12
- package/src/operations/reverse.js +21 -15
- package/src/operations/root.js +6 -5
- package/src/operations/scope.js +31 -26
- package/src/operations/shuffle.js +23 -16
- package/src/operations/size.js +13 -0
- package/src/operations/sort.js +55 -40
- package/src/operations/sync.js +21 -0
- package/src/operations/take.js +23 -11
- package/src/operations/text.js +4 -4
- package/src/operations/toFunction.js +7 -7
- package/src/operations/traverse.js +4 -4
- package/src/operations/traverseOrThrow.js +13 -9
- package/src/operations/traversePath.js +2 -2
- package/src/operations/values.js +18 -9
- package/src/operations/withKeys.js +22 -16
- package/src/symbols.js +1 -0
- package/src/utilities/castArraylike.js +10 -2
- package/src/utilities/getMapArgument.js +38 -0
- package/src/utilities/getParent.js +2 -2
- package/src/utilities/isStringlike.js +7 -5
- package/src/utilities/setParent.js +7 -7
- package/src/utilities/toFunction.js +2 -2
- package/src/utilities/toPlainValue.js +22 -18
- package/test/SampleAsyncMap.js +34 -0
- package/test/browser/assert.js +20 -0
- package/test/browser/index.html +54 -21
- package/test/drivers/AsyncMap.test.js +119 -0
- package/test/drivers/{BrowserFileTree.test.js → BrowserFileMap.test.js} +42 -23
- package/test/drivers/{calendarTree.test.js → CalendarMap.test.js} +17 -19
- package/test/drivers/ConstantMap.test.js +15 -0
- package/test/drivers/DeepObjectMap.test.js +36 -0
- package/test/drivers/{ExplorableSiteTree.test.js → ExplorableSiteMap.test.js} +29 -14
- package/test/drivers/FileMap.test.js +185 -0
- package/test/drivers/FunctionMap.test.js +56 -0
- package/test/drivers/ObjectMap.test.js +166 -0
- package/test/drivers/SetMap.test.js +35 -0
- package/test/drivers/{SiteTree.test.js → SiteMap.test.js} +14 -10
- package/test/drivers/SyncMap.test.js +321 -0
- package/test/jsonKeys.test.js +2 -2
- package/test/operations/addNextPrevious.test.js +3 -2
- package/test/operations/assign.test.js +30 -35
- package/test/operations/cache.test.js +8 -6
- package/test/operations/cachedKeyFunctions.test.js +6 -5
- package/test/operations/clear.test.js +6 -27
- package/test/operations/deepEntries.test.js +32 -0
- package/test/operations/deepMerge.test.js +6 -5
- package/test/operations/deepReverse.test.js +2 -2
- package/test/operations/deepTake.test.js +2 -2
- package/test/operations/deepText.test.js +4 -4
- package/test/operations/deepValuesIterator.test.js +2 -2
- package/test/operations/delete.test.js +2 -2
- package/test/operations/extensionKeyFunctions.test.js +6 -5
- package/test/operations/filter.test.js +3 -3
- package/test/operations/from.test.js +23 -31
- package/test/operations/globKeys.test.js +9 -9
- package/test/operations/groupBy.test.js +6 -5
- package/test/operations/inners.test.js +4 -4
- package/test/operations/invokeFunctions.test.js +2 -2
- package/test/operations/isMap.test.js +15 -0
- package/test/operations/isMaplike.test.js +15 -0
- package/test/operations/json.test.js +2 -2
- package/test/operations/keys.test.js +16 -3
- package/test/operations/map.test.js +20 -18
- package/test/operations/mapExtension.test.js +6 -6
- package/test/operations/mapReduce.test.js +2 -2
- package/test/operations/mask.test.js +4 -3
- package/test/operations/match.test.js +2 -2
- package/test/operations/merge.test.js +15 -11
- package/test/operations/paginate.test.js +5 -5
- package/test/operations/parent.test.js +3 -3
- package/test/operations/paths.test.js +6 -6
- package/test/operations/plain.test.js +8 -8
- package/test/operations/regExpKeys.test.js +12 -11
- package/test/operations/reverse.test.js +4 -3
- package/test/operations/scope.test.js +6 -5
- package/test/operations/shuffle.test.js +3 -2
- package/test/operations/sort.test.js +7 -10
- package/test/operations/sync.test.js +43 -0
- package/test/operations/take.test.js +2 -2
- package/test/operations/toFunction.test.js +2 -2
- package/test/operations/traverse.test.js +4 -5
- package/test/operations/withKeys.test.js +2 -2
- package/test/utilities/setParent.test.js +6 -6
- package/test/utilities/toFunction.test.js +2 -2
- package/test/utilities/toPlainValue.test.js +51 -12
- package/src/drivers/DeepMapTree.js +0 -23
- package/src/drivers/DeepObjectTree.js +0 -18
- package/src/drivers/DeferredTree.js +0 -81
- package/src/drivers/FileTree.js +0 -276
- package/src/drivers/MapTree.js +0 -70
- package/src/drivers/ObjectTree.js +0 -158
- package/src/drivers/SetTree.js +0 -34
- package/src/drivers/constantTree.js +0 -19
- package/src/drivers/limitConcurrency.js +0 -63
- package/src/internal.js +0 -16
- package/src/utilities/getTreeArgument.js +0 -43
- package/test/drivers/DeepMapTree.test.js +0 -17
- package/test/drivers/DeepObjectTree.test.js +0 -35
- package/test/drivers/DeferredTree.test.js +0 -22
- package/test/drivers/FileTree.test.js +0 -192
- package/test/drivers/FunctionTree.test.js +0 -46
- package/test/drivers/MapTree.test.js +0 -59
- package/test/drivers/ObjectTree.test.js +0 -163
- package/test/drivers/SetTree.test.js +0 -44
- package/test/drivers/constantTree.test.js +0 -13
- package/test/drivers/limitConcurrency.test.js +0 -41
- package/test/operations/isAsyncMutableTree.test.js +0 -17
- package/test/operations/isAsyncTree.test.js +0 -26
- package/test/operations/isTreelike.test.js +0 -13
|
@@ -1,53 +1,48 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import ObjectMap from "../../src/drivers/ObjectMap.js";
|
|
4
|
+
import SyncMap from "../../src/drivers/SyncMap.js";
|
|
5
5
|
import assign from "../../src/operations/assign.js";
|
|
6
6
|
import plain from "../../src/operations/plain.js";
|
|
7
|
+
import { deepEntries } from "../../src/Tree.js";
|
|
8
|
+
import SampleAsyncMap from "../SampleAsyncMap.js";
|
|
7
9
|
|
|
8
10
|
describe("assign", () => {
|
|
9
|
-
test("assign
|
|
10
|
-
const target = new
|
|
11
|
-
a
|
|
12
|
-
b
|
|
13
|
-
more
|
|
14
|
-
|
|
15
|
-
},
|
|
16
|
-
});
|
|
11
|
+
test("assign can apply updates from an async tree to a sync tree", async () => {
|
|
12
|
+
const target = new SyncMap([
|
|
13
|
+
["a", 1],
|
|
14
|
+
["b", 2],
|
|
15
|
+
["more", new SyncMap([["d", 3]])],
|
|
16
|
+
]);
|
|
17
17
|
|
|
18
|
-
const source = new
|
|
19
|
-
a
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
e: 6, // Add
|
|
25
|
-
},
|
|
26
|
-
// Add new subtree
|
|
27
|
-
extra: {
|
|
28
|
-
f: 7,
|
|
29
|
-
},
|
|
30
|
-
});
|
|
18
|
+
const source = new SampleAsyncMap([
|
|
19
|
+
["a", 4], // Overwrite existing value
|
|
20
|
+
["c", 5], // Add
|
|
21
|
+
["more", [["e", 6]]], // Should leave existing `more` keys alone.
|
|
22
|
+
["extra", [["f", 7]]], // Add new subtree
|
|
23
|
+
]);
|
|
31
24
|
|
|
32
25
|
// Apply changes.
|
|
33
26
|
const result = await assign(target, source);
|
|
34
27
|
|
|
35
28
|
assert.equal(result, target);
|
|
36
|
-
assert.deepEqual(await
|
|
37
|
-
a
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
assert.deepEqual(await deepEntries(target), [
|
|
30
|
+
["a", 4],
|
|
31
|
+
["b", 2],
|
|
32
|
+
[
|
|
33
|
+
"more",
|
|
34
|
+
[
|
|
35
|
+
["d", 3],
|
|
36
|
+
["e", 6],
|
|
37
|
+
],
|
|
38
|
+
],
|
|
39
|
+
["c", 5],
|
|
40
|
+
["extra", [["f", 7]]],
|
|
41
|
+
]);
|
|
47
42
|
});
|
|
48
43
|
|
|
49
44
|
test("assign() can apply updates to an array", async () => {
|
|
50
|
-
const target = new
|
|
45
|
+
const target = new ObjectMap(["a", "b", "c"]);
|
|
51
46
|
await assign(target, ["d", "e"]);
|
|
52
47
|
assert.deepEqual(await plain(target), ["d", "e", "c"]);
|
|
53
48
|
});
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import
|
|
3
|
+
import DeepObjectMap from "../../src/drivers/DeepObjectMap.js";
|
|
4
|
+
import SyncMap from "../../src/drivers/SyncMap.js";
|
|
4
5
|
import cache from "../../src/operations/cache.js";
|
|
6
|
+
import keys from "../../src/operations/keys.js";
|
|
5
7
|
|
|
6
8
|
describe("cache", () => {
|
|
7
9
|
test("caches reads of values from one tree into another", async () => {
|
|
8
|
-
const objectCache = new
|
|
10
|
+
const objectCache = new SyncMap();
|
|
9
11
|
const fixture = await cache(
|
|
10
|
-
new
|
|
12
|
+
new DeepObjectMap({
|
|
11
13
|
a: 1,
|
|
12
14
|
b: 2,
|
|
13
15
|
c: 3,
|
|
@@ -18,8 +20,8 @@ describe("cache", () => {
|
|
|
18
20
|
objectCache
|
|
19
21
|
);
|
|
20
22
|
|
|
21
|
-
const
|
|
22
|
-
assert.deepEqual(
|
|
23
|
+
const treeKeys = await keys(fixture);
|
|
24
|
+
assert.deepEqual(treeKeys, ["a", "b", "c", "more/"]);
|
|
23
25
|
|
|
24
26
|
assert.equal(await objectCache.get("a"), undefined);
|
|
25
27
|
assert.equal(await fixture.get("a"), 1);
|
|
@@ -31,7 +33,7 @@ describe("cache", () => {
|
|
|
31
33
|
|
|
32
34
|
assert.equal(await objectCache.get("more"), undefined);
|
|
33
35
|
const more = await fixture.get("more");
|
|
34
|
-
assert.deepEqual([...(await
|
|
36
|
+
assert.deepEqual([...(await keys(more))], ["d"]);
|
|
35
37
|
assert.equal(await more.get("d"), 4);
|
|
36
38
|
const moreCache = await objectCache.get("more");
|
|
37
39
|
assert.equal(await moreCache.get("d"), 4);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import
|
|
3
|
+
import DeepObjectMap from "../../src/drivers/DeepObjectMap.js";
|
|
4
|
+
import ObjectMap from "../../src/drivers/ObjectMap.js";
|
|
4
5
|
import cachedKeyFunctions from "../../src/operations/cachedKeyFunctions.js";
|
|
5
6
|
import * as trailingSlash from "../../src/trailingSlash.js";
|
|
6
7
|
|
|
7
8
|
describe("cachedKeyFunctions", () => {
|
|
8
9
|
test("maps keys with caching", async () => {
|
|
9
|
-
const tree = new
|
|
10
|
+
const tree = new ObjectMap({
|
|
10
11
|
a: "letter a",
|
|
11
12
|
b: "letter b",
|
|
12
13
|
});
|
|
@@ -41,7 +42,7 @@ describe("cachedKeyFunctions", () => {
|
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
test("maps keys with caching and deep option", async () => {
|
|
44
|
-
const tree = new
|
|
45
|
+
const tree = new DeepObjectMap({
|
|
45
46
|
a: "letter a",
|
|
46
47
|
b: {
|
|
47
48
|
c: "letter c",
|
|
@@ -76,7 +77,7 @@ describe("cachedKeyFunctions", () => {
|
|
|
76
77
|
});
|
|
77
78
|
|
|
78
79
|
test("preserves trailing slashes if key function does so", async () => {
|
|
79
|
-
const tree = new
|
|
80
|
+
const tree = new ObjectMap({
|
|
80
81
|
a: "letter a",
|
|
81
82
|
});
|
|
82
83
|
const addUnderscore = async (sourceValue, sourceKey) => `_${sourceKey}`;
|
|
@@ -90,7 +91,7 @@ describe("cachedKeyFunctions", () => {
|
|
|
90
91
|
});
|
|
91
92
|
|
|
92
93
|
test("if key function toggles slash, defers to key function slash handling", async () => {
|
|
93
|
-
const tree = new
|
|
94
|
+
const tree = new ObjectMap({
|
|
94
95
|
a: "letter a",
|
|
95
96
|
});
|
|
96
97
|
const addUnderscoreAndSlash = async (sourceValue, sourceKey) =>
|
|
@@ -1,34 +1,13 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
2
|
import { describe, test } from "node:test";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
-
const tempDirectory = path.join(dirname, "fixtures/temp");
|
|
3
|
+
import ObjectMap from "../../src/drivers/ObjectMap.js";
|
|
4
|
+
import clear from "../../src/operations/clear.js";
|
|
5
|
+
import plain from "../../src/operations/plain.js";
|
|
11
6
|
|
|
12
7
|
describe("clear", () => {
|
|
13
8
|
test("unsets all public keys in an object tree", async () => {
|
|
14
|
-
const tree = new
|
|
15
|
-
await
|
|
16
|
-
assert.deepEqual(await
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test("unsets all public keys in a file tree", async () => {
|
|
20
|
-
// Create a temp directory with some files
|
|
21
|
-
await fs.mkdir(tempDirectory, { recursive: true });
|
|
22
|
-
await fs.writeFile(path.join(tempDirectory, "a"), "1");
|
|
23
|
-
await fs.writeFile(path.join(tempDirectory, "b"), "2");
|
|
24
|
-
|
|
25
|
-
const tree = new FileTree(tempDirectory);
|
|
26
|
-
await Tree.clear(tree);
|
|
27
|
-
|
|
28
|
-
const files = await fs.readdir(tempDirectory);
|
|
29
|
-
assert.deepEqual(files, []);
|
|
30
|
-
|
|
31
|
-
// Remove temp directory
|
|
32
|
-
await fs.rm(tempDirectory, { recursive: true });
|
|
9
|
+
const tree = new ObjectMap({ a: 1, b: 2, c: 3 });
|
|
10
|
+
await clear(tree);
|
|
11
|
+
assert.deepEqual(await plain(tree), {});
|
|
33
12
|
});
|
|
34
13
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { describe, test } from "node:test";
|
|
3
|
+
import deepEntries from "../../src/operations/deepEntries.js";
|
|
4
|
+
import SampleAsyncMap from "../SampleAsyncMap.js";
|
|
5
|
+
|
|
6
|
+
describe("deepEntries", () => {
|
|
7
|
+
test("converts an async tree to an array of nested entries arrays", async () => {
|
|
8
|
+
const fixture = new SampleAsyncMap([
|
|
9
|
+
["a", 1],
|
|
10
|
+
["b", 2],
|
|
11
|
+
[
|
|
12
|
+
"more",
|
|
13
|
+
[
|
|
14
|
+
["c", 3],
|
|
15
|
+
["d", 4],
|
|
16
|
+
],
|
|
17
|
+
],
|
|
18
|
+
]);
|
|
19
|
+
const result = await deepEntries(fixture);
|
|
20
|
+
assert.deepStrictEqual(result, [
|
|
21
|
+
["a", 1],
|
|
22
|
+
["b", 2],
|
|
23
|
+
[
|
|
24
|
+
"more",
|
|
25
|
+
[
|
|
26
|
+
["c", 3],
|
|
27
|
+
["d", 4],
|
|
28
|
+
],
|
|
29
|
+
],
|
|
30
|
+
]);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import
|
|
3
|
+
import DeepObjectMap from "../../src/drivers/DeepObjectMap.js";
|
|
4
4
|
import deepMerge from "../../src/operations/deepMerge.js";
|
|
5
|
+
import plain from "../../src/operations/plain.js";
|
|
5
6
|
|
|
6
7
|
describe("mergeDeep", () => {
|
|
7
8
|
test("can merge deep", async () => {
|
|
8
|
-
const fixture = deepMerge(
|
|
9
|
-
new
|
|
9
|
+
const fixture = await deepMerge(
|
|
10
|
+
new DeepObjectMap({
|
|
10
11
|
a: {
|
|
11
12
|
b: 0, // Will be obscured by `b` below
|
|
12
13
|
c: {
|
|
@@ -14,7 +15,7 @@ describe("mergeDeep", () => {
|
|
|
14
15
|
},
|
|
15
16
|
},
|
|
16
17
|
}),
|
|
17
|
-
new
|
|
18
|
+
new DeepObjectMap({
|
|
18
19
|
a: {
|
|
19
20
|
b: 1,
|
|
20
21
|
c: {
|
|
@@ -24,7 +25,7 @@ describe("mergeDeep", () => {
|
|
|
24
25
|
},
|
|
25
26
|
})
|
|
26
27
|
);
|
|
27
|
-
assert.deepEqual(await
|
|
28
|
+
assert.deepEqual(await plain(fixture), {
|
|
28
29
|
a: {
|
|
29
30
|
b: 1,
|
|
30
31
|
c: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import { Tree } from "../../src/internal.js";
|
|
4
3
|
import deepReverse from "../../src/operations/deepReverse.js";
|
|
4
|
+
import plain from "../../src/operations/plain.js";
|
|
5
5
|
|
|
6
6
|
describe("deepReverse", () => {
|
|
7
7
|
test("reverses keys at all levels of a tree", async () => {
|
|
@@ -13,7 +13,7 @@ describe("deepReverse", () => {
|
|
|
13
13
|
},
|
|
14
14
|
};
|
|
15
15
|
const reversed = await deepReverse(tree);
|
|
16
|
-
assert.deepEqual(await
|
|
16
|
+
assert.deepEqual(await plain(reversed), {
|
|
17
17
|
b: {
|
|
18
18
|
d: 3,
|
|
19
19
|
c: 2,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import { Tree } from "../../src/internal.js";
|
|
4
3
|
import deepTake from "../../src/operations/deepTake.js";
|
|
4
|
+
import plain from "../../src/operations/plain.js";
|
|
5
5
|
|
|
6
6
|
describe("deepTake", () => {
|
|
7
7
|
test("traverses deeply and returns a limited number of items", async () => {
|
|
@@ -17,6 +17,6 @@ describe("deepTake", () => {
|
|
|
17
17
|
g: 5,
|
|
18
18
|
};
|
|
19
19
|
const result = await deepTake(tree, 4);
|
|
20
|
-
assert.deepEqual(await
|
|
20
|
+
assert.deepEqual(await plain(result), [1, 2, 3, 4]);
|
|
21
21
|
});
|
|
22
22
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import
|
|
4
|
-
import { Tree } from "../../src/internal.js";
|
|
3
|
+
import FunctionMap from "../../src/drivers/FunctionMap.js";
|
|
5
4
|
import deepText from "../../src/operations/deepText.js";
|
|
5
|
+
import from from "../../src/operations/from.js";
|
|
6
6
|
|
|
7
7
|
describe("deepText", () => {
|
|
8
8
|
test("concatenates deep tree values", async () => {
|
|
9
|
-
const tree =
|
|
9
|
+
const tree = from({
|
|
10
10
|
a: "A",
|
|
11
11
|
b: "B",
|
|
12
12
|
c: "C",
|
|
@@ -21,7 +21,7 @@ describe("deepText", () => {
|
|
|
21
21
|
|
|
22
22
|
test("concatenates deep tree-like values", async () => {
|
|
23
23
|
const letters = ["a", "b", "c"];
|
|
24
|
-
const specimens = new
|
|
24
|
+
const specimens = new FunctionMap(
|
|
25
25
|
(letter) => ({
|
|
26
26
|
lowercase: letter,
|
|
27
27
|
uppercase: letter.toUpperCase(),
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import
|
|
3
|
+
import ObjectMap from "../../src/drivers/ObjectMap.js";
|
|
4
4
|
import deepValuesIterator from "../../src/operations/deepValuesIterator.js";
|
|
5
5
|
|
|
6
6
|
describe("deepValuesIterator", () => {
|
|
7
7
|
test("returns an iterator of a tree's deep values", async () => {
|
|
8
|
-
const tree = new
|
|
8
|
+
const tree = new ObjectMap({
|
|
9
9
|
a: 1,
|
|
10
10
|
b: 2,
|
|
11
11
|
more: {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import
|
|
3
|
+
import ObjectMap from "../../src/drivers/ObjectMap.js";
|
|
4
4
|
import { default as del } from "../../src/operations/delete.js";
|
|
5
5
|
import plain from "../../src/operations/plain.js";
|
|
6
6
|
|
|
7
7
|
describe("delete", () => {
|
|
8
8
|
test("removes a value", async () => {
|
|
9
|
-
const fixture = new
|
|
9
|
+
const fixture = new ObjectMap({
|
|
10
10
|
"Alice.md": "Hello, **Alice**.",
|
|
11
11
|
"Bob.md": "Hello, **Bob**.",
|
|
12
12
|
"Carol.md": "Hello, **Carol**.",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import
|
|
3
|
+
import ObjectMap from "../../src/drivers/ObjectMap.js";
|
|
4
4
|
import extensionKeyFunctions from "../../src/operations/extensionKeyFunctions.js";
|
|
5
5
|
import map from "../../src/operations/map.js";
|
|
6
|
+
import plain from "../../src/operations/plain.js";
|
|
6
7
|
|
|
7
8
|
describe("keyMapsForExtensions", () => {
|
|
8
9
|
test("returns key functions that pass a matching key through", async () => {
|
|
@@ -34,7 +35,7 @@ describe("keyMapsForExtensions", () => {
|
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
test("works with map to handle keys that end in a given resultExtension", async () => {
|
|
37
|
-
const files = new
|
|
38
|
+
const files = new ObjectMap({
|
|
38
39
|
"file1.txt": "will be mapped",
|
|
39
40
|
file2: "won't be mapped",
|
|
40
41
|
"file3.foo": "won't be mapped",
|
|
@@ -45,13 +46,13 @@ describe("keyMapsForExtensions", () => {
|
|
|
45
46
|
key,
|
|
46
47
|
value: (sourceValue, sourceKey, tree) => sourceValue.toUpperCase(),
|
|
47
48
|
});
|
|
48
|
-
assert.deepEqual(await
|
|
49
|
+
assert.deepEqual(await plain(fixture), {
|
|
49
50
|
"file1.txt": "WILL BE MAPPED",
|
|
50
51
|
});
|
|
51
52
|
});
|
|
52
53
|
|
|
53
54
|
test("works with map to change a key's resultExtension", async () => {
|
|
54
|
-
const files = new
|
|
55
|
+
const files = new ObjectMap({
|
|
55
56
|
"file1.txt": "will be mapped",
|
|
56
57
|
file2: "won't be mapped",
|
|
57
58
|
"file3.foo": "won't be mapped",
|
|
@@ -62,7 +63,7 @@ describe("keyMapsForExtensions", () => {
|
|
|
62
63
|
key,
|
|
63
64
|
value: (sourceValue, sourceKey, tree) => sourceValue.toUpperCase(),
|
|
64
65
|
});
|
|
65
|
-
assert.deepEqual(await
|
|
66
|
+
assert.deepEqual(await plain(fixture), {
|
|
66
67
|
"file1.upper": "WILL BE MAPPED",
|
|
67
68
|
});
|
|
68
69
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import { Tree } from "../../src/internal.js";
|
|
4
3
|
import filter from "../../src/operations/filter.js";
|
|
4
|
+
import plain from "../../src/operations/plain.js";
|
|
5
5
|
|
|
6
6
|
describe("filter", () => {
|
|
7
7
|
test("returns values that pass a filter function", async () => {
|
|
@@ -14,7 +14,7 @@ describe("filter", () => {
|
|
|
14
14
|
},
|
|
15
15
|
(value) => value % 2 === 1 // odd
|
|
16
16
|
);
|
|
17
|
-
assert.deepEqual(await
|
|
17
|
+
assert.deepEqual(await plain(result), {
|
|
18
18
|
a: 1,
|
|
19
19
|
c: 3,
|
|
20
20
|
});
|
|
@@ -35,7 +35,7 @@ describe("filter", () => {
|
|
|
35
35
|
test: (value) => value % 2 === 1, // odd
|
|
36
36
|
}
|
|
37
37
|
);
|
|
38
|
-
assert.deepEqual(await
|
|
38
|
+
assert.deepEqual(await plain(result), {
|
|
39
39
|
a: 1,
|
|
40
40
|
c: {
|
|
41
41
|
d: 3,
|
|
@@ -1,42 +1,32 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import DeepObjectMap from "../../src/drivers/DeepObjectMap.js";
|
|
4
|
+
import SetMap from "../../src/drivers/SetMap.js";
|
|
5
5
|
import from from "../../src/operations/from.js";
|
|
6
|
-
import
|
|
6
|
+
import values from "../../src/operations/values.js";
|
|
7
7
|
import * as symbols from "../../src/symbols.js";
|
|
8
8
|
|
|
9
9
|
describe("from", () => {
|
|
10
|
-
test("returns
|
|
11
|
-
const tree1 = new
|
|
12
|
-
a
|
|
13
|
-
|
|
10
|
+
test("returns a Map as is", async () => {
|
|
11
|
+
const tree1 = new Map([
|
|
12
|
+
["a", 1],
|
|
13
|
+
["b", 2],
|
|
14
|
+
]);
|
|
14
15
|
const tree2 = from(tree1);
|
|
15
16
|
assert.equal(tree2, tree1);
|
|
16
17
|
});
|
|
17
18
|
|
|
18
|
-
test("
|
|
19
|
-
const obj = new String();
|
|
20
|
-
/** @type {any} */ (obj).unpack = () => ({
|
|
21
|
-
a: "Hello, a.",
|
|
22
|
-
});
|
|
23
|
-
const tree = from(obj);
|
|
24
|
-
assert.deepEqual(await plain(tree), {
|
|
25
|
-
a: "Hello, a.",
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("returns a deep object tree if deep option is true", async () => {
|
|
19
|
+
test("returns a deep object map if deep option is true", async () => {
|
|
30
20
|
const obj = {
|
|
31
21
|
sub: {
|
|
32
22
|
a: 1,
|
|
33
23
|
},
|
|
34
24
|
};
|
|
35
25
|
const tree = from(obj, { deep: true });
|
|
36
|
-
assert(tree instanceof
|
|
26
|
+
assert(tree instanceof DeepObjectMap);
|
|
37
27
|
});
|
|
38
28
|
|
|
39
|
-
test("returns a deep object
|
|
29
|
+
test("returns a deep object map if object has [deep] symbol set", async () => {
|
|
40
30
|
const obj = {
|
|
41
31
|
sub: {
|
|
42
32
|
a: 1,
|
|
@@ -44,18 +34,20 @@ describe("from", () => {
|
|
|
44
34
|
};
|
|
45
35
|
Object.defineProperty(obj, symbols.deep, { value: true });
|
|
46
36
|
const tree = from(obj);
|
|
47
|
-
assert(tree instanceof
|
|
37
|
+
assert(tree instanceof DeepObjectMap);
|
|
48
38
|
});
|
|
49
39
|
|
|
50
|
-
test("
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
40
|
+
test("returns a SetMap for Set objects", async () => {
|
|
41
|
+
const set = new Set(["a", "b", "c"]);
|
|
42
|
+
const map = from(set);
|
|
43
|
+
assert(map instanceof SetMap);
|
|
44
|
+
assert.deepEqual(await values(map), ["a", "b", "c"]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test.only("returns an array for an Iterator", async () => {
|
|
48
|
+
const set = new Set(["a", "b", "c"]);
|
|
49
|
+
const map = from(set.values());
|
|
50
|
+
assert.deepEqual(await values(map), ["a", "b", "c"]);
|
|
59
51
|
});
|
|
60
52
|
|
|
61
53
|
test("autoboxes primitive values", async () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import { Tree } from "../../src/internal.js";
|
|
4
3
|
import globKeys from "../../src/operations/globKeys.js";
|
|
4
|
+
import traverse from "../../src/operations/traverse.js";
|
|
5
5
|
|
|
6
6
|
describe("globKeys", () => {
|
|
7
7
|
test("matches globs", async () => {
|
|
@@ -26,8 +26,8 @@ describe("globKeys", () => {
|
|
|
26
26
|
"*": "default",
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
|
-
assert.equal(await
|
|
30
|
-
assert.equal(await
|
|
29
|
+
assert.equal(await traverse(globTree, "sub/", "file"), "default");
|
|
30
|
+
assert.equal(await traverse(globTree, "sub/", "foo"), "bar");
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
test("supports deep matches with globstar", async () => {
|
|
@@ -43,11 +43,11 @@ describe("globKeys", () => {
|
|
|
43
43
|
"*.html": true,
|
|
44
44
|
},
|
|
45
45
|
});
|
|
46
|
-
assert.equal(await
|
|
47
|
-
assert.equal(await
|
|
48
|
-
assert.equal(await
|
|
49
|
-
assert.equal(await
|
|
50
|
-
assert.equal(await
|
|
51
|
-
assert.equal(await
|
|
46
|
+
assert.equal(await traverse(globTree, "a/", "b/", "foo.txt"), true);
|
|
47
|
+
assert.equal(await traverse(globTree, "c/", "foo"), false);
|
|
48
|
+
assert.equal(await traverse(globTree, "sub/", "file.md"), true);
|
|
49
|
+
assert.equal(await traverse(globTree, "sub/", "file.txt"), true);
|
|
50
|
+
assert.equal(await traverse(globTree, "sub/", "file.html"), true);
|
|
51
|
+
assert.equal(await traverse(globTree, "sub/", "file"), false);
|
|
52
52
|
});
|
|
53
53
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import
|
|
3
|
+
import from from "../../src/operations/from.js";
|
|
4
4
|
import groupBy from "../../src/operations/groupBy.js";
|
|
5
|
+
import plain from "../../src/operations/plain.js";
|
|
5
6
|
|
|
6
7
|
describe("groupBy transform", () => {
|
|
7
8
|
test("groups an array using a group key function", async () => {
|
|
@@ -11,9 +12,9 @@ describe("groupBy transform", () => {
|
|
|
11
12
|
{ name: "Alegreya", tags: ["Serif"] },
|
|
12
13
|
{ name: "Work Sans", tags: ["Grotesque", "Sans Serif"] },
|
|
13
14
|
];
|
|
14
|
-
const tree =
|
|
15
|
+
const tree = from(fonts);
|
|
15
16
|
const grouped = await groupBy(tree, (value, key, tree) => value.tags);
|
|
16
|
-
assert.deepEqual(await
|
|
17
|
+
assert.deepEqual(await plain(grouped), {
|
|
17
18
|
Geometric: [{ name: "Albert Sans", tags: ["Geometric", "Sans Serif"] }],
|
|
18
19
|
Grotesque: [{ name: "Work Sans", tags: ["Grotesque", "Sans Serif"] }],
|
|
19
20
|
"Sans Serif": [
|
|
@@ -32,9 +33,9 @@ describe("groupBy transform", () => {
|
|
|
32
33
|
Alegreya: { tags: ["Serif"] },
|
|
33
34
|
"Work Sans": { tags: ["Grotesque", "Sans Serif"] },
|
|
34
35
|
};
|
|
35
|
-
const tree =
|
|
36
|
+
const tree = from(fonts);
|
|
36
37
|
const grouped = await groupBy(tree, (value, key, tree) => value.tags);
|
|
37
|
-
assert.deepEqual(await
|
|
38
|
+
assert.deepEqual(await plain(grouped), {
|
|
38
39
|
Geometric: {
|
|
39
40
|
"Albert Sans": { tags: ["Geometric", "Sans Serif"] },
|
|
40
41
|
},
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import
|
|
3
|
+
import DeepObjectMap from "../../src/drivers/DeepObjectMap.js";
|
|
4
4
|
import inners from "../../src/operations/inners.js";
|
|
5
|
+
import plain from "../../src/operations/plain.js";
|
|
5
6
|
|
|
6
7
|
describe("inners", () => {
|
|
7
8
|
test("returns the interior nodes of a tree", async () => {
|
|
8
|
-
const obj = new
|
|
9
|
+
const obj = new DeepObjectMap({
|
|
9
10
|
a: 1,
|
|
10
11
|
b: {
|
|
11
12
|
c: 2,
|
|
@@ -19,8 +20,7 @@ describe("inners", () => {
|
|
|
19
20
|
},
|
|
20
21
|
});
|
|
21
22
|
const result = await inners(obj);
|
|
22
|
-
|
|
23
|
-
assert.deepEqual(plain, {
|
|
23
|
+
assert.deepEqual(await plain(result), {
|
|
24
24
|
b: {
|
|
25
25
|
d: {},
|
|
26
26
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import { Tree } from "../../src/internal.js";
|
|
4
3
|
import invokeFunctions from "../../src/operations/invokeFunctions.js";
|
|
4
|
+
import plain from "../../src/operations/plain.js";
|
|
5
5
|
|
|
6
6
|
describe("invokeFunctions", () => {
|
|
7
7
|
test("invokes function values, leaves other values as is", async () => {
|
|
@@ -9,7 +9,7 @@ describe("invokeFunctions", () => {
|
|
|
9
9
|
a: 1,
|
|
10
10
|
b: () => 2,
|
|
11
11
|
});
|
|
12
|
-
assert.deepEqual(await
|
|
12
|
+
assert.deepEqual(await plain(fixture), {
|
|
13
13
|
a: 1,
|
|
14
14
|
b: 2,
|
|
15
15
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { describe, test } from "node:test";
|
|
3
|
+
import AsyncMap from "../../src/drivers/AsyncMap.js";
|
|
4
|
+
import isMap from "../../src/operations/isMap.js";
|
|
5
|
+
|
|
6
|
+
describe("isMap", () => {
|
|
7
|
+
test("returns true if the object is a Map or AsyncMap", () => {
|
|
8
|
+
assert(!isMap(null));
|
|
9
|
+
assert(!isMap(1));
|
|
10
|
+
assert(!isMap({}));
|
|
11
|
+
assert(!isMap([]));
|
|
12
|
+
assert(isMap(new Map()));
|
|
13
|
+
assert(isMap(new AsyncMap()));
|
|
14
|
+
});
|
|
15
|
+
});
|