https://github.com/timhall/toml-patch
Patch, parse, and stringify TOML
https://github.com/timhall/toml-patch
nodejs toml toml-parser
Last synced: 9 months ago
JSON representation
Patch, parse, and stringify TOML
- Host: GitHub
- URL: https://github.com/timhall/toml-patch
- Owner: timhall
- License: mit
- Created: 2019-04-05T14:23:35.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T19:56:56.000Z (about 3 years ago)
- Last Synced: 2024-05-02T00:47:10.505Z (over 1 year ago)
- Topics: nodejs, toml, toml-parser
- Language: TypeScript
- Homepage:
- Size: 1.1 MB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
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-patch
```
For browser usage, you can use unpkg:
```html
```
## 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.
```js
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.
```js
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"}`
```js
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"`
);
```
## Development
1. Update submodules: `git submodule update --remote`
2. Typecheck: `npm run typecheck`
3. Build: `npm run build`
4. Test: `npm test`
5. Specs compliance: `npm run specs`
6. Benchmark: `npm run benchmark [] [--help] [--example] [--reference]`