serialize-typst-value
v1.0.0
Published
Serialize JavaScript values into Typst data expressions
Maintainers
Readme
Serialize Typst Value
This is a simple package that provides a way to serialize JavaScript objects to Typst values. It is useful for converting JavaScript objects into a format that can be inserted into Typst documents.
Installation
npm install serialize-typst-valueUsage
import serializeTypstValue from 'serialize-typst-value'
const obj = {
name: 'John Doe',
age: 30,
isActive: true,
hobbies: ['reading', 'gaming'],
address: {
street: '123 Main St',
city: 'Anytown',
country: 'USA'
}
}
console.log(serializeTypstValue(obj))
// With added whitespace:
// (
// "name": "John Doe",
// "age": 30,
// "isActive": true,
// "hobbies": ["reading", "gaming"],
// "address": ("street": "123 Main St", "city": "Anytown", "country": "USA")
// )Details
Values are serialized in the following manner:
nullis serialized asnonebooleanis serialized astrueorfalsenumberis serialized as either anintor afloatNaNis serialized asfloat.nanInfinityis serialized asfloat.inf-Infinityis serialized as-float.inf
BigIntis serialized as anintstringare serialized as astrFunctionandSymbolwill throw anUnexpectedValueErrorundefinedwill be ignored in object values, and will throw anUnexpectedValueErrorin any other placeTemporal.PlainDate,Temporal.PlainDateTime, andTemporal.PlainTimeis serialized asdatetimeDate,Map,Set, andRegExpis not yet supported, but might be included in a future minor version, it's currently undefined behavior to try and serialize them
