JavaScript sample
Requires Node.js 20 or later. Uses only built-in modules; no installation step. Run from the repository root:
node implementations/javascript/configsample.mjs examples/sample.dotregnode implementations/javascript/configsample.mjs --mode raw examples/sample.dotregnode --test implementations/javascript/test.mjsOmit the filename or use - to read UTF-8 standard input. The CLI collects and
decodes the whole file before writing JSON; errors leave standard output empty.
strings is the default mode. Type annotations are retained without conversion.
import { createReadStream } from 'node:fs';import { parseEach, decodeString } from './dotreg.mjs';
const source = createReadStream('settings.txt');try { await parseEach(source, entry => { if (entry.kind === 'value') { const text = decodeString(entry); // Consume text.value here; text.unset distinguishes explicit empty values. } });} finally { source.destroy(); }parse(source) returns a promise of syntax entries without partial results on
failure. parseEach(source, visit) awaits each callback before parsing another
entry; returning false stops successfully and exceptions propagate unchanged.
Both accept a string, a byte array, or an iterable/async iterable of byte arrays.
Streams are borrowed; callers close their own resources, including after a stop.
The library retains a physical line, one lookahead line and the heading stack;
an unfinished multiline value requires its body. Persistent path nodes avoid
copying all ancestors into every stored scope. Each emitted path is independent.
Literal block decoding returns the existing string where possible; escaped
text is assembled from spans. It does not split the whole source into lines.
The library also exports appendValue, setText and setTextAt. They accept a complete source string and decoded key elements and return an updated string. Appending follows the deepest existing matching heading with two more spaces and a relative key; with no matching heading it writes a fully qualified key at the end. setText replaces a unique occurrence or appends when absent; setTextAt selects a zero-based repeated occurrence. Values are written as escaped, double-quoted single-line strings. These helpers preserve unrelated source text and do not perform type conversion.
This folder also contains VS Code editor support, including formatting, parser diagnostics, syntax highlighting, snippets and resolved-key hover information, plus a hierarchical Document Outline. It offers type-name completion and a quick fix for adding provisional type annotations. These names are hints, not a standard type list or conversion implementation. It uses this same parser and requires no npm dependencies.
See the parser set for the common contract, conformance checks and provisional grammar choices. TypeScript uses this same engine with static types. The public APIs remain provisional.