Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899/** Path utilities. @module */
import type { TomlPath, } from './types.ts';
/** Decoded key segment fields needed by path readers, without parser ownership.
@example ```ts const segment: TomlKeySegmentView = { type: 'TOMLBare', name: 'title', }; ``` */type TomlKeySegmentView = | { readonly type: 'TOMLBare'; readonly name: string; } | { readonly type: 'TOMLQuoted'; readonly value: string; };
/** Dotted key segments viewed as read-only path data.
@example ```ts const key: TomlKeyView = { keys: [{ type: 'TOMLBare', name: 'title', },], }; ``` */type TomlKeyView = { readonly keys: readonly TomlKeySegmentView[]; };
/** Surface the string form of a key fragment. `TOMLBare` carries the identifier as `name`; `TOMLQuoted` carries the decoded string as `value`. Both are surfaced as the same string here so path comparisons treat `key = 1` and `"key" = 1` identically. @returns Computed string. @example ```ts keyNameOf({ key: { type: 'TOMLBare', name: 'foo' } as never, },); // 'foo' ``` */export function keyNameOf({ key, }: { readonly key: TomlKeySegmentView; },): string { return key.type === 'TOMLBare' ? key.name : key.value;}
/** The full list of segments that a `TOMLKey` spells. Dotted-key forms like `a.b.c = 1` produce three segments. @returns Computed result (`readonly string[]`). @example ```ts keysOf({ key: tomlKeyForABC, },); // ['a', 'b', 'c'] ``` */export function keysOf({ key, }: { readonly key: TomlKeyView; },): readonly string[] { return key.keys .map(function nameOf(k: TomlKeySegmentView,) { return keyNameOf({ key: k, },); },);}
/** Render a `TomlPath` as a human-readable string for error messages. @returns Computed string. @example ```ts formatPath({ path: ['fruits', 0, 'name'] as const, },); // 'fruits[0].name' ``` */export function formatPath({ path, }: { readonly path: TomlPath; },): string { return path .map(function fmt( seg, i, ) { if ((typeof seg) === 'number') return `[${String(seg,)}]`; if (i === 0) return seg; return `.${seg}`; },) .join('',);}