@weborigami/async-tree 0.6.15 → 0.6.16

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/async-tree",
3
- "version": "0.6.15",
3
+ "version": "0.6.16",
4
4
  "description": "Asynchronous tree drivers based on standard JavaScript classes",
5
5
  "type": "module",
6
6
  "main": "./main.js",
@@ -13,7 +13,7 @@ import isMaplike from "./isMaplike.js";
13
13
  * specified depth. A depth of 0 will yield values only at the tree's top level.
14
14
  *
15
15
  * @param {import("../../index.ts").Maplike} maplike
16
- * @param {{ depth?: number, expand?: boolean }} [options]
16
+ * @param {{ depth?: number, expand?: boolean, unpack?: boolean }} [options]
17
17
  * @returns {AsyncGenerator<[any, any], void, undefined>}
18
18
  */
19
19
  export default async function* deepEntriesIterator(maplike, options = {}) {
@@ -22,12 +22,13 @@ export default async function* deepEntriesIterator(maplike, options = {}) {
22
22
  });
23
23
 
24
24
  const depth = options.depth ?? Infinity;
25
- const expand = options.expand ?? false;
25
+ const expand = options.expand ?? true;
26
+ const unpack = options.unpack ?? false;
26
27
 
27
28
  for await (let [key, value] of tree.entries()) {
28
29
  value = await value;
29
30
 
30
- if (expand && isUnpackable(value)) {
31
+ if (unpack && isUnpackable(value)) {
31
32
  value = await value.unpack();
32
33
  }
33
34
 
@@ -37,7 +38,7 @@ export default async function* deepEntriesIterator(maplike, options = {}) {
37
38
  (isMap(value) ||
38
39
  (expand && typeof value !== "function" && isMaplike(value)));
39
40
  if (recurse) {
40
- yield* deepEntriesIterator(value, { depth: depth - 1, expand });
41
+ yield* deepEntriesIterator(value, { depth: depth - 1, expand, unpack });
41
42
  } else {
42
43
  yield [key, value];
43
44
  }
@@ -86,7 +86,9 @@ export default async function traverseOrThrow(maplike, ...keys) {
86
86
  const message =
87
87
  value === undefined
88
88
  ? "A path tried to unpack a value that doesn't exist."
89
- : "A path tried to unpack data that's already unpacked.";
89
+ : isPacked(value)
90
+ ? "A path tried to unpack data but there's no unpack function."
91
+ : "A path tried to unpack data that's already unpacked.";
90
92
  throw new TraverseError(message, {
91
93
  head: maplike,
92
94
  lastValue,
@@ -67,7 +67,7 @@ describe("deepEntriesIterator", () => {
67
67
  packed,
68
68
  };
69
69
  const entries = [];
70
- for await (const entry of deepEntriesIterator(tree, { expand: true })) {
70
+ for await (const entry of deepEntriesIterator(tree, { unpack: true })) {
71
71
  entries.push(entry);
72
72
  }
73
73
  assert.deepEqual(entries, [
@@ -6,7 +6,7 @@ import plain from "../../src/operations/plain.js";
6
6
 
7
7
  describe("flat", () => {
8
8
  test("flattens an array one level by default", async () => {
9
- const result = await flat([1, 2, [3], [[4, [5]]]], 1);
9
+ const result = await flat([1, 2, [3], [[4, [5]]]]);
10
10
  assert.deepEqual(await plain(result), [1, 2, 3, [4, [5]]]);
11
11
  });
12
12