@kronajs/core
v0.4.0
Published
Framework-agnostic core behind kronajs: a line-based document model for JSON, YAML, TOML and INI/.env, with folding ranges and a line diff.
Maintainers
Readme
@kronajs/core
Framework-agnostic document model, format providers and line diff for
configuration files. The engine behind kronajs;
no React, no DOM.
npm install @kronajs/coreimport { parseDocument, diffLines, alignDiff } from '@kronajs/core'
import '@kronajs/core/yaml'
const doc = parseDocument(source, 'yaml')
doc.lines // source lines
doc.foldingRanges // collapsible ranges
doc.tokensAt(12) // tokens for one line, computed on demand and memoized
doc.diagnostics // parse problems, never thrown
const { rows, stats } = alignDiff(diffLines(before, after))The model is lines plus folding ranges, not a tree of values: diffing is
line based and folding is range based, so one representation serves both — and
no JavaScript object is ever built from the document, which rules out prototype
pollution through a __proto__ key by construction.
| Function | Returns |
| --- | --- |
| parseDocument(source, format?, options?) | DocumentModel — never throws for content reasons |
| diffLines(left, right, options?) | DiffResult, with approximate when the time budget ran out |
| alignDiff(result, options?) | Rows for two panels, with spacers, plus stats |
| intralineDiff(left, right, options?) | Word-level spans for one changed row |
| collapseUnchanged(rows, options?) | Unchanged runs worth hiding |
| unifiedPatch(rows, leftLines, rightLines, options?) | The diff as a unified patch, ready for git apply |
| scanUnsafeCharacters(text) | Bidi and invisible characters, with positions |
| toSnapshot / fromSnapshot | Structured-clone-safe projection, for Web Workers |
Formats: JSON/JSONC, TOML and INI/.env register from the main entry point; YAML
lives behind @kronajs/core/yaml because its parser is tens of kilobytes, and
JSON5, XML, HCL and Java properties behind @kronajs/core/json5, /xml, /hcl
and /properties, so a bundle that never opens one does not carry its
scanner.
License
MIT
