@mostlyrightmd/core/formats
Classes
Section titled “Classes”ToonTabularError
Section titled “ToonTabularError”Thrown when toonDumps receives rows that aren’t valid tabular input. The encoder refuses non-uniform rows or non-primitive values rather than silently dropping columns or stringifying nested structures.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”new ToonTabularError()
Section titled “new ToonTabularError()”new ToonTabularError(
message,options):ToonTabularError
Parameters
Section titled “Parameters”message
Section titled “message”string = ""
options
Section titled “options”ContractErrorOptions = {}
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Properties
Section titled “Properties”actual
Section titled “actual”
readonlyactual:null|string
Inherited from
Section titled “Inherited from”defaultErrorCode
Section titled “defaultErrorCode”
staticdefaultErrorCode:string="CONTRACT_ERROR"
Subclass override — the stable string enum surfaced via errorCode.
Inherited from
Section titled “Inherited from”ContractError.defaultErrorCode
docUrl
Section titled “docUrl”
readonlydocUrl:null|string
Inherited from
Section titled “Inherited from”errorCode
Section titled “errorCode”
readonlyerrorCode:string
Inherited from
Section titled “Inherited from”expected
Section titled “expected”
readonlyexpected:null|string
Inherited from
Section titled “Inherited from”
readonlyfield:null|string
Inherited from
Section titled “Inherited from”location
Section titled “location”
readonlylocation:null|string
Inherited from
Section titled “Inherited from”name:
string="ToonTabularError"
Overrides
Section titled “Overrides”ContractError.name
requestId
Section titled “requestId”
readonlyrequestId:null|string
Inherited from
Section titled “Inherited from”source
Section titled “source”
readonlysource:null|string
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”toDict()
Section titled “toDict()”toDict():
Record<string,unknown>
Return a JSON-safe dict suitable for MCP error.data.
Returns
Section titled “Returns”Record<string, unknown>
Inherited from
Section titled “Inherited from”Functions
Section titled “Functions”csvDumps()
Section titled “csvDumps()”csvDumps(
rows):string
Serialize rows to a CSV string. Column names come from
Object.keys(rows[0]). Empty rows emits an empty string (matches
pd.DataFrame({}).to_csv(index=False)).
Header cells are quoted on the same triggers as data cells. Without this
guard, a column name like "a,b"
would dump as two headers and roundtrip into the wrong schema.
Parameters
Section titled “Parameters”readonly Record<string, unknown>[]
Returns
Section titled “Returns”string
csvLoads()
Section titled “csvLoads()”csvLoads(
data):object
Parse a CSV string into rows + columns.
Returns string-valued cells; CSV is dtype-lossy (pandas read_csv would re-infer dtypes — we leave that to the caller).
Empty input → { rows: [], columns: [] }. Header-only input →
{ rows: [], columns: [...] }.
The stateful parser preserves newlines inside quoted cells, so
csvLoads(csvDumps(rows)) is a faithful roundtrip when cells contain \n.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”object
columns
Section titled “columns”columns:
string[]
rows:
Record<string,string>[]
jsonDumps()
Section titled “jsonDumps()”jsonDumps(
rows,columns?):string
Serialize rows to a JSON string.
- Non-empty: emits records form
JSON.stringify(rows). - Empty: emits envelope
{"columns": [...], "data": []}— column names survive the empty-frame roundtrip. Throws RangeError ifcolumnsis not provided in the empty case.
Parameters
Section titled “Parameters”readonly Record<string, unknown>[]
columns?
Section titled “columns?”readonly string[]
Returns
Section titled “Returns”string
jsonLoads()
Section titled “jsonLoads()”jsonLoads(
data):object
Parse a JSON string into rows + column-order array.
Accepts both the records form ([{...}, ...]) and the empty-frame
envelope ({columns, data}). Returns BOTH rows AND columns so
callers can preserve column order on empty cases.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”object
columns
Section titled “columns”columns:
string[]
rows:
Record<string,unknown>[]
toonDumps()
Section titled “toonDumps()”toonDumps(
rows,columns?):string
Encode rows as a TOON v3.0 tabular block.
Header is rows[N]{c1,c2,...}:; data lines are 2-space indented and
comma-separated. Empty rows emits rows[0]: (header-only, no columns
region; matches Python _encode_array_field empty-list path).
Note: empty-row encoding differs from dumps() in toon.py (which
carries column names through rows[0]{...}:). The TS encoder accepts
a columns second arg in the empty case for parity with that
pandas-aware wrapper.
Parameters
Section titled “Parameters”readonly Record<string, unknown>[]
columns?
Section titled “columns?”readonly string[]
Returns
Section titled “Returns”string
Throws
Section titled “Throws”when rows are non-uniform (differing key sets across rows) or when any cell value is non-primitive (object/array/bigint/etc.).
toonLoads()
Section titled “toonLoads()”toonLoads(
data):object
Parse a TOON v3.0 tabular block back into rows + columns.
Accepts only the tabular shape that toonDumps produces; nested objects
/ expanded lists are out of scope for the formats module.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”object
columns
Section titled “columns”columns:
string[]
rows:
Record<string,unknown>[]