glost-utils
v0.2.0
Published
Framework-agnostic utilities for GLOST manipulation, conversion, and merging
Maintainers
Readme
glost-utils
Framework-agnostic utilities for GLOST manipulation, conversion, and merging.
Overview
This package provides practical utilities for working with GLOST documents:
- Text-to-GLOST conversion - Convert plain text into GLOST documents
- Document manipulation - Extract words, sentences, metadata
- Data merging - Merge transcription and metadata into existing documents
- Script conversion - Handle ruby text and text format conversion
Installation
npm install glost-utils
# or
pnpm add glost-utilsUsage
Text to GLOST
import { convertTextToGLOST } from "glost-utils";
const doc = await convertTextToGLOST({
text: "Hello world",
language: "en",
strategy: myLanguageStrategy // Your tokenization logic
});Document Queries
import {
getAllWordsFromDocument,
getFirstSentenceFromDocument,
hasTranscriptionData
} from "glost-utils";
// Get all word nodes
const words = getAllWordsFromDocument(doc);
// Get first sentence
const sentence = getFirstSentenceFromDocument(doc);
// Check for transcription
if (hasTranscriptionData(doc, "ipa")) {
// Document has IPA transcription
}Merging Data
import {
mergeTranscriptionDataIntoDocument,
extendGLOSTDocumentWithMetadata
} from "glost-utils";
// Merge transcription into existing document
const withTranscription = mergeTranscriptionDataIntoDocument(doc, {
"hello": { ipa: "həˈloʊ" },
"world": { ipa: "wɜːld" }
});
// Add metadata
const withMetadata = extendGLOSTDocumentWithMetadata(doc, {
"hello": { frequency: "very-common", difficulty: "beginner" },
"world": { frequency: "very-common", difficulty: "beginner" }
});Script Conversion
import {
convertScriptToString,
type RubySegment
} from "glost-utils";
// Convert ruby text to plain string
const ruby: RubySegment[] = [
{ base: "漢字", ruby: "かんじ" }
];
const plain = convertScriptToString(ruby); // "漢字"API
Text Conversion
convertTextToGLOST(options)- Convert text to GLOST document
Document Utilities
getAllWordsFromDocument(doc)- Extract all word nodesgetFirstSentenceFromDocument(doc)- Get first sentencegetWordsFromFirstSentence(doc)- Get words from first sentencegetDocumentTranscriptionSystems(doc)- List transcription systemshasTranscriptionData(doc, system)- Check for transcriptiongetDocumentMetadata(doc)- Get document metadatagetSentenceTranslation(sentence, lang)- Get sentence translation
Merging Utilities
mergeTranscriptionData(word, data)- Merge transcription into wordmergeTranscriptionDataIntoDocument(doc, data)- Merge into documentextendGLOSTWithMetadata(word, metadata)- Add metadata to wordextendGLOSTDocumentWithMetadata(doc, data)- Add metadata to documenthydrateGLOSTDocument(doc, data)- Hydrate with all data typesfilterGLOSTByGender(doc, gender)- Filter words by gender
Script Conversion
convertScriptToString(script)- Convert to plain stringisRubyScript(script)- Check if ruby textisPlainTextScript(script)- Check if plain textensureArrayFormat(script)- Convert to array formatensureStringFormat(script)- Convert to string formatgetPlainText(script)- Extract plain text
Exports
// Main utilities
import { ... } from "glost-utils";
// Text-to-GLOST
import { convertTextToGLOST } from "glost-utils/text-to-glost";
// Merging
import { mergeTranscriptionDataIntoDocument } from "glost-utils/merger";
// Document utilities
import { getAllWordsFromDocument } from "glost-utils/document";
// Script conversion
import { convertScriptToString } from "glost-utils/script";
// Interfaces
import type { ILanguageStrategy } from "glost-utils/interfaces";Related Packages
glost- Core GLOST types and nodesglost-common- Common utilitiesglost-extensions- Extension system
License
MIT
