API reference

Cell value inference

inferCellType, escape helpers, error code constants.

5 exports · 3 source files

Escape

src/utils/escape.ts

# escapeCellString function

src/utils/escape.ts:30

Escape a string for safe storage in an OOXML cell. Already-escaped sequences (`_xHHHH_`) are protected by escaping their leading underscore; illegal codepoints are replaced with their `_xHHHH_` representation.

function escapeCellString(s: string): string

Parameters

NameTypeDescription
s string

Returns

string

# unescapeCellString function

src/utils/escape.ts:45

Inverse of escapeCellString. Looking from left to right we replace any `_xHHHH_` sequence with the corresponding code unit; the protected `_x005F_` becomes a literal underscore which the subsequent replacements skip safely (replace's regex is non-overlapping).

function unescapeCellString(s: string): string

Parameters

NameTypeDescription
s string

Returns

string

Inference

src/utils/inference.ts

# inferCellType function

src/utils/inference.ts:39

Infer the cell `t` attribute for a runtime value. - `boolean` → 'b' - `number` → 'n' (incl. integer numerics; date inference is left to the caller because Excel decides on type via the cell's number format, not the raw value) - `Date` → 'd' - string starting with `=` → 'f' (formula) - string in ERROR_CODES → 'e' - any other string → 's' - `null` / `undefined` → 'n' (empty) Throws nothing — returns 'n' as the no-information fallback.

function inferCellType(value: unknown): CellDataType

Parameters

NameTypeDescription
value unknown

Returns

CellDataType

# ERROR_CODES const

src/utils/inference.ts:13

Excel error tokens. Anything outside this set is treated as a string.

const ERROR_CODES: ReadonlySet<string>

Css

src/utils/css.ts

# cssRecordToInlineStyle function

src/utils/css.ts:25

Serialize a CSS-property record to an inline-style declaration string (`prop1: val1; prop2: val2`). Properties are alphabetised so the output is deterministic across runs. - Empty record returns `''`. - Empty-string values are skipped (treat as "unset"). - Values containing `;` are dropped — they would terminate the declaration early and risk attribute-injection in `style="…"` contexts. Callers should pre-escape user data; this is a defensive last line. The returned string is suitable for direct interpolation into an HTML `style="…"` attribute *after* the usual attribute-value HTML escaping (no `&` / `"` injection here — this only guards against stray semicolons).

function cssRecordToInlineStyle(record: Record<string, string> | undefined): string

Parameters

NameTypeDescription
record Record<string, string> | undefined

Returns

string