@sealcode/jdd 0.4.13 → 0.4.15
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/@types/document.d.ts +4 -3
- package/lib/document.js +10 -4
- package/lib/document.js.map +1 -1
- package/lib/utils/insert_nbsp.js +1 -1
- package/lib/utils/insert_nbsp.js.map +1 -1
- package/package.json +1 -1
package/@types/document.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { JDDContext } from "./jdd-context.js";
|
|
2
2
|
import { Registry } from "./registry.js";
|
|
3
3
|
export declare const JDDStatus: unique symbol;
|
|
4
|
-
export type
|
|
4
|
+
export type ComponentData = {
|
|
5
5
|
component_name: string;
|
|
6
6
|
args: Record<string, unknown>;
|
|
7
|
-
}
|
|
7
|
+
};
|
|
8
|
+
export type RawJDDocument = Array<ComponentData>;
|
|
8
9
|
export type JDDocumentContainer<Status extends "parsed" | "storage"> = {
|
|
9
10
|
value: RawJDDocument;
|
|
10
11
|
[JDDStatus]: Status;
|
|
11
12
|
};
|
|
12
13
|
export declare function documentToStorage(registry: Registry, jdd_context: JDDContext, document_container: JDDocumentContainer<"parsed">): Promise<JDDocumentContainer<"storage">>;
|
|
13
|
-
export declare function documentToParsed(registry: Registry, jdd_context: JDDContext, document_container: JDDocumentContainer<"storage"
|
|
14
|
+
export declare function documentToParsed(registry: Registry, jdd_context: JDDContext, document_container: JDDocumentContainer<"storage">, handle_unknown_component?: (component_name: string) => void): Promise<JDDocumentContainer<"parsed">>;
|
|
14
15
|
export declare function documentContainerFromParsed(document: RawJDDocument): JDDocumentContainer<"parsed">;
|
|
15
16
|
export declare function documentContainerFromStorage(document: RawJDDocument): JDDocumentContainer<"storage">;
|
package/lib/document.js
CHANGED
|
@@ -12,17 +12,23 @@ export async function documentToStorage(registry, jdd_context, document_containe
|
|
|
12
12
|
}));
|
|
13
13
|
return { value: result, [JDDStatus]: "storage" };
|
|
14
14
|
}
|
|
15
|
-
export async function documentToParsed(registry, jdd_context, document_container) {
|
|
16
|
-
|
|
15
|
+
export async function documentToParsed(registry, jdd_context, document_container, handle_unknown_component = (component_name) => {
|
|
16
|
+
console.warn(`Unknown component when parsing a JDD document: ${component_name}`);
|
|
17
|
+
} // you can pass a different function and e.g. throw an error here if you want
|
|
18
|
+
) {
|
|
19
|
+
const result = (await Promise.all(document_container.value
|
|
20
|
+
.map(async ({ component_name, args }) => {
|
|
17
21
|
const component = registry.get(component_name);
|
|
18
22
|
if (!component) {
|
|
19
|
-
|
|
23
|
+
handle_unknown_component(component_name);
|
|
24
|
+
return null;
|
|
20
25
|
}
|
|
21
26
|
return {
|
|
22
27
|
component_name,
|
|
23
28
|
args: await component.convertStorageToParsed(jdd_context, args),
|
|
24
29
|
};
|
|
25
|
-
})
|
|
30
|
+
})
|
|
31
|
+
.filter((e) => e !== null)));
|
|
26
32
|
return { value: result, [JDDStatus]: "parsed" };
|
|
27
33
|
}
|
|
28
34
|
export function documentContainerFromParsed(document) {
|
package/lib/document.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.js","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC;AAclC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,QAAkB,EAClB,WAAuB,EACvB,kBAAiD;IAEjD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,EAAE;QAC/D,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC/C,IAAI,CAAC,SAAS,E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C,EAAE,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC3C,QAAuB;IAEvB,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC;AACzD,CAAC"}
|
package/lib/utils/insert_nbsp.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const insert_nbsp = (string) => string.replace(/(?<=\s[A-Za-z])\s|(?<=^[A-Za-z])\s/gm, " ");
|
|
1
|
+
export const insert_nbsp = (string) => (string || "").replace(/(?<=\s[A-Za-z])\s|(?<=^[A-Za-z])\s/gm, " ");
|
|
2
2
|
//# sourceMappingURL=insert_nbsp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert_nbsp.js","sourceRoot":"","sources":["../../src/utils/insert_nbsp.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,EAAE,CAC7C,MAAM,CAAC,OAAO,CAAC,sCAAsC,EAAE,QAAQ,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"insert_nbsp.js","sourceRoot":"","sources":["../../src/utils/insert_nbsp.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,EAAE,CAC7C,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,sCAAsC,EAAE,QAAQ,CAAC,CAAC"}
|