@weborigami/origami 0.0.47 → 0.0.48

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.
@@ -76,6 +76,7 @@ export { default as sort } from "../src/builtins/@sort.js";
76
76
  export { default as sortBy } from "../src/builtins/@sortBy.js";
77
77
  export { default as static } from "../src/builtins/@static.js";
78
78
  export { default as stdin } from "../src/builtins/@stdin.js";
79
+ export { default as string } from "../src/builtins/@string.js";
79
80
  export { default as svg } from "../src/builtins/@svg.js";
80
81
  export { default as table } from "../src/builtins/@table.js";
81
82
  export { default as take } from "../src/builtins/@take.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/origami",
3
- "version": "0.0.47",
3
+ "version": "0.0.48",
4
4
  "description": "Web Origami language, CLI, framework, and server",
5
5
  "type": "module",
6
6
  "repository": {
@@ -17,9 +17,9 @@
17
17
  "typescript": "5.4.2"
18
18
  },
19
19
  "dependencies": {
20
- "@weborigami/async-tree": "0.0.47",
21
- "@weborigami/language": "0.0.47",
22
- "@weborigami/types": "0.0.47",
20
+ "@weborigami/async-tree": "0.0.48",
21
+ "@weborigami/language": "0.0.48",
22
+ "@weborigami/types": "0.0.48",
23
23
  "exif-parser": "0.1.12",
24
24
  "graphviz-wasm": "3.0.1",
25
25
  "highlight.js": "11.9.0",
@@ -1,4 +1,4 @@
1
- import { merge } from "@weborigami/async-tree";
1
+ import { isPlainObject, isUnpackable, merge } from "@weborigami/async-tree";
2
2
  import { Scope } from "@weborigami/language";
3
3
  import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
4
4
 
@@ -24,10 +24,22 @@ export default async function treeMerge(...trees) {
24
24
  return filtered[0];
25
25
  }
26
26
 
27
+ // Unpack any packed objects.
28
+ const unpacked = await Promise.all(
29
+ filtered.map((obj) =>
30
+ isUnpackable(obj) ? /** @type {any} */ (obj).unpack() : obj
31
+ )
32
+ );
33
+
34
+ // If all trees are plain objects, return a plain object.
35
+ if (unpacked.every((tree) => isPlainObject(tree))) {
36
+ return Object.assign({}, ...unpacked);
37
+ }
38
+
27
39
  // If a tree can take a scope, give it one that includes the other trees and
28
40
  // the current scope.
29
- const scopedTrees = filtered.map((tree) => {
30
- const otherTrees = filtered.filter((g) => g !== tree);
41
+ const scopedTrees = unpacked.map((tree) => {
42
+ const otherTrees = unpacked.filter((g) => g !== tree);
31
43
  const scope = new Scope(...otherTrees, this);
32
44
  // Each tree will be included first in its own scope.
33
45
  return Scope.treeWithScope(tree, scope);
@@ -0,0 +1,14 @@
1
+ import { toString } from "../common/utilities.js";
2
+ import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
3
+
4
+ /**
5
+ * Convert an object to a string.
6
+ *
7
+ * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
8
+ * @this {AsyncTree|null}
9
+ * @param {any} object
10
+ */
11
+ export default function stringBuiltin(object) {
12
+ assertScopeIsDefined(this, "string");
13
+ return toString(object);
14
+ }
@@ -1,11 +1,12 @@
1
1
  import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
2
2
 
3
3
  /**
4
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
4
+ * Unpack a packed format like a Buffer or ArrayBuffer to a usable form like
5
+ * text or a plain JavaScript object.
5
6
  *
7
+ * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
6
8
  * @this {AsyncTree|null}
7
9
  * @param {any} obj
8
- * @returns
9
10
  */
10
11
  export default function unpack(obj) {
11
12
  assertScopeIsDefined(this, "unpack");
@@ -54,7 +54,7 @@ export default {
54
54
  async unpack(packed, options = {}) {
55
55
  const parent = options.parent ?? null;
56
56
  const text = utilities.toString(packed);
57
- if (!text) {
57
+ if (text === null) {
58
58
  throw new Error("Tried to treat something as text but it wasn't text.");
59
59
  }
60
60