Convert Lona files between JSON, and source code (Swift + MDX).
Lona token files are typically stored as MDX (Markdown with embedded React components).
Token files support a special kind of code block, marked with the language "tokens", that contains Lona token definitions. These definitions can be stored as JSON, or (a small subset of) Swift. This utility converts between the different formats.
Supported formats: 'json'
, 'source'
Example: Convert a .md
document to JSON
import { convertDocument } from '@lona/serialization'
const lonaDocument = '...' // source code of a Lona document
const lonaJson = convertDocument(lonaDocument, 'json')
Supported formats: 'json'
, 'source'
Example: Convert a .tokens
file to JSON
import { convertLogic } from '@lona/serialization'
const lonaTokens = '...' // source code of a Lona tokens file
const lonaJson = serialization.convertLogic(lonaTokens, 'json')