Simple TOML parser
npm i toml-parse
CDN Links:
- https://cdn.jsdelivr.net/npm/toml-parse@1.0.0/toml-parse.js
- https://www.unpkg.com/toml-parse@1.0.0/toml-parse.js
// ES6
import tomlParse from "toml-parse";
// commonjs
const tomlParse = require("toml-parse");
const tomlCode = `
# Example TOML code
title = "Hello, World"
[author]
name = "John Doe"
age = 30
`;
const json = tomlParse.toJSON(tomlCode);
console.log(json);
const json = {
title: 'Hello, World',
author: { name: 'John Doe', age: 30 }
};
const tomlCode = tomlParse.fromJSON(json);
console.log(tomlCode);
const tomlCode = `
# Example TOML code
[body]
background-color = "white"
color = "black"
`;
const cssCode = tomlParse.toCSS(tomlCode);
console.log(cssCode);
const cssCode = `
body {
background-color: white;
color: black;
}
h1, h2 {
font-weight: bold;
}
`;
const tomlCode = tomlParse.fromCSS(cssCode);
console.log(tomlCode);
const value = 'Hello, World!';
const tomlValue = tomlParse.toTomlValue(value);
console.log(tomlValue);
const value = 'true';
const parsed = tomlParse.parseValue(value);
console.log(parsed);
const json = {
fruits: {
apple: 'red',
banana: 'yellow'
}
};
const tableName = 'fruits.apple';
const table = tomlParse.getTable(json, tableName);
console.log(table);
const json = {
fruits: {
apple: 'red',
banana: 'yellow'
}
};
const key = 'fruits.apple';
const value = 'green';
tomlParse.setKey(json, key, value);
console.log(json);