Package Exports
- toml-patch
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (toml-patch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
toml-patch
Patch, parse, and stringify TOML.
Installation
toml-patch is dependency-free and can be installed via npm or yarn.
$ npm install --save toml-patchFor browser usage, you can use unpkg:
<script src="https://unpkg.com/toml-patch"></script>API
# patch(existing, updated)
Patch an existing TOML string with the given updated JS/JSON value, while attempting to retain the format of the existing document, including comments, indentation, and structure.
const TOML = require('toml-patch');
const assert = require('assert');
const existing = `
# This is a TOML document
title = "TOML example"
owner.name = "Bob"
`
const patched = TOML.patch(existing, {
title: 'TOML example',
owner: {
name: 'Tim'
}
});
assert.strictEqual(patched, `
# This is a TOML document
title = "TOML example"
owner.name = "Tim"
`);# parse(value)
Parse a TOML string into a JS/JSON value.
const TOML = require('toml-patch');
const assert = require('assert');
const parsed = TOML.parse(`
# This is a TOML document.
title = "TOML Example"
[owner]
name = "Tim"`);
assert.deepStrictEqual(parsed, {
title: 'TOML Example',
owner: {
name: 'Tim'
}
});# stringify(value[, options])
Convert a JS/JSON value to a TOML string. options can be provided for high-level formatting guidelines that follows prettier's configuration.
options
[printWidth = 80]- (coming soon)[trailingComma = false]- Add trailing comma to inline tables[bracketSpacing = true]-true:{ key = "value" },false:{key = "value"}
const TOML = require('toml-patch');
const assert = require('assert');
const toml = TOML.stringify({
title: 'TOML Example',
owner: {
name: 'Tim'
}
});
assert.strictEqual(toml,
`title = "TOML Example"
[owner]
name = "Tim"`);