@equationalapplications/core-okf 4.13.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Equational Applications LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @equationalapplications/core-okf
2
+
3
+ Zero-dependency primitives for producing [Open Knowledge Format](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md) (OKF v0.1) bundles: YAML frontmatter serialization, concept document assembly, and `index.md`/`log.md` builders. No knowledge of any specific data model — bring your own mapping from your domain objects to `OkfFrontmatter` + body strings.
@@ -0,0 +1,39 @@
1
+ type OkfFrontmatterScalar = string | number | boolean | null;
2
+ type OkfFrontmatterValue = OkfFrontmatterScalar | OkfFrontmatterScalar[];
3
+ interface OkfFrontmatter {
4
+ type: string;
5
+ title?: string;
6
+ description?: string;
7
+ resource?: string;
8
+ tags?: string[];
9
+ timestamp?: string;
10
+ [key: string]: OkfFrontmatterValue | undefined;
11
+ }
12
+ interface OkfIndexEntry {
13
+ path: string;
14
+ title: string;
15
+ description?: string;
16
+ }
17
+ interface OkfIndexSection {
18
+ heading: string;
19
+ entries: OkfIndexEntry[];
20
+ }
21
+ interface OkfLogEntry {
22
+ date: string;
23
+ text: string;
24
+ }
25
+ interface OkfFile {
26
+ path: string;
27
+ content: string;
28
+ }
29
+
30
+ declare function serializeFrontmatter(fm: OkfFrontmatter): string;
31
+
32
+ declare function buildConceptDocument(fm: OkfFrontmatter, body: string): string;
33
+
34
+ declare function buildIndexMd(sections: OkfIndexSection[]): string;
35
+ declare function buildRootIndexMd(okfVersion: string, sections: OkfIndexSection[]): string;
36
+
37
+ declare function buildLogMd(entries: OkfLogEntry[]): string;
38
+
39
+ export { type OkfFile, type OkfFrontmatter, type OkfIndexEntry, type OkfIndexSection, type OkfLogEntry, buildConceptDocument, buildIndexMd, buildLogMd, buildRootIndexMd, serializeFrontmatter };
@@ -0,0 +1,39 @@
1
+ type OkfFrontmatterScalar = string | number | boolean | null;
2
+ type OkfFrontmatterValue = OkfFrontmatterScalar | OkfFrontmatterScalar[];
3
+ interface OkfFrontmatter {
4
+ type: string;
5
+ title?: string;
6
+ description?: string;
7
+ resource?: string;
8
+ tags?: string[];
9
+ timestamp?: string;
10
+ [key: string]: OkfFrontmatterValue | undefined;
11
+ }
12
+ interface OkfIndexEntry {
13
+ path: string;
14
+ title: string;
15
+ description?: string;
16
+ }
17
+ interface OkfIndexSection {
18
+ heading: string;
19
+ entries: OkfIndexEntry[];
20
+ }
21
+ interface OkfLogEntry {
22
+ date: string;
23
+ text: string;
24
+ }
25
+ interface OkfFile {
26
+ path: string;
27
+ content: string;
28
+ }
29
+
30
+ declare function serializeFrontmatter(fm: OkfFrontmatter): string;
31
+
32
+ declare function buildConceptDocument(fm: OkfFrontmatter, body: string): string;
33
+
34
+ declare function buildIndexMd(sections: OkfIndexSection[]): string;
35
+ declare function buildRootIndexMd(okfVersion: string, sections: OkfIndexSection[]): string;
36
+
37
+ declare function buildLogMd(entries: OkfLogEntry[]): string;
38
+
39
+ export { type OkfFile, type OkfFrontmatter, type OkfIndexEntry, type OkfIndexSection, type OkfLogEntry, buildConceptDocument, buildIndexMd, buildLogMd, buildRootIndexMd, serializeFrontmatter };
package/dist/index.js ADDED
@@ -0,0 +1,133 @@
1
+ 'use strict';
2
+
3
+ // src/frontmatter.ts
4
+ var RESERVED_LITERALS = /* @__PURE__ */ new Set(["true", "false", "yes", "no", "on", "off", "null", "~", ""]);
5
+ function looksLikeNumber(value) {
6
+ return /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/.test(value);
7
+ }
8
+ function isIso8601Timestamp(value) {
9
+ return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2}|[+-]\d{4}|[+-]\d{2})$/.test(value);
10
+ }
11
+ function needsQuoting(value) {
12
+ if (value !== value.trim()) return true;
13
+ if (/[\n\r\t]/.test(value)) return true;
14
+ if (isIso8601Timestamp(value)) return false;
15
+ if (/^[-?:]\s/.test(value)) return true;
16
+ if (/^[\[\]{}&,*%!|>'"@`]/.test(value)) return true;
17
+ if (value.includes(":") || value.includes("#")) return true;
18
+ if (RESERVED_LITERALS.has(value.toLowerCase())) return true;
19
+ if (looksLikeNumber(value)) return true;
20
+ return false;
21
+ }
22
+ function quoteString(value) {
23
+ const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
24
+ return `"${escaped}"`;
25
+ }
26
+ function serializeScalarString(value) {
27
+ return needsQuoting(value) ? quoteString(value) : value;
28
+ }
29
+ function serializeKey(key) {
30
+ if (/\s/.test(key) || needsQuoting(key) || isIso8601Timestamp(key)) {
31
+ return quoteString(key);
32
+ }
33
+ return key;
34
+ }
35
+ function serializeValue(value) {
36
+ if (value === null) return "null";
37
+ if (typeof value === "boolean") return String(value);
38
+ if (typeof value === "number") return String(value);
39
+ if (typeof value === "string") return serializeScalarString(value);
40
+ throw new Error(`Unsupported frontmatter value type: ${typeof value}`);
41
+ }
42
+ function serializeFrontmatter(fm) {
43
+ const lines = ["---"];
44
+ for (const [key, value] of Object.entries(fm)) {
45
+ if (value === void 0) continue;
46
+ if (Array.isArray(value)) {
47
+ if (value.length === 0) {
48
+ lines.push(`${serializeKey(key)}: []`);
49
+ } else {
50
+ lines.push(`${serializeKey(key)}:`);
51
+ for (const item of value) {
52
+ if (typeof item === "string") {
53
+ lines.push(` - ${serializeScalarString(item)}`);
54
+ } else {
55
+ lines.push(` - ${serializeValue(item)}`);
56
+ }
57
+ }
58
+ }
59
+ } else {
60
+ lines.push(`${serializeKey(key)}: ${serializeValue(value)}`);
61
+ }
62
+ }
63
+ lines.push("---");
64
+ return lines.join("\n") + "\n";
65
+ }
66
+
67
+ // src/concept.ts
68
+ function buildConceptDocument(fm, body) {
69
+ return `${serializeFrontmatter(fm)}
70
+ ${body}`;
71
+ }
72
+
73
+ // src/index-md.ts
74
+ function renderEntry(entry) {
75
+ const esc = (s) => s.replace(/\\/g, "\\\\").replace(/\[/g, "\\[").replace(/\]/g, "\\]").replace(/\r?\n/g, " ");
76
+ const title = esc(entry.title);
77
+ const description = entry.description ? esc(entry.description) : void 0;
78
+ return description ? `* [${title}](${entry.path}) - ${description}` : `* [${title}](${entry.path})`;
79
+ }
80
+ function renderSections(sections) {
81
+ const lines = [];
82
+ for (const section of sections) {
83
+ lines.push(`## ${section.heading}`);
84
+ lines.push("");
85
+ for (const entry of section.entries) {
86
+ lines.push(renderEntry(entry));
87
+ }
88
+ lines.push("");
89
+ }
90
+ if (lines.length === 0) return "";
91
+ return lines.join("\n").trimEnd() + "\n";
92
+ }
93
+ function buildIndexMd(sections) {
94
+ return renderSections(sections);
95
+ }
96
+ function buildRootIndexMd(okfVersion, sections) {
97
+ const frontmatter = `---
98
+ okf_version: ${serializeScalarString(okfVersion)}
99
+ ---
100
+ `;
101
+ return `${frontmatter}
102
+ ${renderSections(sections)}`;
103
+ }
104
+
105
+ // src/log-md.ts
106
+ function buildLogMd(entries) {
107
+ const groups = /* @__PURE__ */ new Map();
108
+ for (const entry of entries) {
109
+ const group = groups.get(entry.date) ?? [];
110
+ group.push(entry);
111
+ groups.set(entry.date, group);
112
+ }
113
+ const dates = Array.from(groups.keys()).sort((a, b) => a < b ? 1 : a > b ? -1 : 0);
114
+ const lines = [];
115
+ for (const date of dates) {
116
+ lines.push(`## ${date}`);
117
+ lines.push("");
118
+ for (const entry of groups.get(date)) {
119
+ lines.push(`- ${entry.text}`);
120
+ }
121
+ lines.push("");
122
+ }
123
+ if (lines.length === 0) return "";
124
+ return lines.join("\n").trimEnd() + "\n";
125
+ }
126
+
127
+ exports.buildConceptDocument = buildConceptDocument;
128
+ exports.buildIndexMd = buildIndexMd;
129
+ exports.buildLogMd = buildLogMd;
130
+ exports.buildRootIndexMd = buildRootIndexMd;
131
+ exports.serializeFrontmatter = serializeFrontmatter;
132
+ //# sourceMappingURL=index.js.map
133
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/frontmatter.ts","../src/concept.ts","../src/index-md.ts","../src/log-md.ts"],"names":[],"mappings":";;;AAEA,IAAM,iBAAA,mBAAoB,IAAI,GAAA,CAAI,CAAC,MAAA,EAAQ,OAAA,EAAS,KAAA,EAAO,IAAA,EAAM,IAAA,EAAM,KAAA,EAAO,MAAA,EAAQ,GAAA,EAAK,EAAE,CAAC,CAAA;AAE9F,SAAS,gBAAgB,KAAA,EAAwB;AAC/C,EAAA,OAAO,yCAAA,CAA0C,KAAK,KAAK,CAAA;AAC7D;AAEA,SAAS,mBAAmB,KAAA,EAAwB;AAClD,EAAA,OAAO,sFAAA,CAAuF,KAAK,KAAK,CAAA;AAC1G;AAEA,S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AA,CAAK,CAAC,CAAA,EAAG,MAAO,CAAA,GAAI,CAAA,GAAI,IAAI,CAAA,GAAI,CAAA,GAAI,KAAK,CAAE,CAAA;AAEnF,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,KAAA,CAAM,IAAA,CAAK,CAAA,GAAA,EAAM,IAAI,CAAA,CAAE,CAAA;AACvB,IAAA,KAAA,CAAM,KAAK,EAAE,CAAA;AACb,IAAA,KAAA,MAAW,KAAA,IAAS,MAAA,CAAO,GAAA,CAAI,IAAI,CAAA,EAAI;AACrC,MAAA,KAAA,CAAM,IAAA,CAAK,CAAA,EAAA,EAAK,KAAA,CAAM,IAAI,CAAA,CAAE,CAAA;AAAA,IAC9B;AACA,IAAA,KAAA,CAAM,KAAK,EAAE,CAAA;AAAA,EACf;AAEA,EAAA,IAAI,KAAA,CAAM,MAAA,KAAW,CAAA,EAAG,OAAO,EAAA;AAC/B,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA,CAAE,SAAQ,GAAI,IAAA;AACtC","file":"index.js","sourcesContent":["import type { OkfFrontmatter } from './types';\n\nconst RESERVED_LITERALS = new Set(['true', 'false', 'yes', 'no', 'on', 'off', 'null', '~', '']);\n\nfunction looksLikeNumber(value: string): boolean {\n return /^[+-]?(\\d+\\.?\\d*|\\.\\d+)([eE][+-]?\\d+)?$/.test(value);\n}\n\nfunction isIso8601Timestamp(value: string): boolean {\n return /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2}|[+-]\\d{4}|[+-]\\d{2})$/.test(value);\n}\n\nfunction needsQuoting(value: string): boolean {\n if (value !== value.trim()) return true;\n if (/[\\n\\r\\t]/.test(value)) return true;\n if (isIso8601Timestamp(value)) return false;\n\n // Quote strings that YAML could otherwise parse as collections/indicators.\n if (/^[-?:]\\s/.test(value)) return true;\n if (/^[\\[\\]{}&,*%!|>'\"@`]/.test(value)) return true;\n\n if (value.includes(':') || value.includes('#')) return true;\n if (RESERVED_LITERALS.has(value.toLowerCase())) return true;\n if (looksLikeNumber(value)) return true;\n return false;\n}\n\nfunction quoteString(value: string): string {\n const escaped = value\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r')\n .replace(/\\t/g, '\\\\t');\n return `\"${escaped}\"`;\n}\n\nexport function serializeScalarString(value: string): string {\n return needsQuoting(value) ? quoteString(value) : value;\n}\n\nfunction serializeKey(key: string): string {\n // needsQuoting() intentionally exempts ISO 8601 timestamps for *values*.\n // For keys, quote timestamp-like scalars to avoid YAML timestamp coercion in some parsers.\n if (/\\s/.test(key) || needsQuoting(key) || isIso8601Timestamp(key)) {\n return quoteString(key);\n }\n return key;\n}\n\nfunction serializeValue(value: unknown): string {\n if (value === null) return 'null';\n if (typeof value === 'boolean') return String(value);\n if (typeof value === 'number') return String(value);\n if (typeof value === 'string') return serializeScalarString(value);\n throw new Error(`Unsupported frontmatter value type: ${typeof value}`);\n}\n\nexport function serializeFrontmatter(fm: OkfFrontmatter): string {\n const lines: string[] = ['---'];\n for (const [key, value] of Object.entries(fm)) {\n if (value === undefined) continue;\n if (Array.isArray(value)) {\n if (value.length === 0) {\n lines.push(`${serializeKey(key)}: []`);\n } else {\n lines.push(`${serializeKey(key)}:`);\n for (const item of value as unknown[]) {\n if (typeof item === 'string') {\n lines.push(` - ${serializeScalarString(item)}`);\n } else {\n lines.push(` - ${serializeValue(item)}`);\n }\n }\n }\n } else {\n lines.push(`${serializeKey(key)}: ${serializeValue(value)}`);\n }\n }\n lines.push('---');\n return lines.join('\\n') + '\\n';\n}\n","import type { OkfFrontmatter } from './types';\nimport { serializeFrontmatter } from './frontmatter';\n\nexport function buildConceptDocument(fm: OkfFrontmatter, body: string): string {\n return `${serializeFrontmatter(fm)}\\n${body}`;\n}\n","import { serializeScalarString } from './frontmatter';\nimport type { OkfIndexEntry, OkfIndexSection } from './types';\n\nfunction renderEntry(entry: OkfIndexEntry): string {\n const esc = (s: string) =>\n s\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\\[/g, '\\\\[')\n .replace(/\\]/g, '\\\\]')\n .replace(/\\r?\\n/g, ' ');\n\n const title = esc(entry.title);\n const description = entry.description ? esc(entry.description) : undefined;\n\n return description\n ? `* [${title}](${entry.path}) - ${description}`\n : `* [${title}](${entry.path})`;\n}\n\nfunction renderSections(sections: OkfIndexSection[]): string {\n const lines: string[] = [];\n for (const section of sections) {\n lines.push(`## ${section.heading}`);\n lines.push('');\n for (const entry of section.entries) {\n lines.push(renderEntry(entry));\n }\n lines.push('');\n }\n if (lines.length === 0) return '';\n return lines.join('\\n').trimEnd() + '\\n';\n}\n\nexport function buildIndexMd(sections: OkfIndexSection[]): string {\n return renderSections(sections);\n}\n\nexport function buildRootIndexMd(okfVersion: string, sections: OkfIndexSection[]): string {\n const frontmatter = `---\\nokf_version: ${serializeScalarString(okfVersion)}\\n---\\n`;\n return `${frontmatter}\\n${renderSections(sections)}`;\n}\n","import type { OkfLogEntry } from './types';\n\nexport function buildLogMd(entries: OkfLogEntry[]): string {\n const groups = new Map<string, OkfLogEntry[]>();\n for (const entry of entries) {\n const group = groups.get(entry.date) ?? [];\n group.push(entry);\n groups.set(entry.date, group);\n }\n\n const dates = Array.from(groups.keys()).sort((a, b) => (a < b ? 1 : a > b ? -1 : 0));\n\n const lines: string[] = [];\n for (const date of dates) {\n lines.push(`## ${date}`);\n lines.push('');\n for (const entry of groups.get(date)!) {\n lines.push(`- ${entry.text}`);\n }\n lines.push('');\n }\n\n if (lines.length === 0) return '';\n return lines.join('\\n').trimEnd() + '\\n';\n}\n"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,127 @@
1
+ // src/frontmatter.ts
2
+ var RESERVED_LITERALS = /* @__PURE__ */ new Set(["true", "false", "yes", "no", "on", "off", "null", "~", ""]);
3
+ function looksLikeNumber(value) {
4
+ return /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/.test(value);
5
+ }
6
+ function isIso8601Timestamp(value) {
7
+ return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2}|[+-]\d{4}|[+-]\d{2})$/.test(value);
8
+ }
9
+ function needsQuoting(value) {
10
+ if (value !== value.trim()) return true;
11
+ if (/[\n\r\t]/.test(value)) return true;
12
+ if (isIso8601Timestamp(value)) return false;
13
+ if (/^[-?:]\s/.test(value)) return true;
14
+ if (/^[\[\]{}&,*%!|>'"@`]/.test(value)) return true;
15
+ if (value.includes(":") || value.includes("#")) return true;
16
+ if (RESERVED_LITERALS.has(value.toLowerCase())) return true;
17
+ if (looksLikeNumber(value)) return true;
18
+ return false;
19
+ }
20
+ function quoteString(value) {
21
+ const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
22
+ return `"${escaped}"`;
23
+ }
24
+ function serializeScalarString(value) {
25
+ return needsQuoting(value) ? quoteString(value) : value;
26
+ }
27
+ function serializeKey(key) {
28
+ if (/\s/.test(key) || needsQuoting(key) || isIso8601Timestamp(key)) {
29
+ return quoteString(key);
30
+ }
31
+ return key;
32
+ }
33
+ function serializeValue(value) {
34
+ if (value === null) return "null";
35
+ if (typeof value === "boolean") return String(value);
36
+ if (typeof value === "number") return String(value);
37
+ if (typeof value === "string") return serializeScalarString(value);
38
+ throw new Error(`Unsupported frontmatter value type: ${typeof value}`);
39
+ }
40
+ function serializeFrontmatter(fm) {
41
+ const lines = ["---"];
42
+ for (const [key, value] of Object.entries(fm)) {
43
+ if (value === void 0) continue;
44
+ if (Array.isArray(value)) {
45
+ if (value.length === 0) {
46
+ lines.push(`${serializeKey(key)}: []`);
47
+ } else {
48
+ lines.push(`${serializeKey(key)}:`);
49
+ for (const item of value) {
50
+ if (typeof item === "string") {
51
+ lines.push(` - ${serializeScalarString(item)}`);
52
+ } else {
53
+ lines.push(` - ${serializeValue(item)}`);
54
+ }
55
+ }
56
+ }
57
+ } else {
58
+ lines.push(`${serializeKey(key)}: ${serializeValue(value)}`);
59
+ }
60
+ }
61
+ lines.push("---");
62
+ return lines.join("\n") + "\n";
63
+ }
64
+
65
+ // src/concept.ts
66
+ function buildConceptDocument(fm, body) {
67
+ return `${serializeFrontmatter(fm)}
68
+ ${body}`;
69
+ }
70
+
71
+ // src/index-md.ts
72
+ function renderEntry(entry) {
73
+ const esc = (s) => s.replace(/\\/g, "\\\\").replace(/\[/g, "\\[").replace(/\]/g, "\\]").replace(/\r?\n/g, " ");
74
+ const title = esc(entry.title);
75
+ const description = entry.description ? esc(entry.description) : void 0;
76
+ return description ? `* [${title}](${entry.path}) - ${description}` : `* [${title}](${entry.path})`;
77
+ }
78
+ function renderSections(sections) {
79
+ const lines = [];
80
+ for (const section of sections) {
81
+ lines.push(`## ${section.heading}`);
82
+ lines.push("");
83
+ for (const entry of section.entries) {
84
+ lines.push(renderEntry(entry));
85
+ }
86
+ lines.push("");
87
+ }
88
+ if (lines.length === 0) return "";
89
+ return lines.join("\n").trimEnd() + "\n";
90
+ }
91
+ function buildIndexMd(sections) {
92
+ return renderSections(sections);
93
+ }
94
+ function buildRootIndexMd(okfVersion, sections) {
95
+ const frontmatter = `---
96
+ okf_version: ${serializeScalarString(okfVersion)}
97
+ ---
98
+ `;
99
+ return `${frontmatter}
100
+ ${renderSections(sections)}`;
101
+ }
102
+
103
+ // src/log-md.ts
104
+ function buildLogMd(entries) {
105
+ const groups = /* @__PURE__ */ new Map();
106
+ for (const entry of entries) {
107
+ const group = groups.get(entry.date) ?? [];
108
+ group.push(entry);
109
+ groups.set(entry.date, group);
110
+ }
111
+ const dates = Array.from(groups.keys()).sort((a, b) => a < b ? 1 : a > b ? -1 : 0);
112
+ const lines = [];
113
+ for (const date of dates) {
114
+ lines.push(`## ${date}`);
115
+ lines.push("");
116
+ for (const entry of groups.get(date)) {
117
+ lines.push(`- ${entry.text}`);
118
+ }
119
+ lines.push("");
120
+ }
121
+ if (lines.length === 0) return "";
122
+ return lines.join("\n").trimEnd() + "\n";
123
+ }
124
+
125
+ export { buildConceptDocument, buildIndexMd, buildLogMd, buildRootIndexMd, serializeFrontmatter };
126
+ //# sourceMappingURL=index.mjs.map
127
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/frontmatter.ts","../src/concept.ts","../src/index-md.ts","../src/log-md.ts"],"names":[],"mappings":";AAEA,IAAM,iBAAA,mBAAoB,IAAI,GAAA,CAAI,CAAC,MAAA,EAAQ,OAAA,EAAS,KAAA,EAAO,IAAA,EAAM,IAAA,EAAM,KAAA,EAAO,MAAA,EAAQ,GAAA,EAAK,EAAE,CAAC,CAAA;AAE9F,SAAS,gBAAgB,KAAA,EAAwB;AAC/C,EAAA,OAAO,yCAAA,CAA0C,KAAK,KAAK,CAAA;AAC7D;AAEA,SAAS,mBAAmB,KAAA,EAAwB;AAClD,EAAA,OAAO,sFAAA,CAAuF,KAAK,KAAK,CAAA;AAC1G;AAEA,SAAS,aAAa,KAAA,EAAwB;AAC5C,EAAA,IAAI,KAAA,KAAU,KAAA,CAAM,IAAA,EAAK,EAAG,OAAO,IAAA;AACnC,EAAA,IAAI,UAAA,CAAW,IAAA,CAAK,KAAK,CAAA,EAAG,OAAO,IAAA;AACnC,EAAA,IAAI,kBAAA,CAAmB,KAAK,CAAA,EAAG,OAAO,KAAA;AAGtC,EAAA,IAAI,UAAA,CAAW,IAAA,CAAK,KAAK,CAAA,EAAG,OAAO,IAAA;AACnC,EAAA,IAAI,sBAAA,CAAuB,IAAA,CAAK,KAAK,CAAA,EAAG,OAAO,IAAA;AAE/C,EAAA,IAAI,KAAA,CAAM,SAAS,GAAG,CAAA,IAAK,MAAM,QAAA,CAAS,GAAG,GAAG,OAAO,IAAA;AACvD,EAAA,IAAI,kBAAkB,GAAA,CAA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AE,CAAA;AAAA,EACf;AAEA,EAAA,IAAI,KAAA,CAAM,MAAA,KAAW,CAAA,EAAG,OAAO,EAAA;AAC/B,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA,CAAE,SAAQ,GAAI,IAAA;AACtC","file":"index.mjs","sourcesContent":["import type { OkfFrontmatter } from './types';\n\nconst RESERVED_LITERALS = new Set(['true', 'false', 'yes', 'no', 'on', 'off', 'null', '~', '']);\n\nfunction looksLikeNumber(value: string): boolean {\n return /^[+-]?(\\d+\\.?\\d*|\\.\\d+)([eE][+-]?\\d+)?$/.test(value);\n}\n\nfunction isIso8601Timestamp(value: string): boolean {\n return /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2}|[+-]\\d{4}|[+-]\\d{2})$/.test(value);\n}\n\nfunction needsQuoting(value: string): boolean {\n if (value !== value.trim()) return true;\n if (/[\\n\\r\\t]/.test(value)) return true;\n if (isIso8601Timestamp(value)) return false;\n\n // Quote strings that YAML could otherwise parse as collections/indicators.\n if (/^[-?:]\\s/.test(value)) return true;\n if (/^[\\[\\]{}&,*%!|>'\"@`]/.test(value)) return true;\n\n if (value.includes(':') || value.includes('#')) return true;\n if (RESERVED_LITERALS.has(value.toLowerCase())) return true;\n if (looksLikeNumber(value)) return true;\n return false;\n}\n\nfunction quoteString(value: string): string {\n const escaped = value\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r')\n .replace(/\\t/g, '\\\\t');\n return `\"${escaped}\"`;\n}\n\nexport function serializeScalarString(value: string): string {\n return needsQuoting(value) ? quoteString(value) : value;\n}\n\nfunction serializeKey(key: string): string {\n // needsQuoting() intentionally exempts ISO 8601 timestamps for *values*.\n // For keys, quote timestamp-like scalars to avoid YAML timestamp coercion in some parsers.\n if (/\\s/.test(key) || needsQuoting(key) || isIso8601Timestamp(key)) {\n return quoteString(key);\n }\n return key;\n}\n\nfunction serializeValue(value: unknown): string {\n if (value === null) return 'null';\n if (typeof value === 'boolean') return String(value);\n if (typeof value === 'number') return String(value);\n if (typeof value === 'string') return serializeScalarString(value);\n throw new Error(`Unsupported frontmatter value type: ${typeof value}`);\n}\n\nexport function serializeFrontmatter(fm: OkfFrontmatter): string {\n const lines: string[] = ['---'];\n for (const [key, value] of Object.entries(fm)) {\n if (value === undefined) continue;\n if (Array.isArray(value)) {\n if (value.length === 0) {\n lines.push(`${serializeKey(key)}: []`);\n } else {\n lines.push(`${serializeKey(key)}:`);\n for (const item of value as unknown[]) {\n if (typeof item === 'string') {\n lines.push(` - ${serializeScalarString(item)}`);\n } else {\n lines.push(` - ${serializeValue(item)}`);\n }\n }\n }\n } else {\n lines.push(`${serializeKey(key)}: ${serializeValue(value)}`);\n }\n }\n lines.push('---');\n return lines.join('\\n') + '\\n';\n}\n","import type { OkfFrontmatter } from './types';\nimport { serializeFrontmatter } from './frontmatter';\n\nexport function buildConceptDocument(fm: OkfFrontmatter, body: string): string {\n return `${serializeFrontmatter(fm)}\\n${body}`;\n}\n","import { serializeScalarString } from './frontmatter';\nimport type { OkfIndexEntry, OkfIndexSection } from './types';\n\nfunction renderEntry(entry: OkfIndexEntry): string {\n const esc = (s: string) =>\n s\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\\[/g, '\\\\[')\n .replace(/\\]/g, '\\\\]')\n .replace(/\\r?\\n/g, ' ');\n\n const title = esc(entry.title);\n const description = entry.description ? esc(entry.description) : undefined;\n\n return description\n ? `* [${title}](${entry.path}) - ${description}`\n : `* [${title}](${entry.path})`;\n}\n\nfunction renderSections(sections: OkfIndexSection[]): string {\n const lines: string[] = [];\n for (const section of sections) {\n lines.push(`## ${section.heading}`);\n lines.push('');\n for (const entry of section.entries) {\n lines.push(renderEntry(entry));\n }\n lines.push('');\n }\n if (lines.length === 0) return '';\n return lines.join('\\n').trimEnd() + '\\n';\n}\n\nexport function buildIndexMd(sections: OkfIndexSection[]): string {\n return renderSections(sections);\n}\n\nexport function buildRootIndexMd(okfVersion: string, sections: OkfIndexSection[]): string {\n const frontmatter = `---\\nokf_version: ${serializeScalarString(okfVersion)}\\n---\\n`;\n return `${frontmatter}\\n${renderSections(sections)}`;\n}\n","import type { OkfLogEntry } from './types';\n\nexport function buildLogMd(entries: OkfLogEntry[]): string {\n const groups = new Map<string, OkfLogEntry[]>();\n for (const entry of entries) {\n const group = groups.get(entry.date) ?? [];\n group.push(entry);\n groups.set(entry.date, group);\n }\n\n const dates = Array.from(groups.keys()).sort((a, b) => (a < b ? 1 : a > b ? -1 : 0));\n\n const lines: string[] = [];\n for (const date of dates) {\n lines.push(`## ${date}`);\n lines.push('');\n for (const entry of groups.get(date)!) {\n lines.push(`- ${entry.text}`);\n }\n lines.push('');\n }\n\n if (lines.length === 0) return '';\n return lines.join('\\n').trimEnd() + '\\n';\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@equationalapplications/core-okf",
3
+ "version": "4.13.1",
4
+ "description": "Zero-dependency Open Knowledge Format (OKF) v0.1 primitives: frontmatter serialization, concept documents, index.md and log.md builders.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "import": "./dist/index.mjs"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsup",
17
+ "dev": "tsup --watch",
18
+ "typecheck": "tsc --noEmit",
19
+ "test": "vitest run",
20
+ "test:watch": "vitest"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "LICENSE",
25
+ "README.md"
26
+ ],
27
+ "license": "MIT",
28
+ "keywords": [
29
+ "okf",
30
+ "open-knowledge-format",
31
+ "markdown",
32
+ "frontmatter",
33
+ "knowledge-graph",
34
+ "typescript"
35
+ ],
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/equationalapplications/expo-llm-wiki.git",
39
+ "directory": "packages/okf"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/equationalapplications/expo-llm-wiki/issues"
43
+ },
44
+ "homepage": "https://github.com/equationalapplications/expo-llm-wiki/tree/main/packages/okf#readme",
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "registry": "https://registry.npmjs.org"
48
+ },
49
+ "engines": {
50
+ "node": ">=20"
51
+ },
52
+ "devDependencies": {
53
+ "tsup": "^8.0.0",
54
+ "typescript": "^5.4.0",
55
+ "vitest": "4.1.5"
56
+ }
57
+ }