{"name":"@decimalturn/toml-patch","version":"0.3.7","keywords":["toml","patch","parse","stringify","parser","encoder","decoder"],"license":"MIT","_id":"@decimalturn/toml-patch@0.3.7","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","dist":{"shasum":"3767d763137d81b2169e5c80da27a66fd1cea9f5","tarball":"http://registry-npm.ywwl.com/@decimalturn/toml-patch/download/@decimalturn/toml-patch-0.3.7.tgz","fileCount":9,"integrity":"sha512-AzBw8XGOfTASzpypq3E0M/jW9/XGz9h879SuEYvzsB8f3xSUvYLABkoDgbLq7jsLCNrxqyRd10Ffxu/ndkMZaw==","signatures":[{"sig":"MEQCICKk7+P7MW2cbmSTfLw2LtaBnmJ7/eIUsAaQ4eYl0MnHAiBh15WhUukazZcuD+cuO9t7FWDzhiwF1RpBGtstagRREg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":455506,"size":117932,"noattachment":false,"key":"/@decimalturn/toml-patch/-/@decimalturn/toml-patch-0.3.7.tgz"},"jest":{"preset":"ts-jest","testRegex":"/__tests__/.*\\.[jt]sx?$","snapshotFormat":{"escapeString":true,"printBasicPrototype":true},"testEnvironment":"node"},"main":"dist/toml-patch.cjs.min.js","types":"dist/toml-patch.d.ts","module":"dist/toml-patch.es.js","browser":"dist/toml-patch.umd.min.js","gitHead":"f6cb9266fcc83f42b2b439b090801b8952e0abb3","scripts":{"test":"jest","build":"rimraf dist && rollup -c","specs":"jest --config specs.config.js","benchmark":"node benchmark/index.js","typecheck":"tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"decimalturn","email":"leducma@live.ca"},"prettier":{"printWidth":100,"singleQuote":true},"_npmVersion":"10.9.3","description":"Patch, parse, and stringify TOML while preserving comments.","directories":{},"_nodeVersion":"22.18.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"mri":"^1","glob":"^11.0.0","jest":"^29.7.0","tslib":"^2.0.0","dedent":"^1.5.3","rimraf":"^6.0.0","rollup":"^4.38.0","js-yaml":"^3","ts-jest":"^29","benchmark":"^2","typescript":"5.8","@types/glob":"^9.0.0","@types/jest":"^29.0.0","npm-run-all2":"^8.0.0","@types/dedent":"^0.7.2","@types/js-yaml":"^3","rollup-plugin-dts":"^6.2.1","@rollup/plugin-terser":"^0.4.4","rollup-plugin-filesize":"^10","@rollup/plugin-typescript":"^12.1.2"},"_npmOperationalInternal":{"tmp":"tmp/toml-patch_0.3.7_1755659359117_0.4749400393460197","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":1755659359430,"_cnpm_publish_time":1755659359430,"dist-tags":{"dev":"3.3.3-dev","latest":"3.3.3","lite":"3.3.3-lite"}}