{"name":"@decimalturn/toml-patch","version":"3.0.3","keywords":["toml","patch","edit","parse","stringify","parser","encoder","decoder","preserve-whitespace","preserve-comments","preserve-formatting","edit-in-place"],"license":"MIT","_id":"@decimalturn/toml-patch@3.0.3","maintainers":[{"name":"decimalturn","email":"decimalturn@gmail.com"}],"contributors":["Tim Hall <tim.hall.engr@gmail.com>","Martin Leduc <31558169+DecimalTurn@users.noreply.github.com>"],"homepage":"https://github.com/DecimalTurn/toml-patch","dist":{"shasum":"eb0efe204edfc241f6ff338bbaf6f76220feea7f","tarball":"http://registry-npm.ywwl.com/@decimalturn/toml-patch/download/@decimalturn/toml-patch-3.0.3.tgz","fileCount":6,"integrity":"sha512-z8w09LRalZT41nOp5y0hwpyJnLZ2bcBAJ4tIbznxLfEzfWIgVLIP9vWjCPJ2IhBBuo0/P+Rr5ibCZtbroyuHHQ==","signatures":[{"sig":"MEYCIQCgf0qgUkQFJbEbnvd96LekhKWlCe+Ezai48rrr1GBxtgIhAKWHeiFxRIAtZ5V08TUzwW8IcXHWPgP4xxHarG7jJHuw","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@decimalturn%2ftoml-patch@3.0.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":197645,"size":56671,"noattachment":false,"key":"/@decimalturn/toml-patch/-/@decimalturn/toml-patch-3.0.3.tgz"},"type":"module","types":"./dist/toml-patch.d.ts","engines":{"node":">=16"},"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":"vitest run","build":"tsdown","specs":"vitest run --config vitest.specs.config.ts","profile":"node benchmark/profile.mjs","test:go":"./run-toml-test.bash","lint:fix":"oxlint --fix","test:all":"pnpm run test && pnpm run test:playwright","benchmark":"npm-run-all2 bench:*","typecheck":"tsc","build:demo":"node scripts/build-demo.mjs","test:watch":"vitest","bench:parse":"node benchmark/parse-benchmark.mjs","publish:jsr":"jsr publish --allow-dirty","benchmark:ci":"npm-run-all2 \"bench:* -- --sample --versions latest\"","build:profile":"cross-env PROFILE_BUILD=1 tsdown","bench:stringify":"node benchmark/stringify-benchmark.mjs","check-overrides":"node scripts/check-overrides.mjs","test:playwright":"playwright test","playwright:install":"playwright install --with-deps chromium","compare-branch-size":"node scripts/compare-branch-size.mjs"},"_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},"repository":{"url":"git+https://github.com/DecimalTurn/toml-patch.git","type":"git"},"description":"Patch, parse, and stringify TOML while preserving comments, whitespace and formatting.","directories":{},"_nodeVersion":"24.19.0","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":{"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)."}},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jsr":"^0.14.0","mri":"^1","glob":"^13.0.0","tslib":"^2.0.0","dedent":"^1.5.3","oxlint":"^1.55.0","rimraf":"^6.0.0","tsdown":"^0.22.13","vitest":"^4.1.10","js-yaml":"4.3.1","benchmark":"^2","cross-env":"^10.1.0","smol-toml":"^1.6.1","typescript":"7.0.2","@types/node":"^24.12.3","npm-run-all2":"^9.0.0","@types/dedent":"^0.7.2","@types/js-yaml":"^4.0.0","@playwright/test":"^1.59.1","@js-temporal/polyfill":"^0.5.1","@decimalturn/toml-patch":"npm:@decimalturn/toml-patch@3.0.2"},"_npmOperationalInternal":{"tmp":"tmp/toml-patch_3.0.3_1787452052287_0.023457951693590662","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":1787452052426,"_cnpm_publish_time":1787452052426,"dist-tags":{"dev":"3.3.3-dev","latest":"3.3.3","lite":"3.3.3-lite"}}