Skip to content

@jsvision/core / parseTheme

Function: parseTheme()

parseTheme(json): Theme

Defined in: color/serialize.ts:191

Parse a serialized theme, validating every field, and return a complete Theme.

Validation is strict and by field kind: the envelope must be { version: 1, roles }; the role set must match exactly (no missing, unknown, or wrong-shape roles); every color parses via toRgb; the desktop pattern must be a single printable cell; and each attrs must be an integer in [0, 127]. Any failure throws InvalidThemeError — a partial theme is never returned. Parsing is pure JSON.parse (no eval, no filesystem).

Parameters

json

string

A theme JSON string, e.g. from serializeTheme.

Returns

Theme

The validated, fully-populated theme.

Throws

InvalidThemeError on malformed JSON, a bad version/shape, or any invalid field.

Example

ts
import { serializeTheme, parseTheme, defaultTheme } from '@jsvision/core';

const theme = parseTheme(serializeTheme(defaultTheme)); // deep-equals defaultTheme