{"name":"@decimalturn/toml-patch","version":"3.2.0","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.2.0","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":"f2508cd487ee695f51e1c892e189a024b28a3cfb","tarball":"http://registry-npm.ywwl.com/@decimalturn/toml-patch/download/@decimalturn/toml-patch-3.2.0.tgz","fileCount":7,"integrity":"sha512-KqMMj0TWTywEf0W6gDbbK5+9Z8GkV4w+X/1fUDHVoo0Z5jWJUrdoOhzSwdYG7WT0D72hb2MI3ftlldhPxW+viQ==","signatures":[{"sig":"MEUCIQDRvaXjyAtZuIy6tmE1f9i5o3bvAqpe/8W1Qh+bftgp3wIgNoRdT24aWtpKwMZK4iNZvAZuEfDbWLIjXtUUbcjauG0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIQDa6RbgdEA86mjP/IAsQVw7iBr6qV5hiZfbyiEc6EgXkAIgLkri//NLunE2mtLbWqcPK7zHdiwL47b1+SVklYZu4zw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@decimalturn%2ftoml-patch@3.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":247224,"size":73340,"noattachment":false,"key":"/@decimalturn/toml-patch/-/@decimalturn/toml-patch-3.2.0.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"},"./patch-lite":{"types":"./dist/patch-lite.d.ts","import":"./dist/patch-lite.js","default":"./dist/patch-lite.js"}},"scripts":{"dev":"pnpm run typecheck && pnpm run build && npm-run-all2 --parallel test:all specs","fuzz":"npx -y tsx scripts/fuzz-run.ts --seed 0 --to 9999 --mutations 3 --progress 100","lint":"oxlint","test":"vitest run","bench":"node benchmark/fixture-benchmark.mjs","build":"rimraf dist && tsdown","fuzz2":"npx -y tsx scripts/fuzz-run2.ts --seed 0 --to 9999 --mutations 3","fuzz3":"npx -y tsx scripts/fuzz-run3.ts --seed 0 --to 9999 --mutations 3","specs":"vitest run --config vitest.specs.config.ts","profile":"node benchmark/profile.mjs","test:go":"./run-toml-test.bash","test:js":"vitest run --config vitest.js.config.ts","lint:fix":"oxlint --fix","test:all":"pnpm run test && pnpm run test:js && pnpm run test:playwright","test:dev":"pnpm run build:dev && node scripts/test-dev-package.mjs","bench:all":"node benchmark/fixture-benchmark.mjs --all","benchmark":"npm-run-all2 bench:*","build:dev":"node scripts/prepare-dev-package.mjs","seed-toml":"npx -y tsx scripts/generate-seed-toml.ts","test:lite":"pnpm run build:lite && node scripts/test-lite-package.mjs","typecheck":"tsc","build:demo":"node scripts/build-demo.mjs","build:lite":"node scripts/prepare-lite-package.mjs","test:watch":"vitest","bench:parse":"node benchmark/parse-benchmark.mjs","bench:patch":"node benchmark/patch-benchmark.mjs","publish:jsr":"jsr publish --allow-dirty","test:output":"node scripts/test-debug.mjs","benchmark:ci":"npm-run-all2 \"bench:* -- --sample --versions latest\"","bench:stringify":"node benchmark/stringify-benchmark.mjs","check-overrides":"node scripts/check-overrides.mjs","test:playwright":"playwright test","bench:patch-lite":"node benchmark/patch-lite-bundle-size.mjs","bench:bundle-size":"node benchmark/bundle-size.mjs","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":{},"sideEffects":false,"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":{"scripts.bench":"Parse and stringify benchmark over the curated fixtures. Fails the CI job when toml-patch exceeds the maxSlowdown budgets in benchmark/thresholds.toml. Set BENCH_BASELINE to a build path to add the branch comparison.","scripts.bench:all":"Runs the same benchmark over every fixture in both corpora, including the single-type and scaling documents the curated set leaves out.","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.23.0","vitest":"^5.0.0","js-yaml":"4.3.2","benchmark":"^2","smol-toml":"^1.9.0","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.1.0"},"_npmOperationalInternal":{"tmp":"tmp/toml-patch_3.2.0_1790401543338_0.25339313274704134","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":1790401543809,"_cnpm_publish_time":1790401543809,"dist-tags":{"dev":"3.3.3-dev","latest":"3.3.3","lite":"3.3.3-lite"}}