{"name":"@decimalturn/toml-patch","version":"1.1.1","keywords":["toml","patch","parse","stringify","parser","encoder","decoder"],"license":"MIT","_id":"@decimalturn/toml-patch@1.1.1","maintainers":[{"name":"decimalturn","email":"leducma@live.ca"}],"contributors":[{"name":"Tim Hall","email":"tim.hall.engr@gmail.com"},{"name":"Martin Leduc","email":"31558169+DecimalTurn@users.noreply.github.com"}],"homepage":"https://github.com/DecimalTurn/toml-patch","bugs":{"url":"https://github.com/DecimalTurn/toml-patch/issues"},"dist":{"shasum":"43d311f28b27745a47a5cc019e580016ce3d20dd","tarball":"http://registry-npm.ywwl.com/@decimalturn/toml-patch/download/@decimalturn/toml-patch-1.1.1.tgz","fileCount":6,"integrity":"sha512-EEKLREI/UHL006/n52xxLuBkILSacCPjwhqF1a2RCGegjkAKcXf2F1KMXbwOxsM3Jn5iYAPd1IgGUIfWMMddTA==","signatures":[{"sig":"MEQCHzd9dkI6sLGXXSIbOaoIR/M+W4lo297fLYXGwsDORvUCIQCq2/ZAd6qpLFi1TFW1B4oC18wD5JQ9xsPDuJaN5Qo+Zw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@decimalturn%2ftoml-patch@1.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":120490,"size":34539,"noattachment":false,"key":"/@decimalturn/toml-patch/-/@decimalturn/toml-patch-1.1.1.tgz"},"type":"module","_from":"file:decimalturn-toml-patch-1.1.1.tgz","types":"./dist/toml-patch.d.ts","exports":{".":{"types":"./dist/toml-patch.d.ts","import":"./dist/toml-patch.js","default":"./dist/toml-patch.js"}},"scripts":{"dev":"pnpm run typecheck && pnpm run build && npm-run-all2 --parallel test:all specs","lint":"oxlint","test":"jest --config jest.config.json","build":"rimraf dist && rollup -c","specs":"jest --config jest.specs.config.cjs","profile":"node benchmark/profile.mjs","test:go":"./run-toml-test.bash","test:js":"node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.js.config.mjs","lint:fix":"oxlint --fix","test:all":"pnpm run test && pnpm run test:js && pnpm run test:playwright","benchmark":"npm-run-all2 bench:*","typecheck":"tsc","build:demo":"node scripts/build-demo.mjs","bench:parse":"node benchmark/parse-benchmark.mjs","benchmark:ci":"npm-run-all2 \"bench:* -- --sample --versions latest\"","bench:stringify":"node benchmark/stringify-benchmark.mjs","test:playwright":"playwright test","playwright:install":"playwright install --with-deps chromium"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:7c731882-3cf8-4d7c-9008-383a8c403318"}},"prettier":{"printWidth":100,"singleQuote":true},"_resolved":"/tmp/9d496c15923d12397e2bef79dd1e7b4d/decimalturn-toml-patch-1.1.1.tgz","_integrity":"sha512-EEKLREI/UHL006/n52xxLuBkILSacCPjwhqF1a2RCGegjkAKcXf2F1KMXbwOxsM3Jn5iYAPd1IgGUIfWMMddTA==","repository":{"url":"git+https://github.com/DecimalTurn/toml-patch.git","type":"git"},"_npmVersion":"11.11.0","description":"Patch, parse, and stringify TOML while preserving comments and formatting.","directories":{},"_nodeVersion":"24.14.1","json-comments":{"tips":"Please install the JsonComments plugin to enable commenting functionality for JSON files, see: https://github.com/zhangfisher/json_comments_extension","package.json":{"pnpm.overrides.lodash":"Override needed to avoid vuln detailed in https://github.com/DecimalTurn/toml-patch/security/dependabot/44","devDependencies.js-yaml":"Used by specs/specs.test.ts to parse YAML expected-value fixtures from submodules/spec-tests (https://github.com/iarna/toml-spec-tests).","pnpm.overrides.picomatch":"Override needed to avoid picomatch vuln detailed in https://github.com/DecimalTurn/toml-patch/security/dependabot/42","pnpm.overrides.serialize-javascript":"https://github.com/DecimalTurn/toml-patch/security/dependabot/40"}},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"mri":"^1","glob":"^13.0.0","jest":"^30.0.0","tslib":"^2.0.0","dedent":"^1.5.3","oxlint":"^1.55.0","rimraf":"^6.0.0","rollup":"^4.59.0","js-yaml":"^4.0.0","ts-jest":"^29","benchmark":"^2","smol-toml":"^1.6.1","typescript":"6.0.3","@types/jest":"^30.0.0","@types/node":"^24.0.0","npm-run-all2":"^8.0.0","@types/dedent":"^0.7.2","@types/js-yaml":"^4.0.0","@playwright/test":"^1.59.1","rollup-plugin-dts":"^6.2.1","@rollup/plugin-terser":"^1.0.0","rollup-plugin-filesize":"^10","@decimalturn/toml-patch":"npm:@decimalturn/toml-patch@1.1.0","@rollup/plugin-typescript":"^12.1.2"},"_npmOperationalInternal":{"tmp":"tmp/toml-patch_1.1.1_1776651025185_0.49158588650114243","host":"s3://npm-registry-packages-npm-production"},"readme":"<img src=\"assets/toml-patch-logo.png\" alt=\"toml-patch logo\" width=\"120\"/>\n\n# toml-patch\n\n[![NPM Version](https://img.shields.io/npm/v/%40decimalturn%2Ftoml-patch?logo=npm&logoColor=white&labelColor=red&color=blue)](https://www.npmjs.com/package/@decimalturn/toml-patch)\n[![JSR Version](https://img.shields.io/jsr/v/%40decimalturn/toml-patch?logo=jsr&color=blue)](https://jsr.io/@decimalturn/toml-patch)\n[![GitHub branch status](https://img.shields.io/github/check-runs/DecimalTurn/toml-patch/latest)](https://github.com/DecimalTurn/toml-patch/actions/workflows/test-and-build.yml)\n\nPatch, parse, and stringify [TOML](https://toml.io/en/) (v1.1.0) while preserving comments, whitespace and formatting.\n\nThis project started as a fork of the [original toml-patch](https://github.com/timhall/toml-patch) but has since evolved into a standalone project with significant improvements in reliability and features. We've added TOML v1.1 support, introduced new APIs like `TomlDocument` and `TomlFormat` classes, fixed numerous bugs through increase in testing namely with [toml-test](https://github.com/toml-lang/toml-test).\n\nWe hope that these improvements can be incorporated upstream one day if the original author returns, but until then, this project is the actively maintained version.\n\n## Documentation\n\n- [Installation](#installation)\n- [API](#api)\n- [Patch-lite](#patch-lite)\n- [Comment ownership](#comment-ownership)\n- [Date/time handling and Temporal](#datetime-handling--temporal)\n- [Formatting](#formatting)\n- [Changelog](https://github.com/DecimalTurn/toml-patch/blob/v3.3.2/CHANGELOG.md)\n- [Contributing](https://github.com/DecimalTurn/toml-patch/blob/v3.3.2/CONTRIBUTING.md)\n- [MIT License](https://github.com/DecimalTurn/toml-patch/blob/v3.3.2/LICENSE)\n\n## Installation\n\ntoml-patch is dependency-free and can be installed via your favorite package manager.\n\n*Example with NPM*\n\n```\n$ npm install --save @decimalturn/toml-patch\n```\n\nFor the standalone lite distribution, install the `lite` npm dist-tag:\n\n```sh\n$ npm install --save @decimalturn/toml-patch@lite\n```\n\nFor browser usage, you can use unpkg:\n\n```html\n<script type=\"module\">\n  import * as TOML from 'https://unpkg.com/@decimalturn/toml-patch@v3.3.2/dist/toml-patch.js';\n</script>\n```\n\n## API\n\noverwrite(tomlString: string): void\ntoml-patch provides a functional API for one-time operations and a document-oriented API for workflows that need multiple operations on the same TOML document.\n\nSee the [API reference](https://github.com/DecimalTurn/toml-patch/blob/v3.3.2/docs/API.md) for `patch`, `parse`, `stringify` and the `TomlDocument` class.\n\nFor a quick start, patch an existing TOML string like this:\n\n```js\nimport { patch } from '@decimalturn/toml-patch';\n\nconst existing = 'title = \"TOML example\"\\nowner.name = \"Bob\"\\n';\nconst updated = patch(existing, {\n  title: 'TOML example',\n  owner: { name: 'Tim' }\n});\n```\n\n## Patch-lite\n\n`patch-lite` is a smaller, edit-only distribution for applications that only need to update existing TOML values, such as bumping a package version. It exposes the same `patch` name with a two-argument `(existing, updated)` signature.\n\nIt is not part of the main package: the main package ships the full API only. Install the lite build from the `lite` npm dist-tag, then import it with the same specifier:\n\n```sh\nnpm install --save @decimalturn/toml-patch@lite\n```\n\n```js\nimport { patch } from '@decimalturn/toml-patch';\n\nconst existing = 'version = \"1.0.0\"\\n';\nconst updated = patch(existing, { version: '1.0.1' });\n// updated === 'version = \"1.0.1\"\\n'\n```\n\nThe dist-tag tarball maps its root export to the lite build, so there is no `patch-lite` subpath: `import { patch } from '@decimalturn/toml-patch/patch-lite'` fails with `ERR_PACKAGE_PATH_NOT_EXPORTED`. Switching between the two is an install change, never a code change.\n\nThe lite function edits existing primitive values only and preserves all source text outside the edited value, including comments, whitespace, line endings and a leading BOM. Added or removed keys, array length changes, reordering, renames, primitive/container type changes and unsupported value types throw before any output is produced. Date/time values may be given as the custom `Date` subclasses or as `Temporal` objects; both are serialized into the existing row's shape. Use the full `patch()` for additions, removals, moves, renames and advanced formatting.\n\nUnlike the full `patch()`, the lite distribution performs no encoding validation on its output: it does not reject strings containing unpaired UTF-16 surrogates, which cannot be represented as valid TOML/UTF-8. Use the full `patch()` when this validation is required.\n\nThe [Patch-lite guide](https://github.com/DecimalTurn/toml-patch/blob/v3.3.2/docs/Patch-Lite.md) lists every supported and rejected operation with its error code, the value-encoding rules that differ from the full `patch()`, and the measured size and throughput, so you can check whether the lite distribution covers your use case.\n\n## Comment Ownership\n\nWhen `patch()` removes or reorders an entry, any comment describing it (a same-line trailing\ncomment, or a line-comment directly above with no blank line in between) travels along with\nit, instead of being left behind to describe whatever ends up in that spot. This applies to root\nkeys, `[table]`/`[[array-of-tables]]` blocks, and elements inside multi-line arrays and inline\ntables.\n\n```js\nimport * as TOML from '@decimalturn/toml-patch';\nimport { strict as assert } from 'assert';\n\nconst existing = `\nx = 1 # a note about x\ny = 2\n`;\n\nconst patched = TOML.patch(existing, { y: 2 });\n\nassert.strictEqual(patched, `\ny = 2\n`);\n```\n\nSee the [comment ownership guide](https://github.com/DecimalTurn/toml-patch/blob/v3.3.2/docs/Comment-Ownership.md) for the full behavior, including how a blank line opts a comment out of ownership and current scope limitations.\n\nNote that `patch()` does not reorder entries by default.\nTo have it match the key order of the object you pass in, enable `updateOrder` in the [formatting options](https://github.com/DecimalTurn/toml-patch/blob/v3.3.2/docs/Formatting.md#updateorder).\n\n## Date/Time Handling & Temporal\n\nTOML date/time values are parsed into custom `Date` subclasses (`LocalDate`, `LocalTime`, `LocalDateTime`, `OffsetDateTime`) by default. Set `temporal: true` to receive [Temporal](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Temporal) objects instead. `stringify()` and `patch()` auto-detect Temporal objects and serialize them correctly. Fractional seconds keep the source precision, sub-millisecond digits included.\n\n### Enabling Temporal\n\nThe `temporal: true` option requires `Temporal` to be available in the runtime:\n\n| Runtime | How to enable |\n|---|---|\n| **Node.js 26+** | Built-in (no config needed) |\n| **Node.js 20–24** | `node --harmony-temporal` flag |\n| **Node.js 14–26** | [@js-temporal/polyfill](https://www.npmjs.com/package/@js-temporal/polyfill) |\n\n```js\nimport * as TOML from '@decimalturn/toml-patch';\n\n// Node 26+ (native) or Node 20–24 with --harmony-temporal:\nconst obj = TOML.parse('d = 2024-01-15\\n', { temporal: true });\n// obj.d → Temporal.PlainDate\n\n// All Node versions with the polyfill:\nimport { Temporal } from '@js-temporal/polyfill';\nglobalThis.Temporal = Temporal;\nconst obj2 = TOML.parse('d = 2024-01-15\\n', { temporal: true });\n// obj2.d → PlainDate (polyfill)\n```\n\n> **Note:** Only offset-based timezones (`+05:30`, `Z`) are supported in TOML. IANA timezone annotations (e.g., `[Asia/Kolkata]`) will throw an error.\n\nSee the [date/time guide](https://github.com/DecimalTurn/toml-patch/blob/v3.3.2/docs/Dates.md) for details and examples.\n\n## Formatting\n\nThe `TomlFormat` class controls how TOML documents are formatted during stringification and patching operations.\n\n```typescript\nclass TomlFormat {\n  newLine: string\n  trailingNewline: number\n  trailingComma: boolean\n  bracketSpacing: boolean\n  inlineTableStart?: number\n  truncateZeroTimeInDates: boolean\n  useTabsForIndentation?: boolean\n  indentWidth: number\n  minimumDecimals?: number\n  minimumTimeDecimals?: number\n  leadingBom: boolean\n  updateOrder?: boolean\n  multilineTable: boolean | number | 'auto' | 'parent'\n  multilineArray: boolean | number | 'auto' | 'parent'\n\n  static default(): TomlFormat\n  static autoDetectFormat(tomlString: string): TomlFormat\n}\n```\n\nStart with `TomlFormat.default()` and override the options you need. e.g.:\n\n```js\nimport { stringify, TomlFormat } from '@decimalturn/toml-patch';\n\nconst format = TomlFormat.default();\nformat.newLine = '\\r\\n';\nformat.trailingNewline = 0;\nformat.trailingComma = true;\nformat.bracketSpacing = false;\nformat.indentWidth = 4;\nformat.multilineTable = 'parent';\n\nconst toml = stringify({\n  title: 'My App',\n  tags: ['dev', 'config'],\n  database: { host: 'localhost', port: 5432 }\n}, format);\n\n```\nSee the [formatting reference](https://github.com/DecimalTurn/toml-patch/blob/v3.3.2/docs/Formatting.md) for the complete list of options, auto-detection behavior, `updateOrder` and more examples.\n","publish_time":1776651025333,"_cnpm_publish_time":1776651025333,"dist-tags":{"dev":"3.3.3-dev","latest":"3.3.3","lite":"3.3.3-lite"}}