@decimalturn/toml-patch 3.3.2-lite → 3.3.3-dev

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.
Files changed (81) hide show
  1. package/dist/dev/comment-alignment.js +371 -0
  2. package/dist/dev/comment-alignment.js.map +1 -0
  3. package/dist/dev/comment-ownership.js +672 -0
  4. package/dist/dev/comment-ownership.js.map +1 -0
  5. package/dist/dev/cst-source.js +117 -0
  6. package/dist/dev/cst-source.js.map +1 -0
  7. package/dist/dev/cst.js +67 -0
  8. package/dist/dev/cst.js.map +1 -0
  9. package/dist/dev/cursor.js +65 -0
  10. package/dist/dev/cursor.js.map +1 -0
  11. package/dist/dev/date-format.js +286 -0
  12. package/dist/dev/date-format.js.map +1 -0
  13. package/dist/dev/decode-utf8.js +26 -0
  14. package/dist/dev/decode-utf8.js.map +1 -0
  15. package/dist/dev/diff-lite.js +107 -0
  16. package/dist/dev/diff-lite.js.map +1 -0
  17. package/dist/dev/diff.js +264 -0
  18. package/dist/dev/diff.js.map +1 -0
  19. package/dist/dev/encode-lite.js +209 -0
  20. package/dist/dev/encode-lite.js.map +1 -0
  21. package/dist/dev/escape-preference.js +165 -0
  22. package/dist/dev/escape-preference.js.map +1 -0
  23. package/dist/dev/find-by-path.js +114 -0
  24. package/dist/dev/find-by-path.js.map +1 -0
  25. package/dist/dev/formatter.js +297 -0
  26. package/dist/dev/formatter.js.map +1 -0
  27. package/dist/dev/generate.js +479 -0
  28. package/dist/dev/generate.js.map +1 -0
  29. package/dist/dev/inline-comma-space.js +12 -0
  30. package/dist/dev/inline-comma-space.js.map +1 -0
  31. package/dist/dev/inline-format.js +105 -0
  32. package/dist/dev/inline-format.js.map +1 -0
  33. package/dist/dev/inline-layout.js +106 -0
  34. package/dist/dev/inline-layout.js.map +1 -0
  35. package/dist/dev/line-ending-backslash.js +319 -0
  36. package/dist/dev/line-ending-backslash.js.map +1 -0
  37. package/dist/dev/literal-string.js +45 -0
  38. package/dist/dev/literal-string.js.map +1 -0
  39. package/dist/dev/location.js +103 -0
  40. package/dist/dev/location.js.map +1 -0
  41. package/dist/dev/parse-error.js +26 -0
  42. package/dist/dev/parse-error.js.map +1 -0
  43. package/dist/dev/parse-js.js +149 -0
  44. package/dist/dev/parse-js.js.map +1 -0
  45. package/dist/dev/parse-string.js +119 -0
  46. package/dist/dev/parse-string.js.map +1 -0
  47. package/dist/dev/parse-toml.js +713 -0
  48. package/dist/dev/parse-toml.js.map +1 -0
  49. package/dist/dev/patch-lite.js +4 -0
  50. package/dist/dev/patch-lite2.js +96 -0
  51. package/dist/dev/patch-lite2.js.map +1 -0
  52. package/dist/dev/patch.js +3143 -0
  53. package/dist/dev/patch.js.map +1 -0
  54. package/dist/dev/smol-toml-date.js +60 -0
  55. package/dist/dev/smol-toml-date.js.map +1 -0
  56. package/dist/dev/to-js.js +307 -0
  57. package/dist/dev/to-js.js.map +1 -0
  58. package/dist/dev/to-toml.js +873 -0
  59. package/dist/dev/to-toml.js.map +1 -0
  60. package/dist/dev/tokenizer.js +224 -0
  61. package/dist/dev/tokenizer.js.map +1 -0
  62. package/dist/dev/toml-document.js +220 -0
  63. package/dist/dev/toml-document.js.map +1 -0
  64. package/dist/dev/toml-format.js +548 -0
  65. package/dist/dev/toml-format.js.map +1 -0
  66. package/dist/dev/toml-patch.js +93 -0
  67. package/dist/dev/toml-patch.js.map +1 -0
  68. package/dist/dev/traverse.js +60 -0
  69. package/dist/dev/traverse.js.map +1 -0
  70. package/dist/dev/truncate.js +63 -0
  71. package/dist/dev/truncate.js.map +1 -0
  72. package/dist/dev/update-order.js +234 -0
  73. package/dist/dev/update-order.js.map +1 -0
  74. package/dist/dev/utils.js +295 -0
  75. package/dist/dev/utils.js.map +1 -0
  76. package/dist/dev/writer.js +757 -0
  77. package/dist/dev/writer.js.map +1 -0
  78. package/dist/{patch.d.ts → patch-lite.d.ts} +0 -2
  79. package/dist/toml-patch.d.ts +548 -0
  80. package/package.json +11 -6
  81. package/dist/patch.js +0 -20
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toml-document.js","names":[],"sources":["../../src/toml-document.ts"],"sourcesContent":["import parseTOML, { continueParsingTOML } from './parse-toml';\nimport toJS from './to-js';\nimport { TomlFormat } from './toml-format';\nimport { Block } from './cst';\nimport { patchCst } from './patch';\nimport { attachSources } from './cst-source';\nimport { detectNewline, resolveTomlFormat } from './toml-format';\nimport { truncateCst } from './truncate';\nimport type { ParseOptions, IntegersAsBigInt } from './parse-options';\nimport { decodeUtf8Bytes, hasLeadingBom, stripLeadingBom, UTF8_BOM } from './decode-utf8';\nimport { isObject } from './utils';\n\n/**\n * TomlDocument encapsulates a TOML CST and provides methods to interact with it.\n */\nexport class TomlDocument {\n private _cst: Block[];\n private _currentTomlString: string;\n private _format: TomlFormat;\n private _integersAsBigInt: IntegersAsBigInt;\n private _temporal: boolean;\n\n /**\n * Initializes the TomlDocument with TOML source, parsing it into a CST.\n *\n * When bytes are provided, they are decoded as UTF-8 in fatal mode.\n * This rejects invalid UTF-8 sequences before parsing.\n *\n * @param tomlSource - The TOML source to parse (string or raw UTF-8 bytes)\n * @param options - Optional parse options\n * @param options.integersAsBigInt - Controls bigint vs number for TOML integers\n * @param options.temporal - When true, returns Temporal objects for date/time values\n */\n constructor(tomlSource: string | Uint8Array, options?: ParseOptions) {\n const sourceString = typeof tomlSource === 'string'\n ? tomlSource\n : decodeUtf8Bytes(tomlSource);\n const tomlString = stripLeadingBom(sourceString);\n\n this._currentTomlString = tomlString;\n this._cst = Array.from(parseTOML(tomlString));\n this._integersAsBigInt = options?.integersAsBigInt ?? 'asNeeded';\n this._temporal = options?.temporal ?? false;\n // Auto-detect formatting preferences from the original TOML string\n this._format = TomlFormat.autoDetectFormatWithCst(sourceString, this._cst);\n }\n\n get toTomlString(): string {\n return this._format.leadingBom ? `${UTF8_BOM}${this._currentTomlString}` : this._currentTomlString;\n }\n\n /**\n * Returns the JavaScript object representation of the TOML document.\n */\n get toJsObject(): any {\n const jsObject = toJS(this._cst, this._currentTomlString, {\n integersAsBigInt: this._integersAsBigInt,\n temporal: this._temporal\n });\n // When temporal is enabled, Temporal objects are already returned — no conversion needed.\n // When temporal is disabled, convert custom date classes to regular JavaScript Date objects.\n if (this._temporal) {\n return jsObject;\n }\n return convertCustomDateClasses(jsObject);\n }\n\n /**\n * Returns the internal CST (for testing purposes).\n * @internal\n */\n get cst(): Block[] {\n return this._cst;\n }\n\n /**\n * Applies a patch to the current CST using a modified JS object.\n * Updates the internal CST. Use toTomlString getter to retrieve the updated TOML string.\n *\n * @param updatedObject - The modified JS object to patch with\n * @param format - Optional formatting options\n */\n patch(updatedObject: any, format?: Partial<TomlFormat> | TomlFormat) : void {\n\n const fmt = resolveTomlFormat(format, this._format);\n\n const sourceBefore = this._currentTomlString;\n\n // Only worth deriving the pre-patch values when a stripped date could\n // actually be present; temporal mode hands out Temporal objects untouched.\n if (!this._temporal && hasPlainDate(updatedObject)) {\n const originalObject = toJS(this._cst, sourceBefore, {\n integersAsBigInt: this._integersAsBigInt,\n temporal: false\n });\n updatedObject = restoreDateRepresentations(updatedObject, originalObject);\n }\n\n const indentWidthExplicit = format instanceof TomlFormat ||\n (format != null && Object.prototype.hasOwnProperty.call(format, 'indentWidth'));\n const trailingCommaExplicit = format instanceof TomlFormat ||\n (format != null && Object.prototype.hasOwnProperty.call(format, 'trailingComma'));\n const inlineTableStartExplicit = format instanceof TomlFormat ||\n (format != null && Object.prototype.hasOwnProperty.call(format, 'inlineTableStart'));\n attachSources(this._cst, sourceBefore);\n const result = patchCst(\n this._cst,\n updatedObject,\n fmt,\n indentWidthExplicit,\n trailingCommaExplicit,\n inlineTableStartExplicit\n );\n this._cst = Array.from(parseTOML(result.tomlString));\n this._format = fmt;\n this._currentTomlString = result.tomlString;\n }\n\n /**\n * Updates the internal document by supplying a modified tomlString.\n * Use toJsObject getter to retrieve the updated JS object representation.\n * @param tomlString - The modified TOML string to update with\n */\n update(tomlString: string): void {\n const tomlContent = stripLeadingBom(tomlString);\n\n if (tomlContent === this._currentTomlString) {\n this._format.leadingBom = hasLeadingBom(tomlString);\n return;\n }\n\n // Now, let's check where the first difference is\n const existingLines = this._currentTomlString.split(this._format.newLine);\n const newLineChar = detectNewline(tomlContent);\n const newTextLines = tomlContent.split(newLineChar);\n let firstDiffLineIndex = 0;\n while (\n firstDiffLineIndex < existingLines.length &&\n firstDiffLineIndex < newTextLines.length &&\n existingLines[firstDiffLineIndex] === newTextLines[firstDiffLineIndex]\n ) {\n firstDiffLineIndex++;\n }\n\n // Calculate the 1-based line number and 0-based column where the first difference occurs\n \n let firstDiffColumn = 0;\n \n // If we're within the bounds of both arrays, find the column where they differ\n if (firstDiffLineIndex < existingLines.length && firstDiffLineIndex < newTextLines.length) {\n const existingLine = existingLines[firstDiffLineIndex];\n const newLine = newTextLines[firstDiffLineIndex];\n \n // Find the first character position where the lines differ\n for (let i = 0; i < Math.max(existingLine.length, newLine.length); i++) {\n if (existingLine[i] !== newLine[i]) {\n firstDiffColumn = i;\n break;\n }\n }\n }\n\n let firstDiffLine = firstDiffLineIndex + 1; // Convert to 1-based\n const { truncatedCst, lastEndPosition } = truncateCst(this._cst, firstDiffLine, firstDiffColumn);\n\n // Determine where to continue parsing from in the new string\n // If lastEndPosition exists, continue from there; otherwise from the start of the document\n const continueFromLine = lastEndPosition ? lastEndPosition.line : 1;\n const continueFromColumn = lastEndPosition ? lastEndPosition.column + 1 : 0;\n\n // Based on the first difference, we can re-parse only the affected part\n // We will need to supply the remaining string after where the CST was truncated\n const remainingLines = newTextLines.slice(continueFromLine - 1);\n \n // If there's a partial line match, we need to extract only the part after the continuation column\n if (remainingLines.length > 0 && continueFromColumn > 0) {\n remainingLines[0] = remainingLines[0].substring(continueFromColumn);\n }\n \n const remainingToml = remainingLines.join(this._format.newLine);\n \n this._cst = Array.from(continueParsingTOML(truncatedCst, remainingToml, {\n line: continueFromLine,\n column: continueFromColumn\n }));\n this._currentTomlString = tomlContent;\n \n // Update the auto-detected format with the new string's characteristics\n this._format = TomlFormat.autoDetectFormatWithCst(tomlString, this._cst);\n }\n\n /**\n * Overwrites the internal syntax tree by fully re-parsing the supplied tomlString.\n * This is simpler but slower than update() which uses incremental parsing.\n * @param tomlString - The TOML string to overwrite with\n */\n overwrite(tomlString: string): void {\n const tomlContent = stripLeadingBom(tomlString);\n\n if (tomlContent === this._currentTomlString) {\n this._format.leadingBom = hasLeadingBom(tomlString);\n return;\n }\n\n // Re-parse the entire document\n this._cst = Array.from(parseTOML(tomlContent));\n this._currentTomlString = tomlContent;\n \n // Update the auto-detected format with the new string's characteristics\n this._format = TomlFormat.autoDetectFormatWithCst(tomlString, this._cst);\n }\n}\n\n/**\n * True when `value` holds a plain `Date` anywhere, i.e. one of the objects\n * toJsObject() produced by stripping a TOML date class. Used to skip the work\n * in restoreDateRepresentations() for the common case of a document with no\n * dates in it. Cycle-safe.\n */\nfunction hasPlainDate(value: any, seen: WeakSet<object> = new WeakSet()): boolean {\n if (value instanceof Date) return value.constructor === Date;\n if (!value || typeof value !== 'object') return false;\n if (seen.has(value)) return false;\n seen.add(value);\n if (Array.isArray(value)) return value.some(item => hasPlainDate(item, seen));\n return Object.keys(value).some(key => hasPlainDate(value[key], seen));\n}\n\n/**\n * Re-attaches the TOML date representation that toJsObject() strips.\n *\n * toJsObject() deliberately hands out plain `Date` objects so that callers get\n * the standard Date contract, notably a standard toISOString(). But the writer\n * derives a value's TOML text from toISOString(), and the TOML date classes\n * override it to return the original spelling. A plain Date handed back in\n * therefore writes as a full offset date-time, so read-modify-write turned\n * `1986-03-02` into `1986-03-02T00:00:00.000Z` whenever the surrounding node was\n * rewritten rather than preserved from the CST.\n *\n * Where the caller left a date alone (still a plain Date, same instant), the\n * original typed instance goes back in so the original spelling is written. A\n * date whose instant actually changed is left as-is: only the caller knows\n * whether a new instant is still meant to be a local date, and they can say so\n * by passing LocalDate / LocalTime / LocalDateTime / OffsetDateTime, which are\n * exported for that purpose. Instances of those classes are never touched.\n *\n * The caller's object is not mutated; a node is copied only when something\n * beneath it changed, so an untouched tree is returned by reference.\n */\nfunction restoreDateRepresentations(updated: any, original: any, seen: WeakSet<object> = new WeakSet()): any {\n if (updated instanceof Date) {\n const erased = updated.constructor === Date\n && original instanceof Date\n && original.constructor !== Date\n && original.getTime() === updated.getTime();\n return erased ? original : updated;\n }\n if (!updated || typeof updated !== 'object' || seen.has(updated)) return updated;\n seen.add(updated);\n\n if (Array.isArray(updated)) {\n if (!Array.isArray(original)) return updated;\n let changed = false;\n const restored = updated.map((item, index) => {\n const next = restoreDateRepresentations(item, original[index], seen);\n if (next !== item) changed = true;\n return next;\n });\n return changed ? restored : updated;\n }\n\n if (!isObject(original)) return updated;\n let changed = false;\n const restored: Record<string, any> = {};\n for (const key of Object.keys(updated)) {\n const value = updated[key];\n const next = restoreDateRepresentations(value, original[key], seen);\n restored[key] = next;\n if (next !== value) changed = true;\n }\n return changed ? restored : updated;\n}\n\n/**\n * Recursively converts custom date classes to regular JavaScript Date objects.\n * This ensures that the toJsObject property returns standard Date objects\n * while preserving the custom classes internally for TOML formatting.\n */\nfunction convertCustomDateClasses(obj: any): any {\n if (obj instanceof Date) {\n // Convert custom date classes to regular Date objects\n return new Date(obj.getTime());\n } else if (Array.isArray(obj)) {\n return obj.map(convertCustomDateClasses);\n } else if (obj && typeof obj === 'object') {\n const result: any = {};\n for (const [key, value] of Object.entries(obj)) {\n result[key] = convertCustomDateClasses(value);\n }\n return result;\n }\n return obj;\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,IAAa,eAAb,MAA0B;CAChB;CACA;CACA;CACA;CACA;;;;;;;;;;;;CAaR,YAAY,YAAiC,SAAwB;EACnE,MAAM,eAAe,OAAO,eAAe,WACvC,aACA,gBAAgB,UAAU;EAC9B,MAAM,aAAa,gBAAgB,YAAY;EAE/C,KAAK,qBAAqB;EAC1B,KAAK,OAAO,MAAM,KAAK,UAAU,UAAU,CAAC;EAC5C,KAAK,uEAAoB,QAAS,qBAAoB;EACtD,KAAK,+DAA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vC,KAAK,MAAM,OAAO,OAAO,KAAK,OAAO,GAAG;EACtC,MAAM,QAAQ,QAAQ;EACtB,MAAM,OAAO,2BAA2B,OAAO,SAAS,MAAM,IAAI;EAClE,SAAS,OAAO;EAChB,IAAI,SAAS,OAAO,UAAU;CAChC;CACA,OAAO,UAAU,WAAW;AAC9B;;;;;;AAOA,SAAS,yBAAyB,KAAe;CAC/C,IAAI,eAAe,MAEjB,OAAO,IAAI,KAAK,IAAI,QAAQ,CAAC;MACxB,IAAI,MAAM,QAAQ,GAAG,GAC1B,OAAO,IAAI,IAAI,wBAAwB;MAClC,IAAI,OAAO,OAAO,QAAQ,UAAU;EACzC,MAAM,SAAc,CAAC;EACrB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,GAAG,GAC3C,OAAO,OAAO,yBAAyB,KAAK;EAE9C,OAAO;CACT;CACA,OAAO;AACT"}
@@ -0,0 +1,548 @@
1
+ //! @decimalturn/toml-patch v3.3.3 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ import { hasLeadingBom, stripLeadingBom } from "./decode-utf8.js";
3
+ import parseTOML from "./parse-toml.js";
4
+
5
+ // src/toml-format.ts
6
+ const DEFAULT_NEWLINE = "\n";
7
+ const DEFAULT_TRAILING_NEWLINE = 1;
8
+ const DEFAULT_TRAILING_COMMA = false;
9
+ const DEFAULT_BRACKET_SPACING = true;
10
+ const DEFAULT_INLINE_TABLE_START = 1;
11
+ const DEFAULT_TRUNCATE_ZERO_TIME_IN_DATES = false;
12
+ const DEFAULT_USE_TABS_FOR_INDENTATION = false;
13
+ const DEFAULT_INDENT_WIDTH = 2;
14
+ const DEFAULT_MINIMUM_DECIMALS = 0;
15
+ const DEFAULT_MINIMUM_TIME_DECIMALS = 0;
16
+ const DEFAULT_LEADING_BOM = false;
17
+ const DEFAULT_UPDATE_ORDER = false;
18
+ const DEFAULT_MULTILINE_TABLE = "auto";
19
+ const DEFAULT_MULTILINE_ARRAY = "auto";
20
+ const DEFAULT_ESCAPE_SEQUENCE_UPPER_CASE = true;
21
+ function detectTrailingComma(cst) {
22
+ for (const item of cst) {
23
+ const result = findTrailingCommaInNode(item);
24
+ if (result !== null) return result;
25
+ }
26
+ return false;
27
+ }
28
+ function detectBracketSpacing(tomlString, cst) {
29
+ for (const item of cst) {
30
+ const result = findBracketSpacingInNode(item, tomlString);
31
+ if (result !== null) return result;
32
+ }
33
+ return true;
34
+ }
35
+ function findBracketSpacingInNode(node, tomlString) {
36
+ if (!node || typeof node !== "object") return null;
37
+ if ((node.type === "InlineArray" || node.type === "InlineTable") && node.loc) {
38
+ const bracketSpacing = checkBracketSpacingInLocation(node.loc, tomlString);
39
+ if (bracketSpacing !== null) return bracketSpacing;
40
+ }
41
+ if (node.items && Array.isArray(node.items)) for (const child of node.items) {
42
+ const result = findBracketSpacingInNode(child, tomlString);
43
+ if (result !== null) return result;
44
+ if (child.item) {
45
+ const nestedResult = findBracketSpacingInNode(child.item, tomlString);
46
+ if (nestedResult !== null) return nestedResult;
47
+ }
48
+ }
49
+ for (const prop of [
50
+ "value",
51
+ "key",
52
+ "item"
53
+ ]) if (node[prop]) {
54
+ const result = findBracketSpacingInNode(node[prop], tomlString);
55
+ if (result !== null) return result;
56
+ }
57
+ return null;
58
+ }
59
+ function checkBracketSpacingInLocation(loc, tomlString) {
60
+ if (!loc || !loc.start || !loc.end) return null;
61
+ const lines = tomlString.split(/\r?\n/);
62
+ const startLine = loc.start.line - 1;
63
+ const endLine = loc.end.line - 1;
64
+ const startCol = loc.start.column;
65
+ const endCol = loc.end.column;
66
+ let rawText = "";
67
+ if (startLine === endLine) {
68
+ var _lines$startLine;
69
+ rawText = ((_lines$startLine = lines[startLine]) === null || _lines$startLine === void 0 ? void 0 : _lines$startLine.substring(startCol, endCol + 1)) || "";
70
+ } else {
71
+ if (lines[startLine]) rawText += lines[startLine].substring(startCol);
72
+ for (let i = startLine + 1; i < endLine; i++) rawText += "\n" + (lines[i] || "");
73
+ if (lines[endLine]) rawText += "\n" + lines[endLine].substring(0, endCol + 1);
74
+ }
75
+ const arrayMatch = rawText.match(/^\[(\s*)/);
76
+ const tableMatch = rawText.match(/^\{(\s*)/);
77
+ if (arrayMatch) return arrayMatch[1].length > 0;
78
+ if (tableMatch) return tableMatch[1].length > 0;
79
+ return null;
80
+ }
81
+ function findTrailingCommaInNode(node) {
82
+ if (!node || typeof node !== "object") return null;
83
+ if (node.type === "InlineArray" && node.items && Array.isArray(node.items)) return checkTrailingCommaInItems(node.items);
84
+ if (node.type === "InlineTable" && node.items && Array.isArray(node.items)) return checkTrailingCommaInItems(node.items);
85
+ if (node.type === "KeyValue" && node.value) return findTrailingCommaInNode(node.value);
86
+ if (node.items && Array.isArray(node.items)) for (const item of node.items) {
87
+ const result = findTrailingCommaInNode(item);
88
+ if (result !== null) return result;
89
+ }
90
+ return null;
91
+ }
92
+ function checkTrailingCommaInItems(items) {
93
+ if (items.length === 0) return null;
94
+ const lastItem = items[items.length - 1];
95
+ if (lastItem && typeof lastItem === "object" && "comma" in lastItem) return lastItem.comma === true;
96
+ return false;
97
+ }
98
+ function detectNewline(str) {
99
+ const lfIndex = str.indexOf("\n");
100
+ if (lfIndex > 0 && str[lfIndex - 1] === "\r") return "\r\n";
101
+ return "\n";
102
+ }
103
+ function countTrailingNewlines(str) {
104
+ let count = 0;
105
+ let pos = str.length;
106
+ while (pos > 0 && str[pos - 1] === "\n") {
107
+ count++;
108
+ pos--;
109
+ if (pos > 0 && str[pos - 1] === "\r") pos--;
110
+ }
111
+ return count;
112
+ }
113
+ function escapeCaseOfRaw(raw) {
114
+ for (let i = 0; i < raw.length; i++) {
115
+ if (raw[i] !== "\\") continue;
116
+ const n1 = raw[i + 1];
117
+ if (!n1) return null;
118
+ if (n1 === "\\") {
119
+ i++;
120
+ continue;
121
+ }
122
+ if (n1 === "x" && /^[0-9A-Fa-f]{2}$/.test(raw.slice(i + 2, i + 4))) return /[A-F]/.test(raw.slice(i + 2, i + 4));
123
+ if (n1 === "u" && /^[0-9A-Fa-f]{4}$/.test(raw.slice(i + 2, i + 6))) return /[A-F]/.test(raw.slice(i + 2, i + 6));
124
+ if (n1 === "U" && /^[0-9A-Fa-f]{8}$/.test(raw.slice(i + 2, i + 10))) return /[A-F]/.test(raw.slice(i + 2, i + 10));
125
+ }
126
+ return null;
127
+ }
128
+ function findEscapeCaseInNode(node) {
129
+ if (!node || typeof node !== "object") return null;
130
+ if (node.type === "String" && typeof node.raw === "string") {
131
+ const result = escapeCaseOfRaw(node.raw);
132
+ if (result !== null) return result;
133
+ }
134
+ for (const prop of [
135
+ "key",
136
+ "item",
137
+ "value"
138
+ ]) if (node[prop] && typeof node[prop] === "object") {
139
+ const result = findEscapeCaseInNode(node[prop]);
140
+ if (result !== null) return result;
141
+ }
142
+ if (Array.isArray(node.items)) for (const child of node.items) {
143
+ const result = findEscapeCaseInNode(child);
144
+ if (result !== null) return result;
145
+ }
146
+ return null;
147
+ }
148
+ function detectEscapeSequenceUpperCase(cstNodes) {
149
+ for (const node of cstNodes) {
150
+ const result = findEscapeCaseInNode(node);
151
+ if (result !== null) return result;
152
+ }
153
+ return true;
154
+ }
155
+ function detectTabsForIndentation(str) {
156
+ const lines = str.split(/\r?\n/);
157
+ let tabCount = 0;
158
+ let spaceCount = 0;
159
+ for (const line of lines) {
160
+ if (line.length === 0) continue;
161
+ if (line[0] === " ") tabCount++;
162
+ else if (line[0] === " ") spaceCount++;
163
+ if (tabCount + spaceCount >= 5) break;
164
+ }
165
+ if (tabCount > 0) return tabCount >= spaceCount;
166
+ return false;
167
+ }
168
+ function countLeadingSpaces(line) {
169
+ let count = 0;
170
+ while (count < line.length && line[count] === " ") count++;
171
+ return count;
172
+ }
173
+ function detectIndentWidth(tomlString, syntaxTree) {
174
+ const lines = tomlString.split(/\r?\n/);
175
+ const widths = [];
176
+ const containers = /* @__PURE__ */ new Set([
177
+ "Table",
178
+ "TableArray",
179
+ "InlineTable",
180
+ "InlineArray"
181
+ ]);
182
+ const rowNodes = /* @__PURE__ */ new Set([
183
+ "Table",
184
+ "TableArray",
185
+ "InlineTable",
186
+ "InlineArray",
187
+ "KeyValue",
188
+ "InlineItem",
189
+ "Comment"
190
+ ]);
191
+ const visit = (node, containerStartLine) => {
192
+ var _node$loc, _node$loc2, _node$loc3;
193
+ if (!node || typeof node !== "object") return;
194
+ if (containerStartLine !== void 0 && rowNodes.has(node.type) && ((_node$loc = node.loc) === null || _node$loc === void 0 || (_node$loc = _node$loc.start) === null || _node$loc === void 0 ? void 0 : _node$loc.line) > containerStartLine) {
195
+ const leadingSpaces = countLeadingSpaces(lines[node.loc.start.line - 1] ?? "");
196
+ if (leadingSpaces > 0) widths.push(leadingSpaces);
197
+ }
198
+ const nextContainerStartLine = containers.has(node.type) && ((_node$loc2 = node.loc) === null || _node$loc2 === void 0 || (_node$loc2 = _node$loc2.end) === null || _node$loc2 === void 0 ? void 0 : _node$loc2.line) > ((_node$loc3 = node.loc) === null || _node$loc3 === void 0 || (_node$loc3 = _node$loc3.start) === null || _node$loc3 === void 0 ? void 0 : _node$loc3.line) ? node.loc.start.line : containerStartLine;
199
+ if (Array.isArray(node.items)) for (const item of node.items) visit(item, nextContainerStartLine);
200
+ if (node.item) visit(node.item, nextContainerStartLine);
201
+ if (node.value) visit(node.value, nextContainerStartLine);
202
+ };
203
+ const nodes = Array.isArray(syntaxTree) ? syntaxTree : Array.from(syntaxTree ?? []);
204
+ for (const node of nodes) visit(node);
205
+ if (widths.length > 0) return Math.min(...widths);
206
+ const rootIndentWidths = lines.filter((line) => line.trim().length > 0 && !line.trimStart().startsWith("#")).map(countLeadingSpaces).filter((width) => width > 0);
207
+ return rootIndentWidths.length > 0 ? Math.min(...rootIndentWidths) : 2;
208
+ }
209
+ /**
210
+ * Validates a format object and warns about unsupported properties.
211
+ * Throws errors for supported properties with invalid types.
212
+ * @param format - The format object to validate
213
+ * @returns The validated format object with only supported properties and correct types
214
+ */
215
+ /**
216
+ * Spellings accepted for `newLine`, mapped to the line ending they denote.
217
+ * A Map rather than an object literal so that a key like `constructor` cannot
218
+ * resolve through Object.prototype.
219
+ */
220
+ const NEW_LINE_ALIASES = /* @__PURE__ */ new Map([
221
+ ["\n", "\n"],
222
+ ["\r\n", "\r\n"],
223
+ ["\\n", "\n"],
224
+ ["\\r\\n", "\r\n"],
225
+ ["LF", "\n"],
226
+ ["CRLF", "\r\n"],
227
+ ["UNIX", "\n"],
228
+ ["DOS", "\r\n"]
229
+ ]);
230
+ /**
231
+ * Resolves an accepted `newLine` spelling to the literal it denotes.
232
+ *
233
+ * TOML permits only LF and CRLF, so anything else would silently produce a
234
+ * document that does not parse (a bare '\\r', or the literal text 'LF' written
235
+ * between every pair of lines). Rejecting it here means every entry point that
236
+ * resolves a format gets the check, rather than just `patch()`.
237
+ *
238
+ * @throws TypeError when the value denotes neither LF nor CRLF
239
+ */
240
+ function normalizeNewLine(value) {
241
+ const resolved = NEW_LINE_ALIASES.get(value) ?? NEW_LINE_ALIASES.get(value.toUpperCase());
242
+ if (resolved === void 0) throw new TypeError("Invalid newLine value: expected LF or CRLF");
243
+ return resolved;
244
+ }
245
+ function validateFormatObject(format) {
246
+ if (!format || typeof format !== "object") return {};
247
+ const isBool = (v) => typeof v === "boolean" ? null : `expected boolean, got ${typeof v}`;
248
+ const isMultilineContainerMode = (v) => v == null || typeof v === "boolean" || v === "auto" || v === "parent" || typeof v === "number" && Number.isInteger(v) && v >= 0 ? null : `expected boolean, non-negative integer, "auto" or "parent", got ${typeof v}`;
249
+ const schema = {
250
+ newLine: (v) => typeof v === "string" ? null : `expected string, got ${typeof v}`,
251
+ trailingNewline: (v) => typeof v === "boolean" || typeof v === "number" ? null : `expected boolean or number, got ${typeof v}`,
252
+ trailingComma: isBool,
253
+ bracketSpacing: isBool,
254
+ leadingBom: isBool,
255
+ inlineTableStart: (v) => v == null || typeof v === "number" && Number.isInteger(v) && v >= 0 ? null : `expected non-negative integer or undefined, got ${typeof v}`,
256
+ truncateZeroTimeInDates: isBool,
257
+ useTabsForIndentation: isBool,
258
+ indentWidth: (v) => v == null || typeof v === "number" && Number.isInteger(v) && v > 0 ? null : `expected positive integer or undefined, got ${typeof v}`,
259
+ minimumDecimals: (v) => v == null || typeof v === "number" && Number.isInteger(v) && v >= 0 ? null : `expected non-negative integer or undefined, got ${typeof v}`,
260
+ minimumTimeDecimals: (v) => v == null || typeof v === "number" && Number.isInteger(v) && v >= 0 ? null : `expected non-negative integer or undefined, got ${typeof v}`,
261
+ updateOrder: isBool,
262
+ multilineTable: isMultilineContainerMode,
263
+ multilineArray: isMultilineContainerMode,
264
+ escapeSequenceUpperCase: isBool
265
+ };
266
+ const validatedFormat = {};
267
+ const unsupported = [];
268
+ const invalid = [];
269
+ for (const key in format) {
270
+ const validator = Object.prototype.hasOwnProperty.call(schema, key) ? schema[key] : void 0;
271
+ if (validator) {
272
+ const value = format[key];
273
+ const error = validator(value);
274
+ if (error) invalid.push(`${key} (${error})`);
275
+ else validatedFormat[key] = value;
276
+ } else if (Object.prototype.hasOwnProperty.call(format, key)) unsupported.push(key);
277
+ }
278
+ if (unsupported.length > 0) console.warn(`toml-patch: Ignoring unsupported format properties: ${unsupported.join(", ")}. Supported properties are: ${Object.keys(schema).join(", ")}`);
279
+ if (invalid.length > 0) throw new TypeError(`Invalid types for format properties: ${invalid.join(", ")}`);
280
+ if ("newLine" in validatedFormat) validatedFormat.newLine = normalizeNewLine(validatedFormat.newLine);
281
+ return validatedFormat;
282
+ }
283
+ /**
284
+ * Resolves a format parameter to a TomlFormat instance.
285
+ * Handles TomlFormat instances and partial TomlFormat objects as well as undefined.
286
+ *
287
+ * @param format - The format parameter to resolve (TomlFormat instance, partial format object, or undefined)
288
+ * @param fallbackFormat - The fallback TomlFormat to use when no format is provided
289
+ * @returns A resolved TomlFormat instance
290
+ */
291
+ function resolveTomlFormat(format, fallbackFormat) {
292
+ if (format) {
293
+ if (format instanceof TomlFormat) return format;
294
+ else {
295
+ const validatedFormat = validateFormatObject(format);
296
+ return new TomlFormat(validatedFormat.newLine ?? fallbackFormat.newLine, validatedFormat.trailingNewline ?? fallbackFormat.trailingNewline, validatedFormat.trailingComma ?? fallbackFormat.trailingComma, validatedFormat.bracketSpacing ?? fallbackFormat.bracketSpacing, "inlineTableStart" in validatedFormat ? validatedFormat.inlineTableStart : fallbackFormat.inlineTableStart, validatedFormat.truncateZeroTimeInDates ?? fallbackFormat.truncateZeroTimeInDates, validatedFormat.useTabsForIndentation ?? fallbackFormat.useTabsForIndentation, validatedFormat.minimumDecimals ?? fallbackFormat.minimumDecimals, validatedFormat.leadingBom ?? fallbackFormat.leadingBom, validatedFormat.updateOrder ?? fallbackFormat.updateOrder, validatedFormat.indentWidth ?? fallbackFormat.indentWidth, validatedFormat.multilineTable ?? fallbackFormat.multilineTable, validatedFormat.multilineArray ?? fallbackFormat.multilineArray, validatedFormat.escapeSequenceUpperCase ?? fallbackFormat.escapeSequenceUpperCase, validatedFormat.minimumTimeDecimals ?? fallbackFormat.minimumTimeDecimals);
297
+ }
298
+ } else return fallbackFormat;
299
+ }
300
+ var TomlFormat = class TomlFormat {
301
+ /**
302
+ * The line ending character(s) to use in the output TOML.
303
+ * This option affects only the stringification process, not the internal representation (CST).
304
+ *
305
+ * @example
306
+ * - '\n' for Unix/Linux line endings
307
+ * - '\r\n' for Windows line endings
308
+ */
309
+ newLine;
310
+ /**
311
+ * The number of trailing newlines to add at the end of the TOML document.
312
+ * This option affects only the stringification process, not the internal representation (CST).
313
+ *
314
+ * @example
315
+ * - 0: No trailing newline
316
+ * - 1: One trailing newline (standard)
317
+ * - 2: Two trailing newlines (adds extra spacing)
318
+ */
319
+ trailingNewline;
320
+ /**
321
+ * Whether to add trailing commas after the last element in arrays and inline tables.
322
+ *
323
+ * @example
324
+ * - true: [1, 2, 3,] and { x = 1, y = 2, }
325
+ * - false: [1, 2, 3] and { x = 1, y = 2 }
326
+ */
327
+ trailingComma;
328
+ /**
329
+ * Whether to add spaces after opening brackets/braces and before closing brackets/braces
330
+ * in arrays and inline tables.
331
+ *
332
+ * @example
333
+ * - true: [ 1, 2, 3 ] and { x = 1, y = 2 }
334
+ * - false: [1, 2, 3] and {x = 1, y = 2}
335
+ */
336
+ bracketSpacing;
337
+ /**
338
+ * Whether the output should include a leading UTF-8 BOM marker (U+FEFF).
339
+ *
340
+ * This is auto-detected from the source TOML and preserved during patching.
341
+ */
342
+ leadingBom;
343
+ /**
344
+ * The nesting depth at which new tables should start being formatted as inline tables.
345
+ * When adding new tables during patching or stringifying objects:
346
+ * - Tables at depth >= inlineTableStart will be formatted as inline tables
347
+ * - Tables at depth < inlineTableStart will be formatted as separate table sections
348
+ *
349
+ * @example
350
+ * - 0: All tables are inline tables including top-level tables (root level)
351
+ * - 1: Top-level tables as sections, nested tables as inline (default)
352
+ * - 2: Two levels as sections, deeper nesting as inline
353
+ */
354
+ inlineTableStart;
355
+ /**
356
+ * Whether to truncate time components in UTC date fields when they are zero.
357
+ * This setting affects only the stringification process.
358
+ *
359
+ * @example
360
+ * - true: Date('2024-01-15T00:00:00.000Z') serializes as 2024-01-15
361
+ * - false: Date('2024-01-15T00:00:00.000Z') serializes as 2024-01-15T00:00:00.000Z
362
+ *
363
+ */
364
+ truncateZeroTimeInDates;
365
+ /**
366
+ * Whether to use tabs instead of spaces for indentation/padding.
367
+ * When enabled, lines that need to be indented will use tabs.
368
+ *
369
+ * @example
370
+ * - true: Uses tabs for indentation
371
+ * - false: Uses spaces for indentation (default)
372
+ *
373
+ */
374
+ useTabsForIndentation;
375
+ /**
376
+ * The number of columns used for one indentation level in generated multiline values.
377
+ * This is auto-detected when patching and defaults to two columns.
378
+ */
379
+ indentWidth;
380
+ /**
381
+ * The minimum number of decimal places to use when serializing JS numbers as TOML floats.
382
+ * When greater than 0, plain JS integer values are serialized as TOML floats padded with
383
+ * zeros to reach the specified decimal count. BigInt values are always serialized as integers
384
+ * regardless of this setting.
385
+ *
386
+ * @example
387
+ * - 0: stringify({ x: 1, y: 1.5 }) → x = 1 / y = 1.5 (default)
388
+ * - 1: stringify({ x: 1, y: 1.5 }) → x = 1.0 / y = 1.5
389
+ * - 2: stringify({ x: 1, y: 1.5 }) → x = 1.00 / y = 1.50
390
+ */
391
+ minimumDecimals;
392
+ /**
393
+ * The minimum number of fractional-second digits to write for date/time values.
394
+ *
395
+ * When greater than 0, a time or datetime is padded with zeros to reach the specified digit
396
+ * count, and a time written as `HH:MM` gains `:00` before its fraction. Digits already written
397
+ * are never removed, so a value with more digits keeps them, and a date-only value is
398
+ * unaffected because it carries no time. This is separate from `minimumDecimals`, which
399
+ * applies to numbers, so the two can be set independently.
400
+ *
401
+ * Not auto-detectable — caller must set explicitly.
402
+ *
403
+ * @example
404
+ * - 0: t = 07:32:00 (default)
405
+ * - 3: t = 07:32:00.000
406
+ */
407
+ minimumTimeDecimals;
408
+ /**
409
+ * Whether `patch()` should reorder root key-values, `[table]`/`[[array]]` section blocks,
410
+ * and rows inside table bodies to match the key order of the JS object passed to `patch()`,
411
+ * carrying each entry's owned comments along with it (see docs/CommentOwnership.md).
412
+ *
413
+ * Off by default: with the option unset or `false`, `patch()` only ever changes values that
414
+ * actually differ between the existing document and the updated object, preserving the
415
+ * existing document's order even when the JS object's key order differs.
416
+ *
417
+ * Not auto-detectable — the existing document's order says nothing about the caller's
418
+ * intent, so `autoDetectFormatWithCst` always resolves this to `false`.
419
+ *
420
+ * See docs/PLAN-Update-Order.md for the full behavior and current scope limitations.
421
+ */
422
+ updateOrder;
423
+ /**
424
+ * Whether newly generated inline tables should use multiline layout.
425
+ *
426
+ * `true` and `false` select a layout directly. A non-negative integer selects
427
+ * multiline layout at that structural container depth or deeper. `'auto'`
428
+ * keeps new containers compact and `'parent'` follows the immediate parent.
429
+ */
430
+ multilineTable;
431
+ /**
432
+ * Whether newly generated inline arrays should use multiline layout.
433
+ *
434
+ * `true` and `false` select a layout directly. A non-negative integer selects
435
+ * multiline layout at that structural container depth or deeper. `'auto'`
436
+ * keeps new containers compact and `'parent'` follows the immediate parent.
437
+ */
438
+ multilineArray;
439
+ /**
440
+ * Whether to write `\uXXXX` / `\UXXXXXXXX` / `\xHH` escape sequences with
441
+ * uppercase hex digits. Auto-detected from the first hex escape sequence in
442
+ * the document during patching; defaults to `true` (uppercase hex).
443
+ */
444
+ escapeSequenceUpperCase;
445
+ constructor(newLine, trailingNewline, trailingComma, bracketSpacing, inlineTableStart, truncateZeroTimeInDates, useTabsForIndentation, minimumDecimals, leadingBom, updateOrder, indentWidth, multilineTable, multilineArray, escapeSequenceUpperCase, minimumTimeDecimals) {
446
+ this.newLine = newLine == null ? "\n" : normalizeNewLine(newLine);
447
+ this.trailingNewline = trailingNewline ?? 1;
448
+ this.trailingComma = trailingComma ?? false;
449
+ this.bracketSpacing = bracketSpacing ?? true;
450
+ this.inlineTableStart = inlineTableStart ?? 1;
451
+ this.truncateZeroTimeInDates = truncateZeroTimeInDates ?? false;
452
+ this.useTabsForIndentation = useTabsForIndentation ?? false;
453
+ this.indentWidth = this.useTabsForIndentation ? 1 : indentWidth ?? 2;
454
+ this.minimumDecimals = minimumDecimals ?? 0;
455
+ this.minimumTimeDecimals = minimumTimeDecimals ?? 0;
456
+ this.leadingBom = leadingBom ?? false;
457
+ this.updateOrder = updateOrder ?? false;
458
+ this.multilineTable = multilineTable ?? "auto";
459
+ this.multilineArray = multilineArray ?? "auto";
460
+ this.escapeSequenceUpperCase = escapeSequenceUpperCase ?? true;
461
+ }
462
+ /**
463
+ * Creates a new TomlFormat instance with default formatting preferences.
464
+ *
465
+ * @returns A new TomlFormat instance with default values:
466
+ * - newLine: '\n'
467
+ * - trailingNewline: 1
468
+ * - trailingComma: false
469
+ * - bracketSpacing: true
470
+ * - leadingBom: false
471
+ * - inlineTableStart: 1
472
+ * - truncateZeroTimeInDates: false
473
+ * - useTabsForIndentation: false
474
+ * - minimumDecimals: 0
475
+ * - minimumTimeDecimals: 0
476
+ * - updateOrder: false
477
+ */
478
+ static default() {
479
+ return new TomlFormat("\n", 1, false, true, 1, false, false, 0, false, false, 2, DEFAULT_MULTILINE_TABLE, DEFAULT_MULTILINE_ARRAY, true, 0);
480
+ }
481
+ /**
482
+ * Auto-detects formatting preferences from an existing TOML string.
483
+ *
484
+ * This method analyzes the provided TOML string to determine formatting
485
+ * preferences such as line endings, trailing newlines, and comma usage.
486
+ *
487
+ * @param tomlString - The TOML string to analyze for formatting patterns
488
+ * @returns A new TomlFormat instance with detected formatting preferences
489
+ *
490
+ * @example
491
+ * ```typescript
492
+ * const toml = 'array = ["a", "b", "c",]\ntable = { x = 1, y = 2, }';
493
+ * const format = TomlFormat.autoDetectFormat(toml);
494
+ * // format.trailingComma will be true
495
+ * // format.newLine will be '\n'
496
+ * // format.trailingNewline will be 0 (no trailing newline)
497
+ * ```
498
+ */
499
+ static autoDetectFormat(tomlString) {
500
+ return TomlFormat.autoDetectFormatWithCst(tomlString);
501
+ }
502
+ /**
503
+ * Internal method: Auto-detects formatting preferences from a TOML string with optional pre-parsed CST.
504
+ *
505
+ * This is used internally to avoid redundant parsing when the CST is already available.
506
+ * External callers should use `autoDetectFormat(tomlString)` instead.
507
+ *
508
+ * @internal
509
+ * @param tomlString - The TOML string to analyze for formatting patterns
510
+ * @param syntaxTree - Optional pre-parsed CST to avoid redundant parsing
511
+ * @returns A new TomlFormat instance with detected formatting preferences
512
+ */
513
+ static autoDetectFormatWithCst(tomlString, syntaxTree) {
514
+ const format = TomlFormat.default();
515
+ format.leadingBom = hasLeadingBom(tomlString);
516
+ const tomlContent = stripLeadingBom(tomlString);
517
+ let cstNodes = [];
518
+ format.newLine = detectNewline(tomlContent);
519
+ format.trailingNewline = countTrailingNewlines(tomlContent);
520
+ try {
521
+ cstNodes = Array.isArray(syntaxTree) ? syntaxTree : Array.from(syntaxTree ?? parseTOML(tomlContent));
522
+ format.trailingComma = detectTrailingComma(cstNodes);
523
+ format.bracketSpacing = detectBracketSpacing(tomlContent, cstNodes);
524
+ } catch (error) {
525
+ format.trailingComma = false;
526
+ format.bracketSpacing = true;
527
+ }
528
+ format.useTabsForIndentation = detectTabsForIndentation(tomlContent);
529
+ if (format.useTabsForIndentation) format.indentWidth = 1;
530
+ else format.indentWidth = detectIndentWidth(tomlContent, cstNodes);
531
+ format.inlineTableStart = 1;
532
+ format.truncateZeroTimeInDates = false;
533
+ format.minimumDecimals = 0;
534
+ format.minimumTimeDecimals = 0;
535
+ format.updateOrder = false;
536
+ format.multilineTable = DEFAULT_MULTILINE_TABLE;
537
+ format.multilineArray = DEFAULT_MULTILINE_ARRAY;
538
+ format.escapeSequenceUpperCase = detectEscapeSequenceUpperCase(cstNodes);
539
+ return format;
540
+ }
541
+ /** @deprecated Use autoDetectFormatWithCst instead. */
542
+ static autoDetectFormatWithAst(tomlString, syntaxTree) {
543
+ return TomlFormat.autoDetectFormatWithCst(tomlString, syntaxTree);
544
+ }
545
+ };
546
+
547
+ export { DEFAULT_MULTILINE_ARRAY, DEFAULT_MULTILINE_TABLE, TomlFormat, countTrailingNewlines, detectBracketSpacing, detectEscapeSequenceUpperCase, detectIndentWidth, detectNewline, detectTabsForIndentation, detectTrailingComma, normalizeNewLine, resolveTomlFormat, validateFormatObject };
548
+ //# sourceMappingURL=toml-format.js.map