@decimalturn/toml-patch 3.2.0 → 3.2.1-lite

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v3.2.1 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  function e(e){return e.type===`Document`}function t(e){return e.type===`Table`}function n(e){return e.type===`TableArray`}function r(e){return e.type===`KeyValue`}function i(e){return e.type===`String`}function a(e){return e.type===`Integer`}function o(e){return e.type===`Float`}function s(e){return e.type===`Boolean`}function c(e){return e.type===`DateTime`}function l(e){return e.type===`InlineArray`}function u(e){return e.type===`InlineItem`}function d(e){return e.type===`InlineTable`}function f(r){return e(r)||t(r)||n(r)||d(r)||l(r)}function p(e){return i(e)||a(e)||o(e)||s(e)||c(e)||l(e)||d(e)}let m,h;function g(e){if(m===e&&h!==void 0)return h;let t=te(e);return m=e,h=t,t}function ee(){m=void 0,h=void 0}function _(e,t){let n=Array.isArray(e)?e:te(e);if(n.length===0)return{line:1,column:t};let r=0,i=n.length-1;for(;r<i;){let e=r+i>>>1;n[e]<t?r=e+1:i=e}n[r]<t&&r++;let a=r+1;return{line:a,column:t-(n[a-2]+1||0)}}function v(e,t){let n=g(e),r=n[t.line-2]===void 0?0:n[t.line-2]+1,i=n[t.line-1]||e.length;return e.substring(r,i)}function te(e){let t=[];for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r===10?t.push(n):r===13&&(e.charCodeAt(n+1)===10?(t.push(n+1),n++):t.push(n))}return t.push(e.length),t}function y(e){return{line:e.line,column:e.column}}function ne(e){return{start:y(e.start),end:y(e.end)}}var b=class extends Error{line;column;constructor(e,t,n){let r=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){let n=v(e,t),i=`${re(t.column)}^`;n&&(r+=`${n}\n${i}\n`)}r+=n,super(r),this.line=t.line,this.column=t.column}};function re(e,t=` `){return t.repeat(e)}const ie=/[\w,\d,",',+,\-,_]/;function ae(){return{reference:null,mixed:!1}}function*oe(e,t){let n=e.length,r=0,i=t??ae(),a=[],o=(e,t)=>({start:_(a,e),end:_(a,t)});for(;r<n;){let t=e.charCodeAt(r);if((t<=31||t===127)&&t!==9&&t!==13&&t!==10)throw new b(e,_(a,r),`Control char 0x${t.toString(16).toUpperCase().padStart(2,`0`)} not allowed`);if(t===13&&(r+1>=n||e.charCodeAt(r+1)!==10))throw new b(e,_(a,r),`Standalone CR; must be CRLF or LF`);if(t!==32&&t!==9&&t!==13){if(t===10)s(r);else if(t===91||t===93)yield{type:`Bracket`,raw:e[r],loc:o(r,r+1)};else if(t===123||t===125)yield{type:`Curly`,raw:e[r],loc:o(r,r+1)};else if(t===61)yield{type:`Equal`,raw:`=`,loc:o(r,r+1)};else if(t===44)yield{type:`Comma`,raw:`,`,loc:o(r,r+1)};else if(t===46)yield{type:`Dot`,raw:`.`,loc:o(r,r+1)};else if(t===35)yield c();else{let t=se(e,r,`'`)||se(e,r,`"`);t?yield l(t):yield u()}}r++}function s(t){a.push(t);let n=t>0&&e.charCodeAt(t-1)===13?`\r
3
3
  `:`
4
4
  `;i.reference===null?i.reference=n:i.reference!==n&&(i.mixed=!0)}function c(){let t=r;for(;r+1<n;){let t=e.charCodeAt(r+1);if(t===10||t===13)break;r++;let n=e.charCodeAt(r);if((n<=31||n===127)&&n!==9)throw new b(e,_(a,r),`Control char 0x${n.toString(16).toUpperCase().padStart(2,`0`)} not allowed`)}return{type:`Comment`,raw:e.slice(t,r+1),loc:o(t,r+1)}}function l(t){let i=r,c=t+t+t;for(r+=3;r<n;){if(se(e,r,t)){let n=3;for(;e[r+n]===t;)n++;if(n>=6)throw new b(e,_(a,r),`Invalid multiline string: ${n} consecutive ${t} characters`);if(n===3){r+=2;break}r+=n-3,r+=2;break}let i=e.charCodeAt(r);if(i===13&&(r+1>=n||e.charCodeAt(r+1)!==10))throw new b(e,_(a,r),`Standalone CR in multiline string; must be CRLF or LF`);if((i<=31||i===127)&&i!==9&&i!==10&&i!==13){let n=t===`"`?`multiline basic strings`:`multiline literal strings`,o=`0x${i.toString(16).toUpperCase().padStart(2,`0`)}`,s=``;i===0?s=`Null`:i===127&&(s=`DEL`);let c=s?`${s} (${o}) not allowed in ${n}`:`Control char ${o} not allowed in ${n}`;throw new b(e,_(a,r),c)}i===10&&s(r),r++}if(r>=n){if(t===`"`){let t=0,i=n-1;for(;i>=0&&e[i]===`\\`;)t++,i--;if(t>0&&t%2!=0)throw new b(e,_(a,r),`Unterminated multiline ${c} (possible escape issue)`)}throw new b(e,_(a,r),`Unterminated multiline ${c}`)}return{type:`Literal`,raw:e.slice(i,r+1),loc:o(i,r+1)}}function u(){let t=e[r];if(!ie.test(t))throw new b(e,_(a,r),`Unexpected char "${t}"`);let i=r,s=t===`"`,c=t===`'`;for(;r<n&&!(r+1>=n);){let t=e.charCodeAt(r+1);if(!(s||c)&&(t===32||t===9||t===10||t===13||t===44||t===46||t===93||t===125||t===61||t===35))break;if(r++,!(s||c)){let t=e.charCodeAt(r);if(t<=31||t===127)throw new b(e,_(a,r),`Control char 0x${t.toString(16).toUpperCase().padStart(2,`0`)} not allowed in unquoted value`)}if(s||c){let t=e.charCodeAt(r);if((t<=31||t===127)&&t!==9){let n=s?`basic strings`:`literal strings`,i=`0x${t.toString(16).toUpperCase().padStart(2,`0`)}`,o=``;t===10?o=`Newline`:t===13?o=`Carriage return`:t===0?o=`Null`:t===127&&(o=`DEL`);let c=o?`${o} (${i}) not allowed in ${n}`:`Control char ${i} not allowed in ${n}`;throw new b(e,_(a,r),c)}}let i=e[r];if(i===`"`&&!c&&(s=!s),i===`'`&&!s&&(c=!c),r+1>=n)break;if(s&&i===`\\`){let t=e[r+1];(t===`"`||t===`\\`)&&r++}}if(s||c)throw new b(e,_(a,i),`Expected close of string with ${s?`"`:`'`}`);return{type:`Literal`,raw:e.slice(i,r+1),loc:o(i,r+1)}}}function se(e,t,n){if(!n||e[t]!==n||e[t+1]!==n||e[t+2]!==n)return!1;if(n===`'`)return n;let r=0,i=t-1;for(;i>=0&&e[i]===`\\`;)r++,i--;return(r===0||r%2==0)&&n}const x=new Int8Array(128);x.fill(-1);for(let e=0;e<10;e++)x[48+e]=e;for(let e=0;e<6;e++)x[65+e]=10+e,x[97+e]=10+e;function S(e){let t=e.charCodeAt(0);return t<128&&x[t]!==-1}function ce(e,t){return x[e.charCodeAt(t)]<<12|x[e.charCodeAt(t+1)]<<8|x[e.charCodeAt(t+2)]<<4|x[e.charCodeAt(t+3)]}function le(e){return e.startsWith(`'''`)?de(e.slice(3,e.length-3)):e.startsWith(`'`)?e.slice(1,e.length-1):e.startsWith(`"""`)?ue(de(e.slice(3,e.length-3)),!0):e.startsWith(`"`)?ue(e.slice(1,e.length-1),!1):e}function ue(e,t){let n=e.length;if(!t&&e.indexOf(`\\`)===-1)return e;let r=[],i=0;for(let a=0;a<n;a++){if(e[a]!==`\\`)continue;if(a>i&&r.push(e.slice(i,a)),a++,a>=n)throw Error(`Trailing backslash`);let o=e[a];switch(o){case`b`:r.push(`\b`);break;case`t`:r.push(` `);break;case`n`:r.push(`
package/package.json CHANGED
@@ -1,126 +1,30 @@
1
1
  {
2
2
  "name": "@decimalturn/toml-patch",
3
- "version": "3.2.0",
4
- "contributors": [
5
- "Tim Hall <tim.hall.engr@gmail.com>",
6
- "Martin Leduc <31558169+DecimalTurn@users.noreply.github.com>"
7
- ],
8
- "license": "MIT",
9
- "description": "Patch, parse, and stringify TOML while preserving comments, whitespace and formatting.",
3
+ "version": "3.2.1-lite",
4
+ "description": "Patch, parse, and stringify TOML while preserving comments, whitespace and formatting. Lite value-editing distribution.",
10
5
  "homepage": "https://github.com/DecimalTurn/toml-patch",
11
6
  "repository": {
12
7
  "type": "git",
13
8
  "url": "git+https://github.com/DecimalTurn/toml-patch.git"
14
9
  },
15
- "publishConfig": {
16
- "access": "public"
17
- },
18
- "keywords": [
19
- "toml",
20
- "patch",
21
- "edit",
22
- "parse",
23
- "stringify",
24
- "parser",
25
- "encoder",
26
- "decoder",
27
- "preserve-whitespace",
28
- "preserve-comments",
29
- "preserve-formatting",
30
- "edit-in-place"
31
- ],
10
+ "license": "MIT",
11
+ "type": "module",
32
12
  "engines": {
33
13
  "node": ">=16"
34
14
  },
35
- "type": "module",
36
15
  "sideEffects": false,
37
- "types": "./dist/toml-patch.d.ts",
38
- "exports": {
39
- ".": {
40
- "types": "./dist/toml-patch.d.ts",
41
- "import": "./dist/toml-patch.js",
42
- "default": "./dist/toml-patch.js"
43
- },
44
- "./patch-lite": {
45
- "types": "./dist/patch-lite.d.ts",
46
- "import": "./dist/patch-lite.js",
47
- "default": "./dist/patch-lite.js"
48
- }
49
- },
50
- "devDependencies": {
51
- "@decimalturn/toml-patch": "npm:@decimalturn/toml-patch@3.1.0",
52
- "@js-temporal/polyfill": "^0.5.1",
53
- "@playwright/test": "^1.59.1",
54
- "@types/dedent": "^0.7.2",
55
- "@types/js-yaml": "^4.0.0",
56
- "@types/node": "^24.12.3",
57
- "benchmark": "^2",
58
- "dedent": "^1.5.3",
59
- "glob": "^13.0.0",
60
- "js-yaml": "4.3.2",
61
- "jsr": "^0.14.0",
62
- "mri": "^1",
63
- "npm-run-all2": "^9.0.0",
64
- "oxlint": "^1.55.0",
65
- "rimraf": "^6.0.0",
66
- "smol-toml": "^1.9.0",
67
- "tsdown": "^0.23.0",
68
- "tslib": "^2.0.0",
69
- "typescript": "7.0.2",
70
- "vitest": "^5.0.0"
71
- },
72
- "prettier": {
73
- "singleQuote": true,
74
- "printWidth": 100
75
- },
16
+ "types": "./dist/patch.d.ts",
76
17
  "files": [
77
- "dist/*.js",
78
- "dist/*.d.ts"
18
+ "dist/"
79
19
  ],
80
- "json-comments": {
81
- "tips": "Please install the JsonComments plugin to enable commenting functionality for JSON files, see: https://github.com/zhangfisher/json_comments_extension",
82
- "package.json": {
83
- "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).",
84
- "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.",
85
- "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."
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/patch.d.ts",
23
+ "import": "./dist/patch.js",
24
+ "default": "./dist/patch.js"
86
25
  }
87
26
  },
88
- "scripts": {
89
- "dev": "pnpm run typecheck && pnpm run build && npm-run-all2 --parallel test:all specs",
90
- "test": "vitest run",
91
- "test:output": "node scripts/test-debug.mjs",
92
- "test:js": "vitest run --config vitest.js.config.ts",
93
- "test:watch": "vitest",
94
- "test:go": "./run-toml-test.bash",
95
- "test:playwright": "playwright test",
96
- "playwright:install": "playwright install --with-deps chromium",
97
- "test:all": "pnpm run test && pnpm run test:js && pnpm run test:playwright",
98
- "typecheck": "tsc",
99
- "specs": "vitest run --config vitest.specs.config.ts",
100
- "bench": "node benchmark/fixture-benchmark.mjs",
101
- "bench:all": "node benchmark/fixture-benchmark.mjs --all",
102
- "benchmark": "npm-run-all2 bench:*",
103
- "benchmark:ci": "npm-run-all2 \"bench:* -- --sample --versions latest\"",
104
- "seed-toml": "npx -y tsx scripts/generate-seed-toml.ts",
105
- "fuzz": "npx -y tsx scripts/fuzz-run.ts --seed 0 --to 9999 --mutations 3 --progress 100",
106
- "fuzz2": "npx -y tsx scripts/fuzz-run2.ts --seed 0 --to 9999 --mutations 3",
107
- "fuzz3": "npx -y tsx scripts/fuzz-run3.ts --seed 0 --to 9999 --mutations 3",
108
- "bench:bundle-size": "node benchmark/bundle-size.mjs",
109
- "bench:parse": "node benchmark/parse-benchmark.mjs",
110
- "bench:stringify": "node benchmark/stringify-benchmark.mjs",
111
- "bench:patch": "node benchmark/patch-benchmark.mjs",
112
- "bench:patch-lite": "node benchmark/patch-lite-bundle-size.mjs",
113
- "profile": "node benchmark/profile.mjs",
114
- "build": "rimraf dist && tsdown",
115
- "build:demo": "node scripts/build-demo.mjs",
116
- "build:dev": "node scripts/prepare-dev-package.mjs",
117
- "build:lite": "node scripts/prepare-lite-package.mjs",
118
- "test:dev": "pnpm run build:dev && node scripts/test-dev-package.mjs",
119
- "test:lite": "pnpm run build:lite && node scripts/test-lite-package.mjs",
120
- "lint": "oxlint",
121
- "lint:fix": "oxlint --fix",
122
- "check-overrides": "node scripts/check-overrides.mjs",
123
- "compare-branch-size": "node scripts/compare-branch-size.mjs",
124
- "publish:jsr": "jsr publish --allow-dirty"
27
+ "publishConfig": {
28
+ "access": "public"
125
29
  }
126
- }
30
+ }
package/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2019–2025 Tim Hall
4
- Copyright (c) 2025 Martin Leduc
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
package/README.md DELETED
@@ -1,200 +0,0 @@
1
- <img src="assets/toml-patch-logo.png" alt="toml-patch logo" width="120"/>
2
-
3
- # toml-patch
4
-
5
- [![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)
6
- [![JSR Version](https://img.shields.io/jsr/v/%40decimalturn/toml-patch?logo=jsr&color=blue)](https://jsr.io/@decimalturn/toml-patch)
7
- [![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)
8
-
9
- Patch, parse, and stringify [TOML](https://toml.io/en/) (v1.1.0) while preserving comments, whitespace and formatting.
10
-
11
- This 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).
12
-
13
- We 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.
14
-
15
- ## Documentation
16
-
17
- - [Installation](#installation)
18
- - [API](#api)
19
- - [Patch-lite](#patch-lite)
20
- - [Comment ownership](#comment-ownership)
21
- - [Date/time handling and Temporal](#datetime-handling--temporal)
22
- - [Formatting](#formatting)
23
- - [Changelog](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/CHANGELOG.md)
24
- - [Contributing](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/CONTRIBUTING.md)
25
- - [MIT License](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/LICENSE)
26
-
27
- ## Installation
28
-
29
- toml-patch is dependency-free and can be installed via your favorite package manager.
30
-
31
- *Example with NPM*
32
-
33
- ```
34
- $ npm install --save @decimalturn/toml-patch
35
- ```
36
-
37
- For the standalone lite distribution, install the `lite` npm dist-tag:
38
-
39
- ```sh
40
- $ npm install --save @decimalturn/toml-patch@lite
41
- ```
42
-
43
- For browser usage, you can use unpkg:
44
-
45
- ```html
46
- <script type="module">
47
- import * as TOML from 'https://unpkg.com/@decimalturn/toml-patch@v3.2.0/dist/toml-patch.js';
48
- </script>
49
- ```
50
-
51
- ## API
52
-
53
- overwrite(tomlString: string): void
54
- toml-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.
55
-
56
- See the [API reference](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/docs/API.md) for `patch`, `parse`, `stringify` and the `TomlDocument` class.
57
-
58
- For a quick start, patch an existing TOML string like this:
59
-
60
- ```js
61
- import { patch } from '@decimalturn/toml-patch';
62
-
63
- const existing = 'title = "TOML example"\nowner.name = "Bob"\n';
64
- const updated = patch(existing, {
65
- title: 'TOML example',
66
- owner: { name: 'Tim' }
67
- });
68
- ```
69
-
70
- ## Patch-lite
71
-
72
- The `patch-lite` subpath 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:
73
-
74
- ```js
75
- import { patch } from '@decimalturn/toml-patch/patch-lite';
76
-
77
- const existing = 'version = "1.0.0"\n';
78
- const updated = patch(existing, { version: '1.0.1' });
79
- // updated === 'version = "1.0.1"\n'
80
- ```
81
-
82
- The 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. Use the full `patch()` for additions, removals, moves, renames and advanced formatting.
83
-
84
- Unlike 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.
85
-
86
- The [Patch-lite guide](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/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.
87
-
88
- The lite distribution is also published as a standalone package under the `lite` npm dist-tag:
89
-
90
- ```sh
91
- npm install @decimalturn/toml-patch@lite
92
- ```
93
-
94
- ## Comment Ownership
95
-
96
- When `patch()` removes or reorders an entry, any comment describing it (a same-line trailing
97
- comment, or a line-comment directly above with no blank line in between) travels along with
98
- it, instead of being left behind to describe whatever ends up in that spot. This applies to root
99
- keys, `[table]`/`[[array-of-tables]]` blocks, and elements inside multi-line arrays and inline
100
- tables.
101
-
102
- ```js
103
- import * as TOML from '@decimalturn/toml-patch';
104
- import { strict as assert } from 'assert';
105
-
106
- const existing = `
107
- x = 1 # a note about x
108
- y = 2
109
- `;
110
-
111
- const patched = TOML.patch(existing, { y: 2 });
112
-
113
- assert.strictEqual(patched, `
114
- y = 2
115
- `);
116
- ```
117
-
118
- See the [comment ownership guide](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/docs/Comment-Ownership.md) for the full behavior, including how a blank line opts a comment out of ownership and current scope limitations.
119
-
120
- Note that `patch()` does not reorder entries by default.
121
- To 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.2.0/docs/Formatting.md#updateorder).
122
-
123
- ## Date/Time Handling & Temporal
124
-
125
- TOML 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.
126
-
127
- ### Enabling Temporal
128
-
129
- The `temporal: true` option requires `Temporal` to be available in the runtime:
130
-
131
- | Runtime | How to enable |
132
- |---|---|
133
- | **Node.js 26+** | Built-in — enable with `temporal: true` |
134
- | **Node.js 20–24** | `node --harmony-temporal` flag |
135
- | **Node.js 14–26** | [@js-temporal/polyfill](https://www.npmjs.com/package/@js-temporal/polyfill) |
136
-
137
- ```js
138
- import * as TOML from '@decimalturn/toml-patch';
139
-
140
- // Node 26+ (native) or Node 20–24 with --harmony-temporal:
141
- const obj = TOML.parse('d = 2024-01-15\n', { temporal: true });
142
- // obj.d → Temporal.PlainDate
143
-
144
- // All Node versions with the polyfill:
145
- import { Temporal } from '@js-temporal/polyfill';
146
- globalThis.Temporal = Temporal;
147
- const obj2 = TOML.parse('d = 2024-01-15\n', { temporal: true });
148
- // obj2.d → PlainDate (polyfill)
149
- ```
150
-
151
- > **Note:** Only offset-based timezones (`+05:30`, `Z`) are supported in TOML. IANA timezone annotations (e.g., `[Asia/Kolkata]`) will throw an error.
152
-
153
- See the [date/time guide](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/docs/Dates.md) for details and examples.
154
-
155
- ## Formatting
156
-
157
- The `TomlFormat` class controls how TOML documents are formatted during stringification and patching operations.
158
-
159
- ```typescript
160
- class TomlFormat {
161
- newLine: string
162
- trailingNewline: number
163
- trailingComma: boolean
164
- bracketSpacing: boolean
165
- inlineTableStart?: number
166
- truncateZeroTimeInDates: boolean
167
- useTabsForIndentation?: boolean
168
- indentWidth: number
169
- minimumDecimals?: number
170
- leadingBom: boolean
171
- updateOrder?: boolean
172
- multilineTable: boolean | number | 'auto' | 'parent'
173
- multilineArray: boolean | number | 'auto' | 'parent'
174
-
175
- static default(): TomlFormat
176
- static autoDetectFormat(tomlString: string): TomlFormat
177
- }
178
- ```
179
-
180
- Start with `TomlFormat.default()` and override the options you need. e.g.:
181
-
182
- ```js
183
- import { stringify, TomlFormat } from '@decimalturn/toml-patch';
184
-
185
- const format = TomlFormat.default();
186
- format.newLine = '\r\n';
187
- format.trailingNewline = 0;
188
- format.trailingComma = true;
189
- format.bracketSpacing = false;
190
- format.indentWidth = 4;
191
- format.multilineTable = 'parent';
192
-
193
- const toml = stringify({
194
- title: 'My App',
195
- tags: ['dev', 'config'],
196
- database: { host: 'localhost', port: 5432 }
197
- }, format);
198
-
199
- ```
200
- See the [formatting reference](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/docs/Formatting.md) for the complete list of options, auto-detection behavior, `updateOrder` and more examples.