@weborigami/origami 0.7.0-beta.1 → 0.7.0-beta.2
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/origami",
|
|
3
|
-
"version": "0.7.0-beta.
|
|
3
|
+
"version": "0.7.0-beta.2",
|
|
4
4
|
"description": "Web Origami language, CLI, framework, and server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@hpcc-js/wasm-graphviz": "1.21.7",
|
|
21
|
-
"@weborigami/async-tree": "0.7.0-beta.
|
|
21
|
+
"@weborigami/async-tree": "0.7.0-beta.2",
|
|
22
22
|
"@weborigami/json-feed-to-rss": "1.0.1",
|
|
23
|
-
"@weborigami/language": "0.7.0-beta.
|
|
23
|
+
"@weborigami/language": "0.7.0-beta.2",
|
|
24
24
|
"css-tree": "3.2.1",
|
|
25
25
|
"highlight.js": "11.11.1",
|
|
26
26
|
"jsdom": "29.1.1",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isPlainObject, isUnpackable, toString } from "@weborigami/async-tree";
|
|
2
|
+
import { toYaml } from "./serialize.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* In Origami, a text document object is any object with a `_body` property.
|
|
@@ -29,6 +30,7 @@ export default async function documentObject(input, data) {
|
|
|
29
30
|
|
|
30
31
|
const result = {};
|
|
31
32
|
Object.assign(result, inputData, data);
|
|
33
|
+
|
|
32
34
|
Object.defineProperty(result, "_body", {
|
|
33
35
|
configurable: true,
|
|
34
36
|
enumerable: true,
|
|
@@ -36,5 +38,29 @@ export default async function documentObject(input, data) {
|
|
|
36
38
|
writable: true,
|
|
37
39
|
});
|
|
38
40
|
|
|
41
|
+
Object.defineProperty(result, "pack", {
|
|
42
|
+
configurable: true,
|
|
43
|
+
enumerable: false,
|
|
44
|
+
value: pack.bind(null, result),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
Object.defineProperty(result, "toString", {
|
|
48
|
+
configurable: true,
|
|
49
|
+
enumerable: false,
|
|
50
|
+
value: pack.bind(null, result),
|
|
51
|
+
});
|
|
52
|
+
|
|
39
53
|
return result;
|
|
40
54
|
}
|
|
55
|
+
|
|
56
|
+
// If the document is just a _body, return its text. Otherwise, return the body
|
|
57
|
+
// as a string with the other properties as YAML front matter.
|
|
58
|
+
async function pack(document) {
|
|
59
|
+
if (Object.keys(document).length === 1 && "_body" in document) {
|
|
60
|
+
return document._body;
|
|
61
|
+
}
|
|
62
|
+
const frontData = { ...document };
|
|
63
|
+
delete frontData._body;
|
|
64
|
+
const frontMatter = await toYaml(frontData);
|
|
65
|
+
return `---\n${frontMatter}---\n\n${document._body}`;
|
|
66
|
+
}
|
package/src/dev/help.yaml
CHANGED
|
@@ -247,6 +247,12 @@ Tree:
|
|
|
247
247
|
filter:
|
|
248
248
|
args: (tree, options)
|
|
249
249
|
description: Filter a tree by a condition
|
|
250
|
+
find:
|
|
251
|
+
args: (map, test)
|
|
252
|
+
description: The value of the first entry satisfying the test
|
|
253
|
+
findKey:
|
|
254
|
+
args: (map, test)
|
|
255
|
+
description: The key of the first entry satisfying the test
|
|
250
256
|
first:
|
|
251
257
|
args: (map)
|
|
252
258
|
description: The first value in the map
|
package/src/origami/htmlDom.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { args } from "@weborigami/async-tree";
|
|
1
|
+
import { args, isUnpackable } from "@weborigami/async-tree";
|
|
2
2
|
import loadJsDom from "../common/loadJsDom.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -7,6 +7,9 @@ import loadJsDom from "../common/loadJsDom.js";
|
|
|
7
7
|
* @param {import("@weborigami/async-tree").Stringlike} html
|
|
8
8
|
*/
|
|
9
9
|
export default async function htmlDom(html) {
|
|
10
|
+
if (isUnpackable(html)) {
|
|
11
|
+
html = await html.unpack();
|
|
12
|
+
}
|
|
10
13
|
html = args.stringlike(html, "Origami.htmlDom");
|
|
11
14
|
const { JSDOM } = await loadJsDom();
|
|
12
15
|
let dom = JSDOM.fragment(html);
|
|
@@ -104,6 +104,8 @@ export default async function constructResponse(request, resource) {
|
|
|
104
104
|
const hash = createHash("sha1");
|
|
105
105
|
if (typeof body === "string" || body instanceof String) {
|
|
106
106
|
hash.update(String(body), "utf8");
|
|
107
|
+
} else if (body instanceof ArrayBuffer) {
|
|
108
|
+
hash.update(new Uint8Array(body));
|
|
107
109
|
} else {
|
|
108
110
|
hash.update(body);
|
|
109
111
|
}
|