Skip to Content
DocumentationPackages@glotblocks/glost-core

glost (Core)

The core package providing types, node factories, and tree utilities.

Installation

pnpm add @glotblocks/glost

Exports

// Main entry import { ... } from '@glotblocks/glost'; // Subpath exports import { ... } from '@glotblocks/glost/nodes'; import { ... } from '@glotblocks/glost/utils'; import { ... } from '@glotblocks/glost/guards'; import { ... } from '@glotblocks/glost/validators';

Node Factory Functions

createGLOSTWordNode

Create a word node with full control.

function createGLOSTWordNode( value: string, transcription?: TransliterationData, metadata?: LinguisticMetadata, level?: LinguisticLevel, lang?: GlostLanguage, script?: string, extras?: GLOSTExtras ): GLOSTWord;

Example:

const word = createGLOSTWordNode( "hello", { ipa: { text: "heloʊ", system: "ipa" } }, { partOfSpeech: "interjection" }, "word", "en", "latin", { translations: { th: "สวัสดี" } } );

createSimpleWord

Create a word with single transcription.

function createSimpleWord( text: string, transliteration: string, system: TranscriptionSystem ): GLOSTWord;

Language-Specific Helpers

Language-specific helper functions have been moved to dedicated packages:

  • Thai: @glotblocks/glost-th package - See glost-th 
  • Japanese: @glotblocks/glost-ja package - See glost-ja 
// Install language packages // npm install @glotblocks/glost-th @glotblocks/glost-ja import { createThaiWord } from '@glotblocks/glost-th'; import { createJapaneseWord } from '@glotblocks/glost-ja';

See Migration Guide for upgrading.

createSentenceFromWords

Build a sentence from word nodes.

function createSentenceFromWords( words: GLOSTWord[], lang: GlostLanguage, script?: string, originalText?: string ): GLOSTSentence;

createDocumentFromParagraphs

Build a document from paragraphs.

function createDocumentFromParagraphs( paragraphs: GLOSTParagraph[], lang: GlostLanguage, script?: string, metadata?: Record<string, unknown> ): GLOSTRoot;

Tree Traversal

getAllWords

Get all word nodes in a tree.

function getAllWords(node: GLOSTNode): GLOSTWord[];

getAllSentences

Get all sentence nodes.

function getAllSentences(node: GLOSTNode): GLOSTSentence[];

findWordsByLanguage

Find words by language code.

function findWordsByLanguage(node: GLOSTNode, lang: GlostLanguage): GLOSTWord[];

Word Utilities

getWordText

Get the text value of a word.

function getWordText(word: GLOSTWord): string;

getWordTranscription

Get transcription for a specific system.

function getWordTranscription(word: GLOSTWord, system: TranscriptionSystem): string | undefined;

hasWordTranscription

Check if word has transcription for a system.

function hasWordTranscription(word: GLOSTWord, system: TranscriptionSystem): boolean;

Type Guards

From glost/guards:

function isGLOSTWord(node: unknown): node is GLOSTWord; function isGLOSTSentence(node: unknown): node is GLOSTSentence; function isGLOSTRoot(node: unknown): node is GLOSTRoot; function hasChildren(node: unknown): node is { children: unknown[] };

Validators

From glost/validators:

function validateGLOSTTree(tree: unknown): string[];

Returns an array of validation error messages. Empty array means valid.

Types

Key types exported:

type GLOSTWord type GLOSTSentence type GLOSTParagraph type GLOSTRoot type GLOSTNode type TransliterationData type LinguisticMetadata type GLOSTExtras type GlostLanguage
Last updated on