2.0.0 • Published 5 years ago

qtoml v2.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

qtoml

Use TOML to construct object literals directly in JavaScript

Coverage Status

const toml = require('qtoml')

let obj = toml`
  [example]
  key1 = ${5 + 8}
  key2 = 17

  [elpmaxe]
  1yek = 31`

console.log(obj) // {example: {key1: 13, key2: 17}, elpmaxe: {1yek: 31}}

DESCRIPTION

This module provides a tagged template string for contructing objects using TOML.

toml`string` -> Object

The provided string must be valid TOML or an error will be thrown. Embedded expressions are evaluted and included and can evaluate to any datatype that can be used in TOML. For example, the following is valid:

obj = toml`a = ${new Date()}` // equivalent of {a: new Date()}

Only values that can be represented as TOML are allowed. Trying to include other values will throw. For example, a single-type array is fine:

let value = [1, 2, 3]
obj = toml`a = ${value}` // {a: [1, 2, 3]}

But a mixed-type array is not:

let value = ['a', 'b', 1, 2]
obj = toml`a = ${value}` // throws
2.0.0

5 years ago

1.0.0

6 years ago