glost 0.3.0 → 0.5.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.
Files changed (57) hide show
  1. package/README.md +253 -114
  2. package/dist/index.d.ts +29 -7
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +38 -23
  5. package/dist/index.js.map +1 -1
  6. package/dist/presets.d.ts +7 -0
  7. package/dist/presets.d.ts.map +1 -0
  8. package/dist/presets.js +7 -0
  9. package/dist/presets.js.map +1 -0
  10. package/dist/processor.d.ts +8 -0
  11. package/dist/processor.d.ts.map +1 -0
  12. package/dist/processor.js +7 -0
  13. package/dist/processor.js.map +1 -0
  14. package/dist/registry.d.ts +8 -0
  15. package/dist/registry.d.ts.map +1 -0
  16. package/dist/registry.js +7 -0
  17. package/dist/registry.js.map +1 -0
  18. package/package.json +27 -37
  19. package/src/index.ts +126 -68
  20. package/src/presets.ts +18 -0
  21. package/src/processor.ts +24 -0
  22. package/src/registry.ts +23 -0
  23. package/tsconfig.json +6 -3
  24. package/CHANGELOG.md +0 -151
  25. package/dist/example.d.ts +0 -10
  26. package/dist/example.d.ts.map +0 -1
  27. package/dist/example.js +0 -138
  28. package/dist/example.js.map +0 -1
  29. package/dist/guards.d.ts +0 -103
  30. package/dist/guards.d.ts.map +0 -1
  31. package/dist/guards.js +0 -264
  32. package/dist/guards.js.map +0 -1
  33. package/dist/nodes.d.ts +0 -163
  34. package/dist/nodes.d.ts.map +0 -1
  35. package/dist/nodes.js +0 -186
  36. package/dist/nodes.js.map +0 -1
  37. package/dist/types.d.ts +0 -379
  38. package/dist/types.d.ts.map +0 -1
  39. package/dist/types.js +0 -6
  40. package/dist/types.js.map +0 -1
  41. package/dist/utils.d.ts +0 -203
  42. package/dist/utils.d.ts.map +0 -1
  43. package/dist/utils.js +0 -497
  44. package/dist/utils.js.map +0 -1
  45. package/dist/validators.d.ts +0 -1876
  46. package/dist/validators.d.ts.map +0 -1
  47. package/dist/validators.js +0 -302
  48. package/dist/validators.js.map +0 -1
  49. package/src/__tests__/README.md +0 -20
  50. package/src/__tests__/example.test.ts +0 -43
  51. package/src/__tests__/example.ts +0 -186
  52. package/src/__tests__/mock-data.ts +0 -624
  53. package/src/guards.ts +0 -341
  54. package/src/nodes.ts +0 -327
  55. package/src/types.ts +0 -565
  56. package/src/utils.ts +0 -652
  57. package/src/validators.ts +0 -336
package/src/guards.ts DELETED
@@ -1,341 +0,0 @@
1
- // ============================================================================
2
- // GLOST Type Guards for Better Developer Experience
3
- // ============================================================================
4
-
5
- import type {
6
- GLOSTParagraph,
7
- GLOSTPunctuation,
8
- GLOSTRoot,
9
- GLOSTSentence,
10
- GLOSTSource,
11
- GLOSTSymbol,
12
- GLOSTText,
13
- GLOSTWhiteSpace,
14
- GLOSTWord,
15
- GLOSTNode,
16
- } from "./types";
17
-
18
- // ============================================================================
19
- // Core Node Type Guards
20
- // ============================================================================
21
-
22
- /**
23
- * Type guard to check if a node is an GLOSTWord
24
- */
25
- export function isGLOSTWord(node: unknown): node is GLOSTWord {
26
- return (
27
- typeof node === "object" &&
28
- node !== null &&
29
- "type" in node &&
30
- node.type === "WordNode" &&
31
- "children" in node &&
32
- "lang" in node &&
33
- "script" in node &&
34
- "level" in node &&
35
- "metadata" in node &&
36
- "transcription" in node &&
37
- "extras" in node
38
- );
39
- }
40
-
41
- /**
42
- * Type guard to check if a node is an GLOSTSentence
43
- */
44
- export function isGLOSTSentence(node: unknown): node is GLOSTSentence {
45
- return (
46
- typeof node === "object" &&
47
- node !== null &&
48
- "type" in node &&
49
- node.type === "SentenceNode" &&
50
- "children" in node &&
51
- "lang" in node &&
52
- "script" in node &&
53
- "level" in node &&
54
- "metadata" in node
55
- );
56
- }
57
-
58
- /**
59
- * Type guard to check if a node is an GLOSTParagraph
60
- */
61
- export function isGLOSTParagraph(node: unknown): node is GLOSTParagraph {
62
- return (
63
- typeof node === "object" &&
64
- node !== null &&
65
- "type" in node &&
66
- node.type === "ParagraphNode" &&
67
- "children" in node &&
68
- "lang" in node &&
69
- "script" in node &&
70
- "level" in node &&
71
- "metadata" in node
72
- );
73
- }
74
-
75
- /**
76
- * Type guard to check if a node is an GLOSTRoot
77
- */
78
- export function isGLOSTRoot(node: unknown): node is GLOSTRoot {
79
- return (
80
- typeof node === "object" &&
81
- node !== null &&
82
- "type" in node &&
83
- node.type === "RootNode" &&
84
- "children" in node &&
85
- "lang" in node &&
86
- "script" in node &&
87
- "level" in node &&
88
- "metadata" in node
89
- );
90
- }
91
-
92
- /**
93
- * Type guard to check if a node is an GLOSTText
94
- */
95
- export function isGLOSTText(node: unknown): node is GLOSTText {
96
- return (
97
- typeof node === "object" &&
98
- node !== null &&
99
- "type" in node &&
100
- node.type === "TextNode" &&
101
- "value" in node &&
102
- typeof node.value === "string"
103
- );
104
- }
105
-
106
- /**
107
- * Type guard to check if a node is an GLOSTPunctuation
108
- */
109
- export function isGLOSTPunctuation(node: unknown): node is GLOSTPunctuation {
110
- return (
111
- typeof node === "object" &&
112
- node !== null &&
113
- "type" in node &&
114
- node.type === "PunctuationNode" &&
115
- "value" in node &&
116
- typeof node.value === "string"
117
- );
118
- }
119
-
120
- /**
121
- * Type guard to check if a node is an GLOSTSymbol
122
- */
123
- export function isGLOSTSymbol(node: unknown): node is GLOSTSymbol {
124
- return (
125
- typeof node === "object" &&
126
- node !== null &&
127
- "type" in node &&
128
- node.type === "SymbolNode" &&
129
- "value" in node &&
130
- typeof node.value === "string"
131
- );
132
- }
133
-
134
- /**
135
- * Type guard to check if a node is an GLOSTWhiteSpace
136
- */
137
- export function isGLOSTWhiteSpace(node: unknown): node is GLOSTWhiteSpace {
138
- return (
139
- typeof node === "object" &&
140
- node !== null &&
141
- "type" in node &&
142
- node.type === "WhiteSpaceNode" &&
143
- "value" in node &&
144
- typeof node.value === "string"
145
- );
146
- }
147
-
148
- /**
149
- * Type guard to check if a node is an GLOSTSource
150
- */
151
- export function isGLOSTSource(node: unknown): node is GLOSTSource {
152
- return (
153
- typeof node === "object" &&
154
- node !== null &&
155
- "type" in node &&
156
- node.type === "SourceNode" &&
157
- "value" in node &&
158
- typeof node.value === "string"
159
- );
160
- }
161
-
162
- // ============================================================================
163
- // Content Type Guards
164
- // ============================================================================
165
-
166
- /**
167
- * Type guard to check if a node is GLOSTNode (any GLOST node)
168
- */
169
- export function isGLOSTNode(node: unknown): node is GLOSTNode {
170
- return (
171
- isGLOSTWord(node) ||
172
- isGLOSTSentence(node) ||
173
- isGLOSTParagraph(node) ||
174
- isGLOSTText(node) ||
175
- isGLOSTPunctuation(node) ||
176
- isGLOSTSymbol(node) ||
177
- isGLOSTWhiteSpace(node) ||
178
- isGLOSTSource(node) ||
179
- isGLOSTRoot(node)
180
- );
181
- }
182
-
183
- // ============================================================================
184
- // Document Type Guards
185
- // ============================================================================
186
-
187
- /**
188
- * Type guard to check if a node is an GLOSTDocument (Root or Content)
189
- */
190
- export function isGLOSTDocument(node: unknown): node is GLOSTRoot {
191
- return isGLOSTRoot(node);
192
- }
193
-
194
- // ============================================================================
195
- // Array Type Guards
196
- // ============================================================================
197
-
198
- /**
199
- * Type guard to check if an array contains only GLOSTWord nodes
200
- */
201
- export function isGLOSTWordArray(nodes: unknown[]): nodes is GLOSTWord[] {
202
- return nodes.every(isGLOSTWord);
203
- }
204
-
205
- /**
206
- * Type guard to check if an array contains only GLOSTSentence nodes
207
- */
208
- export function isGLOSTSentenceArray(nodes: unknown[]): nodes is GLOSTSentence[] {
209
- return nodes.every(isGLOSTSentence);
210
- }
211
-
212
- /**
213
- * Type guard to check if an array contains only GLOSTParagraph nodes
214
- */
215
- export function isGLOSTParagraphArray(nodes: unknown[]): nodes is GLOSTParagraph[] {
216
- return nodes.every(isGLOSTParagraph);
217
- }
218
-
219
- /**
220
- * Type guard to check if an array contains only GLOSTContent nodes
221
- */
222
- export function isGLOSTContentArray(nodes: unknown[]): nodes is (GLOSTWord | GLOSTSentence | GLOSTParagraph | GLOSTText | GLOSTPunctuation | GLOSTSymbol | GLOSTWhiteSpace | GLOSTSource)[] {
223
- return nodes.every(node =>
224
- isGLOSTWord(node) ||
225
- isGLOSTSentence(node) ||
226
- isGLOSTParagraph(node) ||
227
- isGLOSTText(node) ||
228
- isGLOSTPunctuation(node) ||
229
- isGLOSTSymbol(node) ||
230
- isGLOSTWhiteSpace(node) ||
231
- isGLOSTSource(node)
232
- );
233
- }
234
-
235
- // ============================================================================
236
- // Utility Type Guards
237
- // ============================================================================
238
-
239
- /**
240
- * Type guard to check if a node has children
241
- */
242
- export function hasChildren(node: unknown): node is { children: unknown[] } {
243
- return (
244
- typeof node === "object" &&
245
- node !== null &&
246
- "children" in node &&
247
- Array.isArray(node.children)
248
- );
249
- }
250
-
251
- /**
252
- * Type guard to check if a node has metadata
253
- */
254
- export function hasMetadata(node: unknown): node is { metadata: Record<string, unknown> } {
255
- return (
256
- typeof node === "object" &&
257
- node !== null &&
258
- "metadata" in node &&
259
- typeof node.metadata === "object" &&
260
- node.metadata !== null
261
- );
262
- }
263
-
264
- /**
265
- * Type guard to check if a node has transcription
266
- */
267
- export function hasTranscription(node: unknown): node is { transcription: Record<string, unknown> } {
268
- return (
269
- typeof node === "object" &&
270
- node !== null &&
271
- "transcription" in node &&
272
- typeof node.transcription === "object" &&
273
- node.transcription !== null
274
- );
275
- }
276
-
277
- /**
278
- * Type guard to check if a node has extras
279
- */
280
- export function hasExtras(node: unknown): node is { extras: Record<string, unknown> } {
281
- return (
282
- typeof node === "object" &&
283
- node !== null &&
284
- "extras" in node &&
285
- typeof node.extras === "object" &&
286
- node.extras !== null
287
- );
288
- }
289
-
290
- // ============================================================================
291
- // Validation Helpers
292
- // ============================================================================
293
-
294
- /**
295
- * Check if a node has valid GLOST structure (type guard based validation)
296
- * For schema-based validation, use validateGLOSTNode from validators.ts
297
- */
298
- export function isGLOSTNodeWithValidChildren(node: unknown): node is GLOSTNode {
299
- if (!isGLOSTNode(node)) {
300
- return false;
301
- }
302
-
303
- // Additional validation for nodes with children
304
- if (hasChildren(node)) {
305
- return (node.children as unknown[]).every(isGLOSTNode);
306
- }
307
-
308
- return true;
309
- }
310
-
311
- /**
312
- * Check if an array contains valid GLOST nodes (type guard based)
313
- */
314
- export function isGLOSTNodeArrayValid(nodes: unknown[]): nodes is GLOSTNode[] {
315
- return nodes.every(isGLOSTNodeWithValidChildren);
316
- }
317
-
318
- /**
319
- * Check if a node is a leaf node (no children)
320
- */
321
- export function isLeafNode(node: GLOSTNode): boolean {
322
- return (
323
- isGLOSTText(node) ||
324
- isGLOSTPunctuation(node) ||
325
- isGLOSTSymbol(node) ||
326
- isGLOSTWhiteSpace(node) ||
327
- isGLOSTSource(node)
328
- );
329
- }
330
-
331
- /**
332
- * Check if a node is a container node (has children)
333
- */
334
- export function isContainerNode(node: GLOSTNode): boolean {
335
- return (
336
- isGLOSTWord(node) ||
337
- isGLOSTSentence(node) ||
338
- isGLOSTParagraph(node) ||
339
- isGLOSTRoot(node)
340
- );
341
- }
package/src/nodes.ts DELETED
@@ -1,327 +0,0 @@
1
- import type {
2
- LanguageCode,
3
- LinguisticMetadata,
4
- GLOSTExtras,
5
- GLOSTParagraph,
6
- GLOSTPunctuation,
7
- GLOSTRoot,
8
- GLOSTSentence,
9
- GLOSTSymbol,
10
- GLOSTText,
11
- GLOSTWhiteSpace,
12
- GLOSTWord,
13
- ScriptSystem,
14
- TransliterationData,
15
- } from "./types";
16
-
17
- // ============================================================================
18
- // Options Interfaces
19
- // ============================================================================
20
-
21
- /**
22
- * Options for creating a GLOST word node
23
- */
24
- export interface CreateWordNodeOptions {
25
- /** The text value of the word */
26
- value: string;
27
- /** Transcription data (IPA, romanization, etc.) */
28
- transcription: TransliterationData;
29
- /** Linguistic metadata (part of speech, etc.) */
30
- metadata: LinguisticMetadata;
31
- /** Language code (ISO-639-1, ISO-639-3, or BCP-47) */
32
- lang?: LanguageCode;
33
- /** Script system used */
34
- script?: ScriptSystem;
35
- /** Additional extension data */
36
- extras?: GLOSTExtras;
37
- }
38
-
39
- /**
40
- * Options for creating a GLOST sentence node
41
- */
42
- export interface CreateSentenceNodeOptions {
43
- /** The original text of the sentence */
44
- originalText: string;
45
- /** Language code */
46
- lang: LanguageCode;
47
- /** Script system used */
48
- script: ScriptSystem;
49
- /** Word nodes in the sentence */
50
- children?: GLOSTWord[];
51
- /** Optional transcription data */
52
- transcription?: TransliterationData;
53
- /** Additional extension data */
54
- extras?: GLOSTExtras;
55
- }
56
-
57
- /**
58
- * Options for creating a GLOST root node
59
- */
60
- export interface CreateRootNodeOptions {
61
- /** Language code */
62
- lang: LanguageCode;
63
- /** Script system used */
64
- script: ScriptSystem;
65
- /** Paragraph nodes */
66
- children?: GLOSTParagraph[];
67
- /** Document metadata */
68
- metadata?: {
69
- title?: string;
70
- author?: string;
71
- date?: string;
72
- description?: string;
73
- };
74
- /** Additional extension data */
75
- extras?: GLOSTExtras;
76
- }
77
-
78
- /**
79
- * Options for creating a simple word node
80
- */
81
- export interface CreateSimpleWordOptions {
82
- /** The text value of the word */
83
- text: string;
84
- /** Transliteration text */
85
- transliteration: string;
86
- /** Transcription system (default: "ipa") */
87
- system?: string;
88
- /** Part of speech (default: "unknown") */
89
- partOfSpeech?: string;
90
- }
91
-
92
-
93
- // ============================================================================
94
- // Node Factory Functions
95
- // ============================================================================
96
-
97
- /**
98
- * Create a GLOST word node
99
- *
100
- * @example
101
- * ```typescript
102
- * const word = createGLOSTWordNode({
103
- * value: "hello",
104
- * transcription: { ipa: { text: "həˈloʊ", system: "ipa" } },
105
- * metadata: { partOfSpeech: "interjection" },
106
- * lang: "en",
107
- * script: "latin"
108
- * });
109
- * ```
110
- */
111
- export function createGLOSTWordNode(options: CreateWordNodeOptions): GLOSTWord {
112
- const { value, transcription, metadata, lang, script, extras } = options;
113
- return {
114
- type: "WordNode",
115
- lang,
116
- script,
117
- transcription,
118
- metadata,
119
- extras,
120
- children: [createGLOSTTextNode(value)],
121
- };
122
- }
123
-
124
- /**
125
- * Create a GLOST sentence node
126
- *
127
- * @example
128
- * ```typescript
129
- * const sentence = createGLOSTSentenceNode({
130
- * originalText: "Hello world",
131
- * lang: "en",
132
- * script: "latin",
133
- * children: [wordNode1, wordNode2]
134
- * });
135
- * ```
136
- */
137
- export function createGLOSTSentenceNode(
138
- options: CreateSentenceNodeOptions,
139
- ): GLOSTSentence {
140
- const {
141
- originalText,
142
- lang,
143
- script,
144
- children = [],
145
- transcription,
146
- extras,
147
- } = options;
148
- return {
149
- type: "SentenceNode",
150
- originalText,
151
- lang,
152
- script,
153
- transcription,
154
- children,
155
- extras,
156
- };
157
- }
158
-
159
- /**
160
- * Create a GLOST paragraph node
161
- */
162
- export function createGLOSTParagraphNode(
163
- children: GLOSTSentence[] = [],
164
- extras?: GLOSTExtras,
165
- ): GLOSTParagraph {
166
- return {
167
- type: "ParagraphNode",
168
- children,
169
- position: undefined,
170
- extras,
171
- };
172
- }
173
-
174
- /**
175
- * Create a GLOST root node
176
- *
177
- * @example
178
- * ```typescript
179
- * const root = createGLOSTRootNode({
180
- * lang: "en",
181
- * script: "latin",
182
- * children: [paragraphNode],
183
- * metadata: { title: "My Document" }
184
- * });
185
- * ```
186
- */
187
- export function createGLOSTRootNode(options: CreateRootNodeOptions): GLOSTRoot {
188
- const { lang, script, children = [], metadata, extras } = options;
189
- return {
190
- type: "RootNode",
191
- lang,
192
- script,
193
- metadata,
194
- children,
195
- position: undefined,
196
- extras,
197
- };
198
- }
199
-
200
- // ============================================================================
201
- // Helper Functions for Common Patterns
202
- // ============================================================================
203
-
204
- /**
205
- * Create a simple word node with basic transcription
206
- *
207
- * @example
208
- * ```typescript
209
- * const word = createSimpleWord({
210
- * text: "hello",
211
- * transliteration: "həˈloʊ",
212
- * system: "ipa",
213
- * partOfSpeech: "interjection"
214
- * });
215
- * ```
216
- */
217
- export function createSimpleWord(options: CreateSimpleWordOptions): GLOSTWord {
218
- const { text, transliteration, system = "ipa", partOfSpeech = "unknown" } = options;
219
-
220
- const transcription: TransliterationData = {
221
- [system]: {
222
- text: transliteration,
223
- system: system as any,
224
- syllables: [text],
225
- },
226
- };
227
-
228
- const metadata: LinguisticMetadata = {
229
- partOfSpeech,
230
- };
231
-
232
- return createGLOSTWordNode({ value: text, transcription, metadata });
233
- }
234
-
235
-
236
- /**
237
- * Create a sentence from an array of words
238
- */
239
- export function createSentenceFromWords(
240
- words: GLOSTWord[],
241
- lang: LanguageCode,
242
- script: ScriptSystem,
243
- originalText?: string,
244
- ): GLOSTSentence {
245
- const text =
246
- originalText ||
247
- words
248
- .map((w) => {
249
- // Extract text from word's Text node children
250
- const textNode = w.children.find(
251
- (child) => child.type === "TextNode",
252
- ) as GLOSTText;
253
- return textNode ? textNode.value : "";
254
- })
255
- .join("");
256
- return createGLOSTSentenceNode({ originalText: text, lang, script, children: words });
257
- }
258
-
259
- /**
260
- * Create a paragraph from an array of sentences
261
- */
262
- export function createParagraphFromSentences(
263
- sentences: GLOSTSentence[],
264
- ): GLOSTParagraph {
265
- return createGLOSTParagraphNode(sentences);
266
- }
267
-
268
- /**
269
- * Create a document from an array of paragraphs
270
- */
271
- export function createDocumentFromParagraphs(
272
- paragraphs: GLOSTParagraph[],
273
- lang: LanguageCode,
274
- script: ScriptSystem,
275
- metadata?: {
276
- title?: string;
277
- author?: string;
278
- date?: string;
279
- description?: string;
280
- },
281
- ): GLOSTRoot {
282
- return createGLOSTRootNode({ lang, script, children: paragraphs, metadata });
283
- }
284
-
285
- // ============================================================================
286
- // NLCST Node Factory Functions
287
- // ============================================================================
288
-
289
- /**
290
- * Create a GLOST punctuation node
291
- */
292
- export function createGLOSTPunctuationNode(value: string): GLOSTPunctuation {
293
- return {
294
- type: "PunctuationNode",
295
- value,
296
- };
297
- }
298
-
299
- /**
300
- * Create a GLOST whitespace node
301
- */
302
- export function createGLOSTWhiteSpaceNode(value: string): GLOSTWhiteSpace {
303
- return {
304
- type: "WhiteSpaceNode",
305
- value,
306
- };
307
- }
308
-
309
- /**
310
- * Create a GLOST symbol node
311
- */
312
- export function createGLOSTSymbolNode(value: string): GLOSTSymbol {
313
- return {
314
- type: "SymbolNode",
315
- value,
316
- };
317
- }
318
-
319
- /**
320
- * Create a GLOST text node
321
- */
322
- export function createGLOSTTextNode(value: string): GLOSTText {
323
- return {
324
- type: "TextNode",
325
- value,
326
- };
327
- }