UNPKG

@structium/toml

Version:

Serialize and deserialize TOML

36 lines (32 loc) 1.25 kB
import { parse, stringify } from 'smol-toml'; type CommonObj = Record<string, unknown> | Record<string, unknown>[] | unknown[]; type DeserializeOptions = Parameters<typeof parse>[1]; /** * Deserialize a TOML string into a JavaScript object. * * @template Res - The expected return type of the deserialized object * @param {string} content - The TOML content string * @param {object} [options] - Options * @returns {Promise<Res>} - The deserialized JavaScript object * @example * * const tomlContent = ` * name = "Alice" * age = 30 * city = "New York" * ` * * const obj = await deserialize( tomlContent ) * console.log( obj ) */ declare const deserialize: <Res extends CommonObj = CommonObj>(content: string, options?: DeserializeOptions) => Promise<Res>; type SerializeOptions = Parameters<typeof stringify>[1]; /** * Serialize a JavaScript object to a TOML string. * * @param {object} content - An object that will be serialized to a TOML string. * @param {object} [options] - Options * @returns {Promise<string>} A TOML string. */ declare const serialize: (content: object, options?: SerializeOptions) => Promise<string>; export { deserialize, serialize };