unfazed 0.6.1 → 0.8.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.
@@ -0,0 +1,38 @@
1
+ import { REFERENCE } from "./reference.generated.js";
2
+ export { REFERENCE };
3
+ /**
4
+ * The SDK's reference, for a script (or a model) that needs a signature:
5
+ * every method of {@link Unfazed} with its parameters, result and an
6
+ * example, in one page (REFERENCE.md). It describes THIS version, the one
7
+ * the script imported (`VERSION`): exactly what `help()` should answer.
8
+ *
9
+ * ```ts
10
+ * import { help } from "unfazed";
11
+ * export default () => help("writeFiles"); // run_script returns the entry
12
+ * ```
13
+ *
14
+ * `help()` is the whole page; `help(topic)` the entries whose heading names
15
+ * it (a method like `"restoreVersion"`, or a section like `"Events"`), or the
16
+ * list of methods when nothing matches.
17
+ */
18
+ export function help(topic) {
19
+ if (!topic)
20
+ return REFERENCE;
21
+ const wanted = topic.trim().replace(/\(\)$/, "").toLowerCase();
22
+ const firstLine = (block) => block.split("\n", 1)[0].toLowerCase();
23
+ // A section ("Events", "Files"): the whole of it.
24
+ const section = REFERENCE.split(/\n(?=## )/).find((block) => firstLine(block) === `## ${wanted}`);
25
+ if (section)
26
+ return section.trim() + "\n";
27
+ // A method: every entry whose heading names it.
28
+ const method = new RegExp(`\`${escape(wanted)}\\(|[ /]${escape(wanted)}\\(`);
29
+ const matches = REFERENCE.split(/\n(?=#{2,3} )/).filter((block) => block.startsWith("### ") && method.test(firstLine(block)));
30
+ if (matches.length > 0)
31
+ return matches.map((block) => block.trim()).join("\n\n") + "\n";
32
+ const names = [...REFERENCE.matchAll(/^### `(\w+)\(/gm)].map((m) => m[1]);
33
+ return `No entry for "${topic}". Methods: ${names.join(", ")}. help() returns the whole reference.\n`;
34
+ }
35
+ function escape(text) {
36
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
37
+ }
38
+ //# sourceMappingURL=reference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference.js","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I,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACxF,MAAM,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,OAAO,iBAAiB,KAAK,eAAe,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,yCAAyC,CAAC;AACxG,CAAC;AAED,SAAS,MAAM,CAAC,IAAY;IAC1B,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { REFERENCE } from \"./reference.generated.js\";\n\nexport { REFERENCE };\n\n/**\n * The SDK's reference, for a script (or a model) that needs a signature:\n * every method of {@link Unfazed} with its parameters, result and an\n * example, in one page (REFERENCE.md). It describes THIS version, the one\n * the script imported (`VERSION`): exactly what `help()` should answer.\n *\n * ```ts\n * import { help } from \"unfazed\";\n * export default () => help(\"writeFiles\"); // run_script returns the entry\n * ```\n *\n * `help()` is the whole page; `help(topic)` the entries whose heading names\n * it (a method like `\"restoreVersion\"`, or a section like `\"Events\"`), or the\n * list of methods when nothing matches.\n */\nexport function help(topic?: string): string {\n if (!topic) return REFERENCE;\n const wanted = topic.trim().replace(/\\(\\)$/, \"\").toLowerCase();\n const firstLine = (block: string) => block.split(\"\\n\", 1)[0]!.toLowerCase();\n // A section (\"Events\", \"Files\"): the whole of it.\n const section = REFERENCE.split(/\\n(?=## )/).find((block) => firstLine(block) === `## ${wanted}`);\n if (section) return section.trim() + \"\\n\";\n // A method: every entry whose heading names it.\n const method = new RegExp(`\\`${escape(wanted)}\\\\(|[ /]${escape(wanted)}\\\\(`);\n const matches = REFERENCE.split(/\\n(?=#{2,3} )/).filter(\n (block) => block.startsWith(\"### \") && method.test(firstLine(block)),\n );\n if (matches.length > 0) return matches.map((block) => block.trim()).join(\"\\n\\n\") + \"\\n\";\n const names = [...REFERENCE.matchAll(/^### `(\\w+)\\(/gm)].map((m) => m[1]);\n return `No entry for \"${topic}\". Methods: ${names.join(\", \")}. help() returns the whole reference.\\n`;\n}\n\nfunction escape(text: string): string {\n return text.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n"]}