@node-core/utils 7.4.0 → 7.4.1

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 (32) hide show
  1. package/lib/update-v8/deps.js +4 -1
  2. package/node_modules/branch-diff/.github/dependabot.yml +14 -2
  3. package/node_modules/branch-diff/.github/workflows/test-and-release.yml +4 -15
  4. package/node_modules/branch-diff/CHANGELOG.md +24 -0
  5. package/node_modules/branch-diff/package.json +35 -3
  6. package/node_modules/js-yaml/dist/browser/js-yaml.esm.min.mjs +2 -2
  7. package/node_modules/js-yaml/dist/browser/js-yaml.esm.min.mjs.map +1 -1
  8. package/node_modules/js-yaml/dist/browser/js-yaml.umd.min.js +1 -1
  9. package/node_modules/js-yaml/dist/browser/js-yaml.umd.min.js.map +1 -1
  10. package/node_modules/js-yaml/dist/js-yaml.cjs.js +2 -1
  11. package/node_modules/js-yaml/dist/js-yaml.cjs.js.map +1 -1
  12. package/node_modules/js-yaml/dist/js-yaml.mjs +2 -1
  13. package/node_modules/js-yaml/dist/js-yaml.mjs.map +1 -1
  14. package/node_modules/js-yaml/package.json +1 -1
  15. package/node_modules/smol-toml/README.md +460 -273
  16. package/node_modules/smol-toml/dist/date.js +50 -21
  17. package/node_modules/smol-toml/dist/error.d.ts +1 -2
  18. package/node_modules/smol-toml/dist/error.js +6 -2
  19. package/node_modules/smol-toml/dist/extract.js +240 -20
  20. package/node_modules/smol-toml/dist/index.cjs +409 -373
  21. package/node_modules/smol-toml/dist/index.d.ts +5 -4
  22. package/node_modules/smol-toml/dist/index.js +2 -1
  23. package/node_modules/smol-toml/dist/parse.d.ts +38 -1
  24. package/node_modules/smol-toml/dist/parse.js +52 -37
  25. package/node_modules/smol-toml/dist/primitive.js +23 -110
  26. package/node_modules/smol-toml/dist/stringify.d.ts +2 -1
  27. package/node_modules/smol-toml/dist/stringify.js +74 -36
  28. package/node_modules/smol-toml/dist/struct.js +76 -99
  29. package/node_modules/smol-toml/dist/util.d.ts +6 -1
  30. package/node_modules/smol-toml/dist/util.js +4 -36
  31. package/node_modules/smol-toml/package.json +8 -8
  32. package/package.json +1 -1
@@ -30,96 +30,13 @@ Object.defineProperties(exports, {
30
30
  __esModule: { value: true },
31
31
  [Symbol.toStringTag]: { value: "Module" }
32
32
  });
33
- //#region src/date.ts
34
- let DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
35
- var TomlDate = class TomlDate extends Date {
36
- #hasDate = false;
37
- #hasTime = false;
38
- #offset = null;
39
- constructor(date) {
40
- let hasDate = true;
41
- let hasTime = true;
42
- let offset = "Z";
43
- if (typeof date === "string") {
44
- let match = date.match(DATE_TIME_RE);
45
- if (match) {
46
- if (!match[1]) {
47
- hasDate = false;
48
- date = `0000-01-01T${date}`;
49
- }
50
- hasTime = !!match[2];
51
- hasTime && date[10] === " " && (date = date.replace(" ", "T"));
52
- if (match[2] && +match[2] > 23) date = "";
53
- else {
54
- offset = match[3] || null;
55
- date = date.toUpperCase();
56
- if (!offset && hasTime) date += "Z";
57
- }
58
- } else date = "";
59
- }
60
- super(date);
61
- if (!isNaN(this.getTime())) {
62
- this.#hasDate = hasDate;
63
- this.#hasTime = hasTime;
64
- this.#offset = offset;
65
- }
66
- }
67
- isDateTime() {
68
- return this.#hasDate && this.#hasTime;
69
- }
70
- isLocal() {
71
- return !this.#hasDate || !this.#hasTime || !this.#offset;
72
- }
73
- isDate() {
74
- return this.#hasDate && !this.#hasTime;
75
- }
76
- isTime() {
77
- return this.#hasTime && !this.#hasDate;
78
- }
79
- isValid() {
80
- return this.#hasDate || this.#hasTime;
81
- }
82
- toISOString() {
83
- let iso = super.toISOString();
84
- if (this.isDate()) return iso.slice(0, 10);
85
- if (this.isTime()) return iso.slice(11, 23);
86
- if (this.#offset === null) return iso.slice(0, -1);
87
- if (this.#offset === "Z") return iso;
88
- let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
89
- offset = this.#offset[0] === "-" ? offset : -offset;
90
- return (/* @__PURE__ */ new Date(this.getTime() - offset * 6e4)).toISOString().slice(0, -1) + this.#offset;
91
- }
92
- static wrapAsOffsetDateTime(jsDate, offset = "Z") {
93
- let date = new TomlDate(jsDate);
94
- date.#offset = offset;
95
- return date;
96
- }
97
- static wrapAsLocalDateTime(jsDate) {
98
- let date = new TomlDate(jsDate);
99
- date.#offset = null;
100
- return date;
101
- }
102
- static wrapAsLocalDate(jsDate) {
103
- let date = new TomlDate(jsDate);
104
- date.#hasTime = false;
105
- date.#offset = null;
106
- return date;
107
- }
108
- static wrapAsLocalTime(jsDate) {
109
- let date = new TomlDate(jsDate);
110
- date.#hasDate = false;
111
- date.#offset = null;
112
- return date;
113
- }
114
- };
115
- //#endregion
116
33
  //#region src/error.ts
117
34
  function getLineColFromPtr(string, ptr) {
118
- let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g);
35
+ let lines = string.slice(0, ptr).split(/\r?\n/);
119
36
  return [lines.length, lines.pop().length + 1];
120
37
  }
121
38
  function makeCodeBlock(string, line, column) {
122
- let lines = string.split(/\r\n|\n|\r/g);
39
+ let lines = string.split(/\r?\n/);
123
40
  let codeblock = "";
124
41
  let numberLen = (Math.log10(line + 1) | 0) + 1;
125
42
  for (let i = line - 1; i <= line + 1; i++) {
@@ -136,7 +53,7 @@ function makeCodeBlock(string, line, column) {
136
53
  }
137
54
  return codeblock;
138
55
  }
139
- var TomlError = class extends Error {
56
+ var TomlError = class TomlError extends Error {
140
57
  line;
141
58
  column;
142
59
  codeblock;
@@ -148,65 +65,19 @@ var TomlError = class extends Error {
148
65
  this.column = column;
149
66
  this.codeblock = codeblock;
150
67
  }
151
- };
152
- //#endregion
153
- //#region src/util.ts
154
- /** @internal */
155
- function indexOfNewline(str, start = 0) {
156
- let idx = str.indexOf("\n", start);
157
- if (str.charCodeAt(idx - 1) === 13) idx--;
158
- return idx;
159
- }
160
- /** @internal */
161
- function skipComment(ctx) {
162
- for (; ctx.p < ctx.s.length; ctx.p++) {
163
- let c = ctx.s.charCodeAt(ctx.p);
164
- if (c === 10) break;
165
- if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
166
- ctx.p++;
167
- break;
168
- }
169
- if (c < 32 && c !== 9 || c === 127) throw new TomlError("control characters are not allowed in comments", {
68
+ /** @internal */
69
+ static x(message, ctx, ptr) {
70
+ throw new TomlError(message, {
170
71
  toml: ctx.s,
171
- ptr: ctx.p
72
+ ptr: ptr ?? ctx.p
172
73
  });
173
74
  }
174
- }
175
- /** @internal */
176
- function skipVoid(ctx, banNewLines, banComments) {
177
- let c;
178
- while (1) {
179
- while ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) ctx.p++;
180
- if (banComments || c !== 35) break;
181
- skipComment(ctx);
182
- }
183
- }
184
- /** @internal */
185
- function skipUntil(ctx, sep, end) {
186
- let ptr = ctx.p;
187
- if (!end) {
188
- ptr = indexOfNewline(ctx.s, ptr);
189
- ctx.p = ptr < 0 ? ctx.s.length : ptr;
190
- return;
191
- }
192
- for (; ctx.p < ctx.s.length; ctx.p++) {
193
- let c = ctx.s.charCodeAt(ctx.p);
194
- if (c === 35) skipComment(ctx);
195
- else if (c === end || c === sep) return;
196
- }
197
- throw new TomlError("cannot find end of structure", {
198
- toml: ctx.s,
199
- ptr
200
- });
201
- }
75
+ };
202
76
  //#endregion
203
77
  //#region src/primitive.ts
204
- let INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
205
- let FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
206
- let LEADING_ZERO = /^[+-]?0[0-9_]/;
207
78
  /** @internal */
208
79
  function parseString(ctx) {
209
- let start = ctx.p;
80
+ let startPtr = ctx.p;
210
81
  let c = ctx.s.charCodeAt(ctx.p++);
211
82
  let first = c;
212
83
  let isLiteral = c === 39;
@@ -221,16 +92,16 @@ function parseString(ctx) {
221
92
  for (; ctx.p < ctx.s.length; ctx.p++) {
222
93
  c = ctx.s.charCodeAt(ctx.p);
223
94
  if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) state = state && 3;
224
- else if (c < 32 && c !== 9 || c === 127) throw new TomlError("control characters are not allowed in strings", {
225
- toml: ctx.s,
226
- ptr: ctx.p
227
- });
95
+ else if (c < 32 && c !== 9 || c === 127) TomlError.x("control characters are not allowed in strings", ctx);
228
96
  else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
229
97
  if (isMultiline) {
230
98
  if (ctx.s.charCodeAt(ctx.p + 3) === first) ctx.p++;
231
99
  if (ctx.s.charCodeAt(ctx.p + 3) === first) ctx.p++;
232
100
  }
233
- if (!state) parsed += ctx.s.slice(sliceStart, ctx.p);
101
+ if (!state) {
102
+ let s = ctx.s.slice(sliceStart, ctx.p);
103
+ parsed = parsed ? parsed + s : s;
104
+ }
234
105
  ctx.p += isMultiline ? 3 : 1;
235
106
  return parsed;
236
107
  } else if (!state) {
@@ -240,25 +111,20 @@ function parseString(ctx) {
240
111
  }
241
112
  } else if (state === 1) {
242
113
  if (c === 120 || c === 117 || c === 85) {
114
+ let errPtr = ctx.p++ - 1;
243
115
  let value = 0;
244
116
  let len = c === 120 ? 2 : c === 117 ? 4 : 8;
245
117
  for (let j = 0; j < len; j++, ctx.p++) {
246
- let hex = ctx.s.charCodeAt(ctx.p + 1);
118
+ let hex = ctx.s.charCodeAt(ctx.p);
247
119
  let digit = hex >= 48 && hex <= 57 ? hex - 48 : hex >= 65 && hex <= 70 ? hex - 65 + 10 : hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1;
248
- if (digit < 0) throw new TomlError("invalid non-hex character in unicode escape", {
249
- toml: ctx.s,
250
- ptr: ctx.p + 1
251
- });
120
+ if (digit < 0) TomlError.x("invalid non-hex character in unicode escape", ctx);
252
121
  value = value << 4 | digit;
253
122
  }
254
- if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) throw new TomlError("invalid unicode escape", {
255
- toml: ctx.s,
256
- ptr: ctx.p
257
- });
123
+ if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) TomlError.x("invalid unicode escape", ctx, errPtr);
258
124
  parsed += String.fromCodePoint(value);
259
- sliceStart = ctx.p + 1;
125
+ sliceStart = ctx.p--;
260
126
  state = 0;
261
- } else if (c === 32 || c === 9) state = 2;
127
+ } else if (isMultiline && (c === 32 || c === 9)) state = 2;
262
128
  else {
263
129
  if (c === 98) parsed += "\b";
264
130
  else if (c === 116) parsed += " ";
@@ -268,166 +134,322 @@ function parseString(ctx) {
268
134
  else if (c === 101) parsed += "\x1B";
269
135
  else if (c === 34) parsed += "\"";
270
136
  else if (c === 92) parsed += "\\";
271
- else throw new TomlError("unrecognized escape sequence", {
272
- toml: ctx.s,
273
- ptr: ctx.p
274
- });
137
+ else TomlError.x("unrecognised escape sequence", ctx);
275
138
  sliceStart = ctx.p + 1;
276
139
  state = 0;
277
140
  }
278
141
  } else if (c !== 32 && c !== 9) {
279
- if (state === 2) throw new TomlError("invalid escape: only line-ending whitespace may be escaped", {
280
- toml: ctx.s,
281
- ptr: sliceStart
282
- });
142
+ if (state === 2) TomlError.x("invalid escape: only line-ending whitespace may be escaped", ctx, sliceStart);
283
143
  state = !isLiteral && c === 92 ? 1 : 0;
284
144
  sliceStart = ctx.p;
285
145
  }
286
146
  }
287
- throw new TomlError("unfinished string", {
288
- toml: ctx.s,
289
- ptr: start
290
- });
291
- }
292
- function sliceAndTrimEndOf(ctx, start, end) {
293
- let value = ctx.s.slice(start, end);
294
- let commentIdx = value.indexOf("#");
295
- if (commentIdx > 0) {
296
- skipComment({
297
- s: value,
298
- p: commentIdx,
299
- d: 0
300
- });
301
- value = value.slice(0, commentIdx);
302
- }
303
- return value.trimEnd();
147
+ TomlError.x("unfinished string", ctx, startPtr);
304
148
  }
305
- /** @internal */
306
- function parseValue(ctx, integersAsBigInt, end) {
307
- let ptr = ctx.p;
308
- let err = {
309
- toml: ctx.s,
310
- ptr
311
- };
312
- skipUntil(ctx, 44, end);
313
- let value = sliceAndTrimEndOf(ctx, ptr, ctx.p);
314
- if (!value) throw new TomlError("incomplete declaration: value expected", err);
315
- if (value === "-inf") return -Infinity;
316
- if (value === "inf" || value === "+inf") return Infinity;
317
- if (value === "nan" || value === "+nan" || value === "-nan") return NaN;
318
- if (value === "-0") return integersAsBigInt ? 0n : 0;
319
- let isInt = INT_REGEX.test(value);
320
- if (isInt || FLOAT_REGEX.test(value)) {
321
- if (LEADING_ZERO.test(value)) throw new TomlError("leading zeroes are not allowed", err);
322
- value = value.replace(/_/g, "");
323
- let numeric = +value;
324
- if (isNaN(numeric)) throw new TomlError("invalid number", err);
325
- if (isInt) {
326
- if ((isInt = !Number.isSafeInteger(numeric)) && !integersAsBigInt) throw new TomlError("integer value cannot be represented losslessly", err);
327
- if (isInt || integersAsBigInt === true) numeric = BigInt(value);
149
+ //#endregion
150
+ //#region src/date.ts
151
+ let DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
152
+ var TomlDate = class TomlDate extends Date {
153
+ #hasDate = false;
154
+ #hasTime = false;
155
+ #offset = null;
156
+ constructor(date, fasttype, unsafeDelim) {
157
+ let hasDate = true;
158
+ let hasTime = true;
159
+ let offset = "Z";
160
+ let c;
161
+ if (typeof date === "string") {
162
+ if (fasttype) prep: {
163
+ if (fasttype < 3) {
164
+ if (+date.slice(11, 13) > 23) {
165
+ date = "";
166
+ break prep;
167
+ }
168
+ if (fasttype === 2) {
169
+ offset = null;
170
+ date += "Z";
171
+ } else if ((c = date.charCodeAt(date.length - 1)) !== 90 && c !== 122) offset = date.slice(date.length - 6);
172
+ if (unsafeDelim) date = date.slice(0, 10) + "T" + date.slice(11);
173
+ } else if (fasttype === 4) date = +date.slice(0, 2) > 23 ? "" : `0000-01-01T${date}Z`;
174
+ hasDate = fasttype !== 4;
175
+ hasTime = fasttype !== 3;
176
+ }
177
+ else {
178
+ let match = date.match(DATE_TIME_RE);
179
+ if (match) {
180
+ if (!match[1]) {
181
+ hasDate = false;
182
+ date = `0000-01-01T${date}`;
183
+ }
184
+ hasTime = !!match[2];
185
+ hasTime && date[10] === " " && (date = date.replace(" ", "T"));
186
+ if (match[2] && +match[2] > 23) date = "";
187
+ else {
188
+ offset = match[3] || null;
189
+ if (!offset && hasTime) date += "Z";
190
+ }
191
+ } else date = "";
192
+ }
193
+ }
194
+ super(date);
195
+ if (!isNaN(this.getTime())) {
196
+ this.#hasDate = hasDate;
197
+ this.#hasTime = hasTime;
198
+ this.#offset = offset;
328
199
  }
329
- return numeric;
330
200
  }
331
- const date = new TomlDate(value);
332
- if (!date.isValid()) throw new TomlError("invalid value", err);
333
- return date;
334
- }
201
+ isDateTime() {
202
+ return this.#hasDate && this.#hasTime;
203
+ }
204
+ isLocal() {
205
+ return !this.#hasDate || !this.#hasTime || !this.#offset;
206
+ }
207
+ isDate() {
208
+ return this.#hasDate && !this.#hasTime;
209
+ }
210
+ isTime() {
211
+ return this.#hasTime && !this.#hasDate;
212
+ }
213
+ isValid() {
214
+ return this.#hasDate || this.#hasTime;
215
+ }
216
+ toISOString() {
217
+ let iso = super.toISOString();
218
+ if (this.isDate()) return iso.slice(0, 10);
219
+ if (this.isTime()) return iso.slice(11, 23);
220
+ if (this.#offset === null) return iso.slice(0, -1);
221
+ if (this.#offset === "Z" || this.#offset === "z") return iso;
222
+ let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
223
+ offset = this.#offset[0] === "-" ? offset : -offset;
224
+ return (/* @__PURE__ */ new Date(this.getTime() - offset * 6e4)).toISOString().slice(0, -1) + this.#offset;
225
+ }
226
+ static wrapAsOffsetDateTime(jsDate, offset = "Z") {
227
+ let date = new TomlDate(jsDate);
228
+ date.#offset = offset;
229
+ return date;
230
+ }
231
+ static wrapAsLocalDateTime(jsDate) {
232
+ let date = new TomlDate(jsDate);
233
+ date.#offset = null;
234
+ return date;
235
+ }
236
+ static wrapAsLocalDate(jsDate) {
237
+ let date = new TomlDate(jsDate);
238
+ date.#hasTime = false;
239
+ date.#offset = null;
240
+ return date;
241
+ }
242
+ static wrapAsLocalTime(jsDate) {
243
+ let date = new TomlDate(jsDate);
244
+ date.#hasDate = false;
245
+ date.#offset = null;
246
+ return date;
247
+ }
248
+ };
335
249
  //#endregion
336
250
  //#region src/extract.ts
251
+ function isDigit(char, base = 10) {
252
+ return base === 16 ? char > 47 && char < 58 || char > 64 && char < 71 || char > 96 && char < 103 : char > 47 && char < 48 + base;
253
+ }
254
+ function isEndOfValue(char, delim) {
255
+ return char === 32 || char === 9 || char === 10 || char === 13 || delim && (char === delim || char === 44) || char === 35;
256
+ }
337
257
  /** @internal */
338
- function extractValue(ctx, end, integersAsBigInt) {
339
- let ptr = ctx.p;
340
- let c = ctx.s.charCodeAt(ptr);
258
+ function extractValue(ctx, end) {
259
+ let errPtr = ctx.p;
260
+ let c = ctx.s.charCodeAt(ctx.p);
341
261
  if (c === 91 || c === 123) {
342
- if (!ctx.d--) throw new TomlError("document contains excessively nested structures. aborting.", {
343
- toml: ctx.s,
344
- ptr
345
- });
346
- let value = c === 91 ? parseArray(ctx, integersAsBigInt) : parseInlineTable(ctx, integersAsBigInt);
262
+ ctx.d-- || TomlError.x("document contains excessively nested structures. aborting.", ctx);
263
+ let value = c === 91 ? parseArray(ctx) : parseInlineTable(ctx);
347
264
  ctx.d++;
348
265
  return value;
349
266
  }
350
267
  if (c === 34 || c === 39) return parseString(ctx);
351
268
  if (c === 116) {
352
- if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101) throw new TomlError("invalid value", {
353
- toml: ctx.s,
354
- ptr
355
- });
356
- ctx.p++;
357
- return true;
269
+ if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101) TomlError.x("invalid value", ctx, errPtr);
270
+ return ctx.p++, true;
358
271
  }
359
272
  if (c === 102) {
360
- if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101) throw new TomlError("invalid value", {
361
- toml: ctx.s,
362
- ptr
363
- });
364
- ctx.p++;
365
- return false;
273
+ if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101) TomlError.x("invalid value", ctx, errPtr);
274
+ return ctx.p++, false;
275
+ }
276
+ if (c === 43 || c === 45) return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 44 - c, end);
277
+ if (ctx.s.charCodeAt(ctx.p + 4) === 45 && ctx.s.charCodeAt(ctx.p + 7) === 45) return parseDate(ctx, c, end);
278
+ if (ctx.s.charCodeAt(ctx.p + 2) === 58) return parseTime(ctx, c, end);
279
+ return parseNumber(ctx, ctx.p, c, 0, end);
280
+ }
281
+ function parseNumber(ctx, startPtr, startChr, sign, endChr) {
282
+ let c = startChr;
283
+ let state = 0;
284
+ let hasUnderscores = false;
285
+ if (c === 105) {
286
+ if (ctx.s.charCodeAt(++ctx.p) !== 110 || ctx.s.charCodeAt(++ctx.p) !== 102) TomlError.x("invalid value", ctx, startPtr);
287
+ return ctx.p++, (sign || 1) / 0;
288
+ }
289
+ if (c === 110) {
290
+ if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 110) TomlError.x("invalid value", ctx, startPtr);
291
+ return ctx.p++, NaN;
292
+ }
293
+ if (c === 48) {
294
+ if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr)) return ctx.bi === true ? 0n : 0;
295
+ if (!sign) {
296
+ if (c === 120) return parseIntegerBaseN(ctx, startPtr, 16, endChr);
297
+ else if (c === 98) return parseIntegerBaseN(ctx, startPtr, 2, endChr);
298
+ else if (c === 111) return parseIntegerBaseN(ctx, startPtr, 8, endChr);
299
+ }
300
+ if (c === 46) state = 2;
301
+ else if (c === 101 || c === 69) state = 4;
302
+ else TomlError.x("illegal leading zero", ctx, startPtr);
303
+ } else if (!isDigit(c)) TomlError.x("invalid value", ctx, startPtr);
304
+ while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
305
+ if (!state) state = 1;
306
+ if (c === 95) {
307
+ if (!(state & 1)) TomlError.x("illegal underscore", ctx);
308
+ state += 11;
309
+ hasUnderscores = true;
310
+ } else if (state === 1 && c === 46) state = 2;
311
+ else if ((state === 1 || state === 3) && (c === 101 || c === 69)) state = 4;
312
+ else if (state === 4 && (c === 43 || c === 45)) {} else if (!isDigit(c)) TomlError.x(`illegal character in numeric literal`, ctx);
313
+ else if (state > 9) state -= 11;
314
+ else if (!(state & 1)) state++;
315
+ }
316
+ if (!state) {
317
+ let val = (startChr - 48) * (sign || 1);
318
+ return ctx.bi === true ? BigInt(val) : val;
319
+ }
320
+ if (!(state & 1)) TomlError.x("unfinished numeric value", ctx, startPtr);
321
+ let str = ctx.s.slice(startPtr, ctx.p);
322
+ if (hasUnderscores) str = str.replaceAll("_", "");
323
+ return state > 1 ? parseFloat(str) : parseInteger(ctx, str, 10, startPtr);
324
+ }
325
+ function parseIntegerBaseN(ctx, startPtr, base, endChr) {
326
+ let c, underscore = 1;
327
+ while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) if (c === 95) {
328
+ if (underscore & 1) TomlError.x("illegal underscore", ctx);
329
+ underscore = 3;
330
+ } else if (!isDigit(c, base)) TomlError.x(`illegal character in numeric literal`, ctx);
331
+ else if (underscore & 1) underscore--;
332
+ if (underscore & 1) TomlError.x("unfinished numeric value", ctx);
333
+ let str = ctx.s.slice(startPtr + 2, ctx.p);
334
+ if (underscore) str = str.replaceAll("_", "");
335
+ return parseInteger(ctx, str, base, startPtr);
336
+ }
337
+ function parseInteger(ctx, str, base, startPtr) {
338
+ if (ctx.bi !== true) int: {
339
+ let val = parseInt(str, base);
340
+ if (!Number.isSafeInteger(val)) {
341
+ if (ctx.bi) break int;
342
+ TomlError.x("integer value cannot be represented losslessly", ctx, startPtr);
343
+ }
344
+ return val;
345
+ }
346
+ return base === 10 ? BigInt(str) : BigInt((base === 2 ? "0b" : base === 8 ? "0o" : "0x") + str);
347
+ }
348
+ function parseDate(ctx, c, endChr) {
349
+ let startPtr = ctx.p++, unsafeSeparator;
350
+ if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++))) return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
351
+ ctx.p += 5;
352
+ if (!isDigit(ctx.s.charCodeAt(ctx.p++))) TomlError.x("invalid date-time: date part is malformed", ctx, startPtr);
353
+ if (ctx.p >= ctx.s.length || ((c = ctx.s.charCodeAt(ctx.p)) !== 32 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 84 && c !== 116) return readDate(ctx, ctx.s.slice(startPtr, ctx.p), 3, false, startPtr);
354
+ if (ctx.s.charCodeAt(ctx.p += 3) !== 58) TomlError.x("invalid date-time: time part is malformed", ctx, startPtr);
355
+ if (ctx.s.charCodeAt(ctx.p += 3) === 58) ctx.p += 3;
356
+ if (ctx.s.charCodeAt(ctx.p) === 46) while (isDigit(ctx.s.charCodeAt(++ctx.p)));
357
+ if (c = ctx.s.charCodeAt(ctx.p)) {
358
+ if (c === 90 || c === 122) return readDate(ctx, ctx.s.slice(startPtr, ++ctx.p), 1, unsafeSeparator, startPtr, "[+00:00]");
359
+ if (c === 43 || c === 45) return readDate(ctx, ctx.s.slice(startPtr, ctx.p += 6), 1, unsafeSeparator, startPtr, !ctx.ld && "[" + ctx.s.slice(ctx.p - 6, ctx.p) + "]");
360
+ }
361
+ return readDate(ctx, ctx.s.slice(startPtr, ctx.p), 2, unsafeSeparator, startPtr);
362
+ }
363
+ function parseTime(ctx, c, endChr) {
364
+ let start = ctx.p;
365
+ if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(++ctx.p))) return parseNumber(ctx, --ctx.p, c, 0, endChr);
366
+ if (ctx.s.charCodeAt(ctx.p += 4) === 58) ctx.p += 3;
367
+ if (ctx.s.charCodeAt(ctx.p) === 46) while (isDigit(ctx.s.charCodeAt(++ctx.p)));
368
+ return readDate(ctx, ctx.s.slice(start, ctx.p), 4, false, start);
369
+ }
370
+ function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
371
+ if (ctx.ld) {
372
+ let date = new TomlDate(str, type, unsafeDelim);
373
+ if (!date.isValid()) TomlError.x("invalid date", ctx, errPtr);
374
+ return date;
375
+ }
376
+ try {
377
+ if (temporalSuffix) str += temporalSuffix;
378
+ switch (type) {
379
+ case 1: return Temporal.ZonedDateTime.from(str);
380
+ case 2: return Temporal.PlainDateTime.from(str);
381
+ case 3: return Temporal.PlainDate.from(str);
382
+ case 4: return Temporal.PlainTime.from(str);
383
+ }
384
+ } catch (e) {
385
+ TomlError.x(e instanceof Error ? e.message : "" + e, ctx, errPtr);
386
+ }
387
+ }
388
+ //#endregion
389
+ //#region src/util.ts
390
+ /** @internal */
391
+ function skipComment(ctx) {
392
+ for (; ctx.p < ctx.s.length; ctx.p++) {
393
+ let c = ctx.s.charCodeAt(ctx.p);
394
+ if (c === 10) break;
395
+ if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
396
+ ctx.p++;
397
+ break;
398
+ }
399
+ if (c < 32 && c !== 9 || c === 127) TomlError.x("control characters are not allowed in comments", ctx);
400
+ }
401
+ }
402
+ /** @internal */
403
+ function skipVoid(ctx, banNewLines, banComments) {
404
+ let c;
405
+ while (ctx.p < ctx.s.length) {
406
+ while (ctx.p < ctx.s.length && ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10))) ctx.p++;
407
+ if (banComments || c !== 35) break;
408
+ skipComment(ctx);
366
409
  }
367
- return parseValue(ctx, integersAsBigInt, end);
368
410
  }
369
411
  //#endregion
370
412
  //#region src/struct.ts
371
- let KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/;
372
413
  /** @internal */
373
- function parseKey(ctx, end = "=") {
374
- let start = ctx.p;
375
- let dot = start - 1;
414
+ function parseKey(ctx, end = 61) {
415
+ let startPtr;
416
+ let state = 0;
376
417
  let parsed = [];
377
- let endPtr = ctx.s.indexOf(end, start);
378
- if (endPtr < 0) throw new TomlError("incomplete key-value: cannot find end of key", {
379
- toml: ctx.s,
380
- ptr: start
381
- });
382
- do {
383
- let c = ctx.s.charCodeAt(ctx.p = ++dot);
384
- if (c !== 32 && c !== 9) {
385
- if (c === 34 || c === 39) {
386
- if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2)) throw new TomlError("multiline strings are not allowed in keys", {
387
- toml: ctx.s,
388
- ptr: ctx.p
389
- });
390
- let part = parseString(ctx);
391
- dot = ctx.s.indexOf(".", ctx.p);
392
- let strEnd = ctx.s.slice(ctx.p, dot < 0 || dot > endPtr ? endPtr : dot);
393
- let newLine = indexOfNewline(strEnd);
394
- if (newLine > -1) throw new TomlError("newlines are not allowed in keys", {
395
- toml: ctx.s,
396
- ptr: newLine
397
- });
398
- if (strEnd.trimStart()) throw new TomlError("found extra tokens after the string part", {
399
- toml: ctx.s,
400
- ptr: ctx.p
401
- });
402
- if (endPtr < ctx.p) {
403
- endPtr = ctx.s.indexOf(end, ctx.p);
404
- if (endPtr < 0) throw new TomlError("incomplete key-value: cannot find end of key", {
405
- toml: ctx.s,
406
- ptr: start
407
- });
408
- }
409
- parsed.push(part);
410
- } else {
411
- dot = ctx.s.indexOf(".", ctx.p);
412
- let part = ctx.s.slice(ctx.p, dot < 0 || dot > endPtr ? endPtr : dot);
413
- if (!KEY_PART_RE.test(part)) throw new TomlError("only letter, numbers, dashes and underscores are allowed in keys", {
414
- toml: ctx.s,
415
- ptr: ctx.p
416
- });
417
- parsed.push(part.trimEnd());
418
+ let sliceStart;
419
+ let c = ctx.s.charCodeAt(startPtr = ctx.p);
420
+ do
421
+ if (c === end) {
422
+ if (!state) TomlError.x("unexpected end of key", ctx);
423
+ if (state === 1) parsed.push(ctx.s.slice(sliceStart, ctx.p));
424
+ return ctx.p++, parsed;
425
+ } else if (c === 46) {
426
+ if (!state) TomlError.x("illegal empty bare key", ctx);
427
+ if (state === 1) parsed.push(ctx.s.slice(sliceStart, ctx.p));
428
+ state = 0;
429
+ } else if (!state && (c === 34 || c === 39)) {
430
+ if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2)) TomlError.x("illegal quoted key: multiline strings are not allowed", ctx);
431
+ parsed.push(parseString(ctx));
432
+ state = 2;
433
+ ctx.p--;
434
+ } else if (c === 32 || c === 9) {
435
+ if (state === 1) {
436
+ parsed.push(ctx.s.slice(sliceStart, ctx.p));
437
+ state = 2;
418
438
  }
439
+ } else if (state === 2 || c < 48 && c !== 45 || c > 57 && c < 65 || c > 90 && c < 97 && c !== 95 || c > 122) TomlError.x("illegal character in key", ctx);
440
+ else if (!state) {
441
+ state = 1;
442
+ sliceStart = ctx.p;
419
443
  }
420
- } while (dot + 1 && dot < endPtr);
421
- ctx.p = endPtr + 1;
422
- skipVoid(ctx, true, true);
423
- return parsed;
444
+ while (c = ctx.s.charCodeAt(++ctx.p));
445
+ TomlError.x("incomplete key-value: cannot find end of key", ctx, startPtr);
424
446
  }
425
447
  /** @internal */
426
- function parseInlineTable(ctx, integersAsBigInt) {
427
- let res = {};
448
+ function parseInlineTable(ctx) {
449
+ let startPtr = ctx.p++;
450
+ let res = Object.create(null);
428
451
  let seen = /* @__PURE__ */ new Set();
429
452
  let c;
430
- ctx.p++;
431
453
  while (ctx.p < ctx.s.length) {
432
454
  skipVoid(ctx);
433
455
  if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
@@ -437,66 +459,54 @@ function parseInlineTable(ctx, integersAsBigInt) {
437
459
  let k;
438
460
  let t = res;
439
461
  let hasOwn = false;
440
- let p = ctx.p;
462
+ let errPtr = ctx.p;
441
463
  let key = parseKey(ctx);
442
464
  for (let i = 0; i < key.length; i++) {
443
- if (i) t = hasOwn ? t[k] : t[k] = {};
465
+ if (i) t = hasOwn ? t[k] : t[k] = Object.create(null);
444
466
  k = key[i];
445
- if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) throw new TomlError("trying to redefine an already defined value", {
446
- toml: ctx.s,
447
- ptr: p
448
- });
449
- if (!hasOwn && k === "__proto__") Object.defineProperty(t, k, {
467
+ if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) TomlError.x("trying to redefine an already defined value", ctx, errPtr);
468
+ let unsafe = k === "__proto__";
469
+ if (ctx.uk && (unsafe || k === "constructor")) {
470
+ t = ctx.uk !== 1 && TomlError.x("document contains an unsafe property", ctx, errPtr);
471
+ break;
472
+ }
473
+ if (!hasOwn && unsafe) Object.defineProperty(t, k, {
450
474
  enumerable: true,
451
475
  configurable: true,
452
476
  writable: true
453
477
  });
454
478
  }
455
- if (hasOwn) throw new TomlError("trying to redefine an already defined value", {
456
- toml: ctx.s,
457
- ptr: ctx.p
458
- });
459
- let value = extractValue(ctx, 125, integersAsBigInt);
460
- seen.add(t[k] = value);
479
+ if (hasOwn) TomlError.x("trying to redefine an already defined value", ctx, errPtr);
480
+ skipVoid(ctx, true, true);
481
+ let value = extractValue(ctx, 125);
482
+ if (t && typeof (t[k] = value) === "object") seen.add(value);
461
483
  skipVoid(ctx);
462
484
  if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) return res;
463
- if (c !== 44) throw new TomlError("expected comma or end of structure", {
464
- toml: ctx.s,
465
- ptr: ctx.p - 1
466
- });
485
+ if (c !== 44) TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
467
486
  }
468
- throw new TomlError("unfinished table encountered", {
469
- toml: ctx.s,
470
- ptr: ctx.p
471
- });
487
+ TomlError.x("unfinished table", ctx, startPtr);
472
488
  }
473
489
  /** @internal */
474
- function parseArray(ctx, integersAsBigInt) {
490
+ function parseArray(ctx) {
491
+ let startPtr = ctx.p++;
475
492
  let res = [];
476
493
  let c;
477
- ctx.p++;
478
494
  while (ctx.p < ctx.s.length) {
479
495
  skipVoid(ctx);
480
496
  if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
481
497
  ctx.p++;
482
498
  return res;
483
499
  }
484
- res.push(extractValue(ctx, 93, integersAsBigInt));
500
+ res.push(extractValue(ctx, 93));
485
501
  skipVoid(ctx);
486
502
  if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) return res;
487
- if (c !== 44) throw new TomlError("expected comma or end of structure", {
488
- toml: ctx.s,
489
- ptr: ctx.p - 1
490
- });
503
+ if (c !== 44) TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
491
504
  }
492
- throw new TomlError("unfinished array encountered", {
493
- toml: ctx.s,
494
- ptr: ctx.p
495
- });
505
+ TomlError.x("unfinished array", ctx, startPtr);
496
506
  }
497
507
  //#endregion
498
508
  //#region src/parse.ts
499
- function peekTable(key, table, meta, type) {
509
+ function peekTable(ctx, key, table, meta, type) {
500
510
  let t = table;
501
511
  let m = meta;
502
512
  let k;
@@ -504,7 +514,7 @@ function peekTable(key, table, meta, type) {
504
514
  let state;
505
515
  for (let i = 0; i < key.length; i++) {
506
516
  if (i) {
507
- t = hasOwn ? t[k] : t[k] = {};
517
+ t = hasOwn ? t[k] : t[k] = Object.create(null);
508
518
  m = (state = m[k]).c;
509
519
  if (type === 0 && (state.t === 1 || state.t === 2)) return null;
510
520
  if (state.t === 2) {
@@ -516,7 +526,9 @@ function peekTable(key, table, meta, type) {
516
526
  k = key[i];
517
527
  if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) return null;
518
528
  if (!hasOwn) {
519
- if (k === "__proto__") {
529
+ let unsafe = k === "__proto__";
530
+ if (ctx.uk && (unsafe || k === "constructor")) return false;
531
+ if (unsafe) {
520
532
  Object.defineProperty(t, k, {
521
533
  enumerable: true,
522
534
  configurable: true,
@@ -532,7 +544,7 @@ function peekTable(key, table, meta, type) {
532
544
  t: i < key.length - 1 && type === 2 ? 3 : type,
533
545
  d: false,
534
546
  i: 0,
535
- c: {}
547
+ c: Object.create(null)
536
548
  };
537
549
  }
538
550
  }
@@ -543,17 +555,17 @@ function peekTable(key, table, meta, type) {
543
555
  state.d = true;
544
556
  t[k] = [];
545
557
  }
546
- t[k].push(t = {});
558
+ t[k].push(t = Object.create(null));
547
559
  state.c[state.i++] = state = {
548
560
  t: 1,
549
561
  d: false,
550
562
  i: 0,
551
- c: {}
563
+ c: Object.create(null)
552
564
  };
553
565
  }
554
566
  if (state.d) return null;
555
567
  state.d = true;
556
- if (type === 1) t = hasOwn ? t[k] : t[k] = {};
568
+ if (type === 1) t = hasOwn ? t[k] : t[k] = Object.create(null);
557
569
  else if (type === 0 && hasOwn) return null;
558
570
  return [
559
571
  k,
@@ -561,51 +573,54 @@ function peekTable(key, table, meta, type) {
561
573
  state.c
562
574
  ];
563
575
  }
564
- function parse(toml, { maxDepth = 1e3, integersAsBigInt } = {}) {
576
+ function validateTablePeek(ctx, peek, ptr) {
577
+ if (peek === null || ctx.uk === 2) TomlError.x(peek === null ? "trying to redefine an already defined table or value" : "document contains an unsafe property", ctx, ptr);
578
+ }
579
+ function parse(toml, options = {}) {
565
580
  let ctx = {
566
581
  s: toml,
567
582
  p: 0,
568
- d: maxDepth
583
+ d: options.maxDepth ?? 1e3,
584
+ bi: options.integersAsBigInt ?? false,
585
+ ld: options.useLegacyDate ?? true,
586
+ uk: options.unsafeKeyBehaviour === "throw" ? 2 : options.unsafeKeyBehaviour === "drop" ? 1 : 0
569
587
  };
570
- let res = {};
571
- let meta = {};
588
+ let res = Object.create(null);
589
+ let meta = Object.create(null);
572
590
  let tmp;
591
+ let skipping = false;
573
592
  let tbl = res;
574
593
  let m = meta;
594
+ if (toml.charCodeAt(0) === 65279) ctx.p++;
575
595
  skipVoid(ctx);
576
596
  while (ctx.p < toml.length) {
577
597
  if (toml.charCodeAt(ctx.p) === 91) {
578
598
  let isTableArray = toml.charCodeAt(++ctx.p) === 91;
579
599
  tmp = ctx.p += +isTableArray;
580
- let k = parseKey(ctx, "]");
600
+ skipping = false;
601
+ let k = parseKey(ctx, 93);
581
602
  if (isTableArray) {
582
- if (toml.charCodeAt(ctx.p - 1) !== 93) throw new TomlError("expected end of table declaration", {
583
- toml,
584
- ptr: ctx.p - 1
585
- });
603
+ if (toml.charCodeAt(ctx.p) !== 93) TomlError.x("expected end of table array declaration", ctx);
586
604
  ctx.p++;
587
605
  }
588
- let p = peekTable(k, res, meta, isTableArray ? 2 : 1);
589
- if (!p) throw new TomlError("trying to redefine an already defined table or value", {
590
- toml,
591
- ptr: tmp
592
- });
593
- m = p[2];
594
- tbl = p[1];
606
+ let p = peekTable(ctx, k, res, meta, isTableArray ? 2 : 1);
607
+ if (!p) {
608
+ validateTablePeek(ctx, p, tmp);
609
+ skipping = true;
610
+ } else {
611
+ m = p[2];
612
+ tbl = p[1];
613
+ }
595
614
  } else {
596
615
  tmp = ctx.p;
597
- let p = peekTable(parseKey(ctx), tbl, m, 0);
598
- if (!p) throw new TomlError("trying to redefine an already defined table or value", {
599
- toml,
600
- ptr: tmp
601
- });
602
- p[1][p[0]] = extractValue(ctx, void 0, integersAsBigInt);
616
+ let p = peekTable(ctx, parseKey(ctx), tbl, m, 0);
617
+ if (!p && !skipping) validateTablePeek(ctx, p, tmp);
618
+ skipVoid(ctx, true, true);
619
+ let v = extractValue(ctx, void 0);
620
+ if (p && !skipping) p[1][p[0]] = v;
603
621
  }
604
622
  skipVoid(ctx, true);
605
- if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && tmp !== 13) throw new TomlError("each key-value declaration must be followed by an end-of-line", {
606
- toml,
607
- ptr: ctx.p
608
- });
623
+ if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && (tmp !== 13 || toml.charCodeAt(ctx.p + 1) !== 10)) TomlError.x("each key-value declaration must be followed by an end-of-line", ctx);
609
624
  skipVoid(ctx);
610
625
  }
611
626
  return res;
@@ -613,12 +628,20 @@ function parse(toml, { maxDepth = 1e3, integersAsBigInt } = {}) {
613
628
  //#endregion
614
629
  //#region src/stringify.ts
615
630
  let BARE_KEY = /^[a-z0-9-_]+$/i;
631
+ let HAS_WELLFORMED = !!"".isWellFormed;
616
632
  function extendedTypeOf(obj) {
617
633
  let type = typeof obj;
618
634
  if (type === "object") {
619
635
  if (Array.isArray(obj)) return "array";
620
- if (typeof obj?.getUTCDate === "function" && obj instanceof Date) return "date";
621
- if (globalThis.Temporal && typeof obj?.since === "function" && (obj instanceof Temporal.Instant || obj instanceof Temporal.PlainDate || obj instanceof Temporal.PlainDateTime || obj instanceof Temporal.PlainTime || obj instanceof Temporal.ZonedDateTime)) return "temporal";
636
+ if (typeof obj.getUTCDate === "function" && obj instanceof Date) return "date";
637
+ if (globalThis.Temporal) {
638
+ if (obj.until) {
639
+ if (obj instanceof Temporal.ZonedDateTime) return "temporal/tz+uc";
640
+ if (obj instanceof Temporal.PlainDateTime || obj instanceof Temporal.PlainDate) return "temporal/uc";
641
+ if (obj instanceof Temporal.PlainTime || obj instanceof Temporal.Instant) return "temporal";
642
+ if (obj instanceof Temporal.PlainYearMonth) return "temporal/x";
643
+ } else if (obj.toPlainDate && obj instanceof Temporal.PlainMonthDay || obj.negated && obj instanceof Temporal.Duration) return "temporal/x";
644
+ }
622
645
  }
623
646
  return type;
624
647
  }
@@ -626,16 +649,18 @@ function isArrayOfTables(obj) {
626
649
  for (let i = 0; i < obj.length; i++) if (extendedTypeOf(obj[i]) !== "object") return false;
627
650
  return obj.length != 0;
628
651
  }
652
+ function formatWellFormedStringUnchecked(s) {
653
+ return JSON.stringify(s).replaceAll("", "\\u007f");
654
+ }
629
655
  function formatString(s) {
630
- return JSON.stringify(s).replace(/\x7f/g, "\\u007f");
656
+ return formatWellFormedStringUnchecked(HAS_WELLFORMED ? s.toWellFormed() : s);
631
657
  }
632
- function stringifyTemporal(temporal) {
633
- return temporal.toString({
634
- calendarName: "never",
635
- timeZoneName: "never"
636
- });
658
+ function formatKey(s) {
659
+ if (BARE_KEY.test(s)) return s;
660
+ if (HAS_WELLFORMED && !s.isWellFormed()) throw new RangeError("key contains illegal lone surrogates");
661
+ return formatWellFormedStringUnchecked(s);
637
662
  }
638
- function stringifyValue(val, type, depth, numberAsFloat) {
663
+ function stringifyValue(val, type, depth, numberAsFloat, strictTemporal) {
639
664
  if (depth === 0) throw new Error("Could not stringify the object: maximum object depth exceeded");
640
665
  switch (type) {
641
666
  case "number":
@@ -644,49 +669,59 @@ function stringifyValue(val, type, depth, numberAsFloat) {
644
669
  if (val === -Infinity) return "-inf";
645
670
  if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val))) return val.toFixed(1);
646
671
  case "bigint":
647
- case "boolean": return val.toString();
672
+ case "boolean":
673
+ case "temporal": return val.toString();
648
674
  case "string": return formatString(val);
649
675
  case "date":
650
676
  if (isNaN(val.getTime())) throw new TypeError("cannot serialize invalid date");
651
677
  return val.toISOString();
652
- case "object": return stringifyInlineTable(val, depth, numberAsFloat);
653
- case "array": return stringifyArray(val, depth, numberAsFloat);
654
- case "temporal": return stringifyTemporal(val);
678
+ case "object": return stringifyInlineTable(val, depth, numberAsFloat, strictTemporal);
679
+ case "array": return stringifyArray(val, depth, numberAsFloat, strictTemporal);
680
+ case "temporal/tz+uc": if (strictTemporal) {
681
+ let tz = val.timeZoneId;
682
+ let tzc = tz.charCodeAt(0);
683
+ if (tzc !== 43 && tzc !== 45 && (tzc !== 85 && tzc !== 71 && tzc !== 90 && tzc !== 69 || tz !== "UTC" && tz !== "UCT" && tz !== "Universal" && tz !== "Zulu" && !tz.startsWith("GMT") && tz !== "Greenwich" && !tz.startsWith("Etc/"))) throw new TypeError("Temporal objects with an IANA timezone are not allowed in Temporal strict mode");
684
+ }
685
+ case "temporal/uc":
686
+ if (strictTemporal && val.calendarId !== "iso8601") throw new TypeError("Temporal objects with a non-default calendar are not allowed in Temporal strict mode");
687
+ return val.toString({
688
+ calendarName: "never",
689
+ timeZoneName: "never"
690
+ });
691
+ case "temporal/x": throw new TypeError("Unsupported " + val[Symbol.toStringTag]);
655
692
  }
656
693
  }
657
- function stringifyInlineTable(obj, depth, numberAsFloat) {
694
+ function stringifyInlineTable(obj, depth, numberAsFloat, strictTemporal) {
658
695
  let keys = Object.keys(obj);
659
696
  if (keys.length === 0) return "{}";
660
697
  let res = "{ ";
661
698
  for (let i = 0; i < keys.length; i++) {
662
699
  let k = keys[i];
663
700
  if (i) res += ", ";
664
- res += BARE_KEY.test(k) ? k : formatString(k);
665
- res += " = ";
666
- res += stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat);
701
+ res += formatKey(k) + " = " + stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat, strictTemporal);
667
702
  }
668
703
  return res + " }";
669
704
  }
670
- function stringifyArray(array, depth, numberAsFloat) {
705
+ function stringifyArray(array, depth, numberAsFloat, strictTemporal) {
671
706
  if (array.length === 0) return "[]";
672
707
  let res = "[ ";
673
708
  for (let i = 0; i < array.length; i++) {
674
709
  if (i) res += ", ";
675
710
  if (array[i] === null || array[i] === void 0) throw new TypeError("arrays cannot contain null or undefined values");
676
- res += stringifyValue(array[i], extendedTypeOf(array[i]), depth - 1, numberAsFloat);
711
+ res += stringifyValue(array[i], extendedTypeOf(array[i]), depth - 1, numberAsFloat, strictTemporal);
677
712
  }
678
713
  return res + " ]";
679
714
  }
680
- function stringifyArrayTable(array, key, depth, numberAsFloat) {
715
+ function stringifyArrayTable(array, key, depth, numberAsFloat, strictTemporal) {
681
716
  if (depth === 0) throw new Error("Could not stringify the object: maximum object depth exceeded");
682
717
  let res = "";
683
718
  for (let i = 0; i < array.length; i++) {
684
719
  res += `${res && "\n"}[[${key}]]\n`;
685
- res += stringifyTable(0, array[i], key, depth, numberAsFloat);
720
+ res += stringifyTable(0, array[i], key, depth, numberAsFloat, strictTemporal);
686
721
  }
687
722
  return res;
688
723
  }
689
- function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat) {
724
+ function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat, strictTemporal) {
690
725
  if (depth === 0) throw new Error("Could not stringify the object: maximum object depth exceeded");
691
726
  let preamble = "";
692
727
  let tables = "";
@@ -696,15 +731,15 @@ function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat) {
696
731
  if (obj[k] !== null && obj[k] !== void 0) {
697
732
  let type = extendedTypeOf(obj[k]);
698
733
  if (type === "symbol" || type === "function") throw new TypeError(`cannot serialize values of type '${type}'`);
699
- let key = BARE_KEY.test(k) ? k : formatString(k);
700
- if (type === "array" && isArrayOfTables(obj[k])) tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat);
734
+ let key = formatKey(k);
735
+ if (type === "array" && isArrayOfTables(obj[k])) tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat, strictTemporal);
701
736
  else if (type === "object") {
702
737
  let tblKey = prefix ? `${prefix}.${key}` : key;
703
- tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat);
738
+ tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat, strictTemporal);
704
739
  } else {
705
740
  preamble += key;
706
741
  preamble += " = ";
707
- preamble += stringifyValue(obj[k], type, depth, numberAsFloat);
742
+ preamble += stringifyValue(obj[k], type, depth, numberAsFloat, strictTemporal);
708
743
  preamble += "\n";
709
744
  }
710
745
  }
@@ -712,14 +747,15 @@ function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat) {
712
747
  if (tableKey && (preamble || !tables)) preamble = preamble ? `[${tableKey}]\n${preamble}` : `[${tableKey}]`;
713
748
  return preamble && tables ? `${preamble}\n${tables}` : preamble || tables;
714
749
  }
715
- function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false } = {}) {
750
+ function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false, strictTemporal = false } = {}) {
716
751
  if (extendedTypeOf(obj) !== "object") throw new TypeError("stringify can only be called with an object");
717
- let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat);
752
+ let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat, strictTemporal);
718
753
  if (str[str.length - 1] !== "\n") return str + "\n";
719
754
  return str;
720
755
  }
721
756
  //#endregion
722
757
  //#region src/index.ts
758
+ /** @deprecated use `import * as ... from 'smol-toml'` instead */
723
759
  var src_default = {
724
760
  parse,
725
761
  stringify,