@node-core/utils 7.1.0 → 7.2.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.
- package/components/metadata.js +2 -1
- package/lib/ci/build-types/test_build.js +3 -3
- package/lib/ci/failure_aggregator.js +2 -2
- package/lib/ci/run_ci.js +3 -2
- package/lib/cli.js +6 -6
- package/lib/figures.js +6 -6
- package/lib/prepare_security.js +20 -21
- package/lib/request.js +1 -1
- package/lib/update-v8/backport.js +3 -4
- package/lib/utils.js +4 -2
- package/lib/verbosity.js +2 -4
- package/node_modules/@listr2/{prompt-adapter-enquirer → prompt-adapter-inquirer}/README.md +4 -4
- package/node_modules/@listr2/prompt-adapter-inquirer/dist/index.d.mts +21 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/dist/index.mjs +46 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/LICENSE +22 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/index.d.ts +2 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/index.js +2 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/inquirer.d.ts +35 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/inquirer.js +1 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/utils.d.ts +34 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/utils.js +2 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/package.json +88 -0
- package/node_modules/@listr2/{prompt-adapter-enquirer → prompt-adapter-inquirer}/package.json +25 -20
- package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/base.d.ts +48 -3
- package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/base.js +58 -19
- package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/package.json +1 -1
- package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/readme.md +36 -1
- package/node_modules/ansi-regex/index.js +9 -4
- package/node_modules/ansi-regex/package.json +1 -1
- package/node_modules/ansi-regex/readme.md +6 -0
- package/node_modules/ansi-styles/index.d.ts +12 -12
- package/node_modules/ansi-styles/index.js +3 -3
- package/node_modules/ansi-styles/package.json +4 -4
- package/node_modules/cli-truncate/index.d.ts +3 -3
- package/node_modules/cli-truncate/index.js +40 -14
- package/node_modules/cli-truncate/node_modules/string-width/index.js +133 -15
- package/node_modules/cli-truncate/node_modules/string-width/package.json +4 -4
- package/node_modules/cli-truncate/node_modules/string-width/readme.md +1 -1
- package/node_modules/cli-truncate/package.json +7 -7
- package/node_modules/cli-truncate/readme.md +2 -3
- package/node_modules/ghauth/.github/dependabot.yml +11 -3
- package/node_modules/ghauth/.github/workflows/depsound.yml +33 -0
- package/node_modules/ghauth/.github/workflows/test-and-release.yml +4 -4
- package/node_modules/ghauth/CHANGELOG.md +60 -0
- package/node_modules/ghauth/package.json +30 -6
- package/node_modules/js-yaml/README.md +20 -187
- package/node_modules/js-yaml/dist/browser/js-yaml.esm.min.mjs +1008 -946
- package/node_modules/js-yaml/dist/browser/js-yaml.esm.min.mjs.map +1 -1
- package/node_modules/js-yaml/dist/browser/js-yaml.umd.min.js +29 -23
- package/node_modules/js-yaml/dist/browser/js-yaml.umd.min.js.map +1 -1
- package/node_modules/js-yaml/dist/js-yaml.cjs.js +1043 -583
- package/node_modules/js-yaml/dist/js-yaml.cjs.js.map +1 -1
- package/node_modules/js-yaml/dist/js-yaml.d.ts +877 -133
- package/node_modules/js-yaml/dist/js-yaml.mjs +995 -556
- package/node_modules/js-yaml/dist/js-yaml.mjs.map +1 -1
- package/node_modules/js-yaml/package.json +8 -7
- package/node_modules/listr2/dist/{index.d.cts → index.d.mts} +90 -60
- package/node_modules/listr2/dist/{index.js → index.mjs} +496 -373
- package/node_modules/listr2/node_modules/string-width/index.d.ts +39 -0
- package/node_modules/listr2/node_modules/string-width/index.js +207 -0
- package/node_modules/listr2/node_modules/string-width/package.json +65 -0
- package/node_modules/listr2/node_modules/string-width/readme.md +66 -0
- package/node_modules/listr2/node_modules/wrap-ansi/index.d.ts +1 -1
- package/node_modules/listr2/node_modules/wrap-ansi/index.js +544 -116
- package/node_modules/listr2/node_modules/wrap-ansi/package.json +10 -13
- package/node_modules/listr2/node_modules/wrap-ansi/readme.md +2 -0
- package/node_modules/listr2/package.json +16 -19
- package/node_modules/log-update/index.d.ts +64 -1
- package/node_modules/log-update/index.js +268 -18
- package/node_modules/log-update/node_modules/string-width/index.d.ts +39 -0
- package/node_modules/log-update/node_modules/string-width/index.js +207 -0
- package/node_modules/log-update/node_modules/string-width/package.json +65 -0
- package/node_modules/log-update/node_modules/string-width/readme.md +66 -0
- package/node_modules/log-update/node_modules/wrap-ansi/index.d.ts +1 -1
- package/node_modules/log-update/node_modules/wrap-ansi/index.js +544 -116
- package/node_modules/log-update/node_modules/wrap-ansi/package.json +10 -13
- package/node_modules/log-update/node_modules/wrap-ansi/readme.md +2 -0
- package/node_modules/log-update/package.json +14 -12
- package/node_modules/log-update/readme.md +61 -0
- package/node_modules/slice-ansi/index.d.ts +2 -2
- package/node_modules/slice-ansi/index.js +260 -112
- package/node_modules/slice-ansi/package.json +10 -9
- package/node_modules/slice-ansi/readme.md +3 -2
- package/node_modules/slice-ansi/tokenize-ansi.js +752 -0
- package/node_modules/smol-toml/README.md +205 -191
- package/node_modules/smol-toml/dist/date.d.ts +0 -1
- package/node_modules/smol-toml/dist/date.js +0 -1
- package/node_modules/smol-toml/dist/error.d.ts +0 -1
- package/node_modules/smol-toml/dist/error.js +0 -1
- package/node_modules/smol-toml/dist/extract.js +32 -65
- package/node_modules/smol-toml/dist/index.cjs +302 -288
- package/node_modules/smol-toml/dist/index.d.ts +0 -1
- package/node_modules/smol-toml/dist/index.js +0 -1
- package/node_modules/smol-toml/dist/parse.d.ts +1 -3
- package/node_modules/smol-toml/dist/parse.js +22 -21
- package/node_modules/smol-toml/dist/primitive.js +75 -76
- package/node_modules/smol-toml/dist/stringify.d.ts +0 -1
- package/node_modules/smol-toml/dist/stringify.js +43 -30
- package/node_modules/smol-toml/dist/struct.js +90 -93
- package/node_modules/smol-toml/dist/util.d.ts +1 -1
- package/node_modules/smol-toml/dist/util.js +36 -39
- package/node_modules/smol-toml/package.json +6 -6
- package/node_modules/strip-ansi/index.js +5 -0
- package/node_modules/strip-ansi/package.json +5 -5
- package/package.json +3 -9
- package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.cjs +0 -127
- package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.d.cts +0 -152
- package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.d.ts +0 -152
- package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.js +0 -92
- package/node_modules/chalk/package.json +0 -92
- package/node_modules/chalk/readme.md +0 -331
- package/node_modules/chalk/source/index.d.ts +0 -437
- package/node_modules/chalk/source/index.js +0 -261
- package/node_modules/chalk/source/utilities.js +0 -33
- package/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +0 -299
- package/node_modules/chalk/source/vendor/ansi-styles/index.js +0 -261
- package/node_modules/chalk/source/vendor/supports-color/browser.d.ts +0 -1
- package/node_modules/chalk/source/vendor/supports-color/browser.js +0 -32
- package/node_modules/chalk/source/vendor/supports-color/index.d.ts +0 -55
- package/node_modules/chalk/source/vendor/supports-color/index.js +0 -206
- package/node_modules/colorette/LICENSE.md +0 -7
- package/node_modules/colorette/README.md +0 -134
- package/node_modules/colorette/index.cjs +0 -218
- package/node_modules/colorette/index.d.ts +0 -93
- package/node_modules/colorette/index.js +0 -150
- package/node_modules/colorette/package.json +0 -40
- package/node_modules/eventemitter3/LICENSE +0 -21
- package/node_modules/eventemitter3/README.md +0 -94
- package/node_modules/eventemitter3/dist/eventemitter3.esm.js +0 -347
- package/node_modules/eventemitter3/dist/eventemitter3.esm.min.js +0 -1
- package/node_modules/eventemitter3/dist/eventemitter3.esm.min.js.map +0 -1
- package/node_modules/eventemitter3/dist/eventemitter3.umd.js +0 -355
- package/node_modules/eventemitter3/dist/eventemitter3.umd.min.js +0 -1
- package/node_modules/eventemitter3/dist/eventemitter3.umd.min.js.map +0 -1
- package/node_modules/eventemitter3/index.d.ts +0 -135
- package/node_modules/eventemitter3/index.js +0 -336
- package/node_modules/eventemitter3/index.mjs +0 -4
- package/node_modules/eventemitter3/package.json +0 -67
- package/node_modules/figures/index.d.ts +0 -279
- package/node_modules/figures/index.js +0 -292
- package/node_modules/figures/package.json +0 -49
- package/node_modules/figures/readme.md +0 -337
- package/node_modules/isexe/LICENSE.md +0 -55
- package/node_modules/isexe/README.md +0 -80
- package/node_modules/isexe/dist/commonjs/index.d.ts +0 -14
- package/node_modules/isexe/dist/commonjs/index.d.ts.map +0 -1
- package/node_modules/isexe/dist/commonjs/index.js +0 -56
- package/node_modules/isexe/dist/commonjs/index.js.map +0 -1
- package/node_modules/isexe/dist/commonjs/index.min.js +0 -2
- package/node_modules/isexe/dist/commonjs/index.min.js.map +0 -7
- package/node_modules/isexe/dist/commonjs/options.d.ts +0 -32
- package/node_modules/isexe/dist/commonjs/options.d.ts.map +0 -1
- package/node_modules/isexe/dist/commonjs/options.js +0 -3
- package/node_modules/isexe/dist/commonjs/options.js.map +0 -1
- package/node_modules/isexe/dist/commonjs/package.json +0 -3
- package/node_modules/isexe/dist/commonjs/posix.d.ts +0 -18
- package/node_modules/isexe/dist/commonjs/posix.d.ts.map +0 -1
- package/node_modules/isexe/dist/commonjs/posix.js +0 -67
- package/node_modules/isexe/dist/commonjs/posix.js.map +0 -1
- package/node_modules/isexe/dist/commonjs/win32.d.ts +0 -18
- package/node_modules/isexe/dist/commonjs/win32.d.ts.map +0 -1
- package/node_modules/isexe/dist/commonjs/win32.js +0 -63
- package/node_modules/isexe/dist/commonjs/win32.js.map +0 -1
- package/node_modules/isexe/dist/esm/index.d.ts +0 -14
- package/node_modules/isexe/dist/esm/index.d.ts.map +0 -1
- package/node_modules/isexe/dist/esm/index.js +0 -16
- package/node_modules/isexe/dist/esm/index.js.map +0 -1
- package/node_modules/isexe/dist/esm/index.min.js +0 -2
- package/node_modules/isexe/dist/esm/index.min.js.map +0 -7
- package/node_modules/isexe/dist/esm/options.d.ts +0 -32
- package/node_modules/isexe/dist/esm/options.d.ts.map +0 -1
- package/node_modules/isexe/dist/esm/options.js +0 -2
- package/node_modules/isexe/dist/esm/options.js.map +0 -1
- package/node_modules/isexe/dist/esm/package.json +0 -3
- package/node_modules/isexe/dist/esm/posix.d.ts +0 -18
- package/node_modules/isexe/dist/esm/posix.d.ts.map +0 -1
- package/node_modules/isexe/dist/esm/posix.js +0 -62
- package/node_modules/isexe/dist/esm/posix.js.map +0 -1
- package/node_modules/isexe/dist/esm/win32.d.ts +0 -18
- package/node_modules/isexe/dist/esm/win32.d.ts.map +0 -1
- package/node_modules/isexe/dist/esm/win32.js +0 -58
- package/node_modules/isexe/dist/esm/win32.js.map +0 -1
- package/node_modules/isexe/package.json +0 -78
- package/node_modules/listr2/dist/index.cjs +0 -2189
- package/node_modules/listr2/dist/index.d.ts +0 -1528
- package/node_modules/rfdc/.github/workflows/ci.yml +0 -21
- package/node_modules/rfdc/LICENSE +0 -15
- package/node_modules/rfdc/default.js +0 -3
- package/node_modules/rfdc/index.d.ts +0 -13
- package/node_modules/rfdc/index.js +0 -198
- package/node_modules/rfdc/index.test-d.ts +0 -13
- package/node_modules/rfdc/package.json +0 -73
- package/node_modules/rfdc/readme.md +0 -181
- package/node_modules/rfdc/test/index.js +0 -306
- package/node_modules/smol-toml/dist/date.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/date.js.map +0 -1
- package/node_modules/smol-toml/dist/error.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/error.js.map +0 -1
- package/node_modules/smol-toml/dist/extract.js.map +0 -1
- package/node_modules/smol-toml/dist/index.cjs.map +0 -1
- package/node_modules/smol-toml/dist/index.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/index.js.map +0 -1
- package/node_modules/smol-toml/dist/parse.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/parse.js.map +0 -1
- package/node_modules/smol-toml/dist/primitive.d.ts +0 -29
- package/node_modules/smol-toml/dist/primitive.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/primitive.js.map +0 -1
- package/node_modules/smol-toml/dist/stringify.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/stringify.js.map +0 -1
- package/node_modules/smol-toml/dist/struct.js.map +0 -1
- package/node_modules/smol-toml/dist/util.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/util.js.map +0 -1
- package/node_modules/smol-toml/src/date.ts +0 -152
- package/node_modules/smol-toml/src/error.ts +0 -77
- package/node_modules/smol-toml/src/extract.ts +0 -113
- package/node_modules/smol-toml/src/index.ts +0 -42
- package/node_modules/smol-toml/src/parse.ts +0 -184
- package/node_modules/smol-toml/src/primitive.ts +0 -249
- package/node_modules/smol-toml/src/stringify.ts +0 -191
- package/node_modules/smol-toml/src/struct.ts +0 -202
- package/node_modules/smol-toml/src/util.ts +0 -106
- package/node_modules/which/LICENSE +0 -15
- package/node_modules/which/README.md +0 -51
- package/node_modules/which/bin/which.js +0 -52
- package/node_modules/which/lib/index.js +0 -111
- package/node_modules/which/package.json +0 -52
- /package/node_modules/@listr2/{prompt-adapter-enquirer → prompt-adapter-inquirer}/LICENSE +0 -0
- /package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/index.d.ts +0 -0
- /package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/index.js +0 -0
- /package/node_modules/{chalk → ansi-escapes}/license +0 -0
- /package/node_modules/{figures → listr2/node_modules/string-width}/license +0 -0
- /package/node_modules/log-update/node_modules/{ansi-escapes → string-width}/license +0 -0
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
4
|
-
*
|
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
|
7
|
-
*
|
|
8
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
-
* list of conditions and the following disclaimer.
|
|
10
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
-
* this list of conditions and the following disclaimer in the
|
|
12
|
-
* documentation and/or other materials provided with the distribution.
|
|
13
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
14
|
-
* may be used to endorse or promote products derived from this software without
|
|
15
|
-
* specific prior written permission.
|
|
16
|
-
*
|
|
17
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
21
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
22
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
23
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
24
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
25
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import { TomlDate } from './date.js'
|
|
30
|
-
import { TomlError } from './error.js'
|
|
31
|
-
|
|
32
|
-
// let CTRL_REGEX = /[\x00-\x08\x0f-\x1f\x7f]/
|
|
33
|
-
let INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/
|
|
34
|
-
let FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/
|
|
35
|
-
let LEADING_ZERO = /^[+-]?0[0-9_]/
|
|
36
|
-
|
|
37
|
-
/** @internal */
|
|
38
|
-
export function parseString(str: string, ptr: number): [string, number] {
|
|
39
|
-
let c = str[ptr++]!
|
|
40
|
-
let first = c
|
|
41
|
-
let isLiteral = c === "'"
|
|
42
|
-
let isMultiline = c === str[ptr] && c === str[ptr + 1]
|
|
43
|
-
if (isMultiline) {
|
|
44
|
-
// Trim initial newline
|
|
45
|
-
if (str[ptr += 2] === '\n') ptr++
|
|
46
|
-
else if (str[ptr] === '\r' && str[ptr + 1] === '\n') ptr += 2
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/*
|
|
50
|
-
The fast path does not seem to bring significant performance gains, so it's commented out.
|
|
51
|
-
Kept for reference and/or future fafoing.
|
|
52
|
-
|
|
53
|
-
Without: spec 5.08 µs/iter 3.88 ipc (99.44% cache) 23.90 branch misses 28.61k cycles 111.01k instructions
|
|
54
|
-
5MB 115.73 ms/iter 2.51 ipc (98.36% cache) 3.12M branch misses 619.30M cycles 1.56G instructions
|
|
55
|
-
|
|
56
|
-
With: spec 5.09 µs/iter 3.90 ipc (99.46% cache) 24.42 branch misses 28.57k cycles 111.49k instructions
|
|
57
|
-
5MB 113.89 ms/iter 2.47 ipc (98.38% cache) 3.12M branch misses 611.94M cycles 1.51G instructions
|
|
58
|
-
|
|
59
|
-
if (c === "'") {
|
|
60
|
-
// Literal strings fast path - no transform needs to occur; just grab the str and that's it
|
|
61
|
-
let endPtr = str.indexOf(isMultiline ? "'''" : "'", ptr)
|
|
62
|
-
if (endPtr < 0) {
|
|
63
|
-
throw new TomlError("unfinished string literal", { toml: str, ptr })
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (isMultiline) {
|
|
67
|
-
// If the string ends with 4-5 quotes, then the first 1-2 are part of the string
|
|
68
|
-
if (str[endPtr + 3] === "'") endPtr++
|
|
69
|
-
if (str[endPtr + 3] === "'") endPtr++
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
let string = str.slice(ptr, endPtr)
|
|
73
|
-
if (CTRL_REGEX.test(string)) {
|
|
74
|
-
let match = string.match(CTRL_REGEX)!
|
|
75
|
-
throw new TomlError('control characters are not allowed in strings', { toml: str, ptr: ptr + (match.index ?? 0) })
|
|
76
|
-
}
|
|
77
|
-
return [string, endPtr + (isMultiline ? 3 : 1)]
|
|
78
|
-
}
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
|
-
let parsed = ''
|
|
82
|
-
let sliceStart = ptr
|
|
83
|
-
|
|
84
|
-
// states:
|
|
85
|
-
// 0 - decoding
|
|
86
|
-
// 1 - decoding escape
|
|
87
|
-
// 2 - whitespace escape (no newline encountered yet, must fail on non-whitespace)
|
|
88
|
-
// 3 - whitespace escape (newline encountered, allowed to transition back to normal decode)
|
|
89
|
-
let state = 0
|
|
90
|
-
for (let i = ptr; i < str.length; i++) {
|
|
91
|
-
c = str[i]!
|
|
92
|
-
|
|
93
|
-
// Deal with newlines first, since that simplifies control character checking and handling across all states
|
|
94
|
-
if (isMultiline && (c === '\n' || (c === '\r' && str[i + 1] === '\n'))) {
|
|
95
|
-
state = state && 3
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Control characters are banned in TOML, so we throw an error if we encounter them
|
|
99
|
-
else if ((c < '\x20' && c !== '\t') || c === '\x7f') {
|
|
100
|
-
throw new TomlError('control characters are not allowed in strings', {
|
|
101
|
-
toml: str,
|
|
102
|
-
ptr: i,
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// The string might terminate while we're parsing through a newline escape.
|
|
107
|
-
// It must have encountered a newline; otherwise, it'll simply fail in another branch.
|
|
108
|
-
else if ((!state || state === 3) && c === first && (!isMultiline || (str[i + 1] === first && str[i + 2] === first))) {
|
|
109
|
-
if (isMultiline) {
|
|
110
|
-
// If the string ends with 4-5 quotes, then the first 1-2 are part of the string
|
|
111
|
-
if (str[i + 3] === first) i++
|
|
112
|
-
if (str[i + 3] === first) i++
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return [
|
|
116
|
-
// If we're in a newline escape still, then there's nothing to add.
|
|
117
|
-
// Also try to avoid concat if there's nothing to add to parsed, or nothing has been added to parsed.
|
|
118
|
-
state ? parsed : parsed + str.slice(sliceStart, i),
|
|
119
|
-
i + (isMultiline ? 3 : 1),
|
|
120
|
-
]
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
else if (!state) {
|
|
124
|
-
if (!isLiteral && c === '\\') {
|
|
125
|
-
parsed += str.slice(sliceStart, (sliceStart = i))
|
|
126
|
-
state = 1
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
else if (state === 1) {
|
|
131
|
-
if (c === 'x' || c === 'u' || c === 'U') { // Unicode escape
|
|
132
|
-
let value = 0
|
|
133
|
-
let len = c === 'x' ? 2 : c === 'u' ? 4 : 8
|
|
134
|
-
for (let j = 0; j < len; j++, i++) {
|
|
135
|
-
let hex = str.charCodeAt(i + 1)
|
|
136
|
-
let digit =
|
|
137
|
-
/* 0-9 */ hex >= 0x30 && hex <= 0x39 ? hex - 0x30 :
|
|
138
|
-
/* A-F */ hex >= 0x41 && hex <= 0x46 ? hex - 0x41 + 10 :
|
|
139
|
-
/* a-f */ hex >= 0x61 && hex <= 0x66 ? hex - 0x61 + 10 : -1
|
|
140
|
-
|
|
141
|
-
if (digit < 0) throw new TomlError('invalid non-hex character in unicode escape', { toml: str, ptr: i + 1 })
|
|
142
|
-
value = (value << 4) | digit
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Because JS does bitwise on signed 32bit integers, all 0xfzzzzzzz values are actually seen as negative
|
|
146
|
-
if (value < 0 || value > 0x10ffff || (value >= 0xd800 && value <= 0xdfff)) {
|
|
147
|
-
throw new TomlError('invalid unicode escape', { toml: str, ptr: i })
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
parsed += String.fromCodePoint(value)
|
|
151
|
-
sliceStart = i + 1
|
|
152
|
-
state = 0
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
else if (c === ' ' || c === '\t') { // If it was a newline, it'd have been handled earlier
|
|
156
|
-
state = 2
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
else {
|
|
160
|
-
if (c === 'b') parsed += '\b'
|
|
161
|
-
else if (c === 't') parsed += '\t'
|
|
162
|
-
else if (c === 'n') parsed += '\n'
|
|
163
|
-
else if (c === 'f') parsed += '\f'
|
|
164
|
-
else if (c === 'r') parsed += '\r'
|
|
165
|
-
else if (c === 'e') parsed += '\x1b'
|
|
166
|
-
else if (c === '"') parsed += '"'
|
|
167
|
-
else if (c === '\\') parsed += '\\'
|
|
168
|
-
else throw new TomlError('unrecognized escape sequence', { toml: str, ptr: i })
|
|
169
|
-
sliceStart = i + 1
|
|
170
|
-
state = 0
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
else if (c !== ' ' && c !== '\t') {
|
|
175
|
-
if (state === 2) {
|
|
176
|
-
throw new TomlError('invalid escape: only line-ending whitespace may be escaped', {
|
|
177
|
-
toml: str,
|
|
178
|
-
ptr: sliceStart,
|
|
179
|
-
})
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// State cannot be zero, or we'd have branched earlier already.
|
|
183
|
-
// If it's a backslash, immediately transition to the escape state so it can be processed.
|
|
184
|
-
state = !isLiteral && c === '\\' ? 1 : 0
|
|
185
|
-
sliceStart = i
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
throw new TomlError('unfinished string', { toml: str, ptr })
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export type IntegersAsBigInt = undefined | boolean | 'asNeeded'
|
|
193
|
-
|
|
194
|
-
/** @internal */
|
|
195
|
-
export function parseValue(value: string, toml: string, ptr: number, integersAsBigInt: IntegersAsBigInt): boolean | number | bigint | TomlDate {
|
|
196
|
-
// Constant values
|
|
197
|
-
if (value === 'true') return true
|
|
198
|
-
if (value === 'false') return false
|
|
199
|
-
if (value === '-inf') return -Infinity
|
|
200
|
-
if (value === 'inf' || value === '+inf') return Infinity
|
|
201
|
-
if (value === 'nan' || value === '+nan' || value === '-nan') return NaN
|
|
202
|
-
|
|
203
|
-
// Avoid FP representation of -0
|
|
204
|
-
if (value === '-0') return integersAsBigInt ? 0n : 0
|
|
205
|
-
|
|
206
|
-
// Numbers
|
|
207
|
-
let isInt = INT_REGEX.test(value)
|
|
208
|
-
if (isInt || FLOAT_REGEX.test(value)) {
|
|
209
|
-
if (LEADING_ZERO.test(value)) {
|
|
210
|
-
throw new TomlError('leading zeroes are not allowed', {
|
|
211
|
-
toml: toml,
|
|
212
|
-
ptr: ptr,
|
|
213
|
-
})
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
value = value.replace(/_/g, '')
|
|
217
|
-
let numeric: number | bigint = +value
|
|
218
|
-
|
|
219
|
-
if (isNaN(numeric)) {
|
|
220
|
-
throw new TomlError('invalid number', {
|
|
221
|
-
toml: toml,
|
|
222
|
-
ptr: ptr,
|
|
223
|
-
})
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (isInt) {
|
|
227
|
-
if ((isInt = !Number.isSafeInteger(numeric)) && !integersAsBigInt) {
|
|
228
|
-
throw new TomlError('integer value cannot be represented losslessly', {
|
|
229
|
-
toml: toml,
|
|
230
|
-
ptr: ptr,
|
|
231
|
-
})
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (isInt || integersAsBigInt === true) numeric = BigInt(value)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return numeric
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const date = new TomlDate(value)
|
|
241
|
-
if (!date.isValid()) {
|
|
242
|
-
throw new TomlError('invalid value', {
|
|
243
|
-
toml: toml,
|
|
244
|
-
ptr: ptr,
|
|
245
|
-
})
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return date
|
|
249
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
4
|
-
*
|
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
|
7
|
-
*
|
|
8
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
-
* list of conditions and the following disclaimer.
|
|
10
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
-
* this list of conditions and the following disclaimer in the
|
|
12
|
-
* documentation and/or other materials provided with the distribution.
|
|
13
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
14
|
-
* may be used to endorse or promote products derived from this software without
|
|
15
|
-
* specific prior written permission.
|
|
16
|
-
*
|
|
17
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
21
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
22
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
23
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
24
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
25
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
let BARE_KEY = /^[a-z0-9-_]+$/i
|
|
30
|
-
|
|
31
|
-
type ExtendedType = ReturnType<typeof extendedTypeOf>
|
|
32
|
-
function extendedTypeOf(obj: any) {
|
|
33
|
-
let type = typeof obj
|
|
34
|
-
if (type === 'object') {
|
|
35
|
-
if (Array.isArray(obj)) return 'array'
|
|
36
|
-
if (obj instanceof Date) return 'date'
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return type
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function isArrayOfTables(obj: any[]) {
|
|
43
|
-
for (let i = 0; i < obj.length; i++) {
|
|
44
|
-
if (extendedTypeOf(obj[i]) !== 'object') return false
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return obj.length != 0
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function formatString(s: string) {
|
|
51
|
-
return JSON.stringify(s).replace(/\x7f/g, '\\u007f')
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function stringifyValue(val: any, type: ExtendedType, depth: number, numberAsFloat: boolean) {
|
|
55
|
-
if (depth === 0) {
|
|
56
|
-
throw new Error('Could not stringify the object: maximum object depth exceeded')
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (type === 'number') {
|
|
60
|
-
if (isNaN(val)) return 'nan'
|
|
61
|
-
if (val === Infinity) return 'inf'
|
|
62
|
-
if (val === -Infinity) return '-inf'
|
|
63
|
-
if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val))) return val.toFixed(1)
|
|
64
|
-
return val.toString()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (type === 'bigint' || type === 'boolean') {
|
|
68
|
-
return val.toString()
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (type === 'string') {
|
|
72
|
-
return formatString(val)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (type === 'date') {
|
|
76
|
-
if (isNaN(val.getTime())) {
|
|
77
|
-
throw new TypeError('cannot serialize invalid date')
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return val.toISOString()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (type === 'object') {
|
|
84
|
-
return stringifyInlineTable(val, depth, numberAsFloat)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (type === 'array') {
|
|
88
|
-
return stringifyArray(val, depth, numberAsFloat)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function stringifyInlineTable(obj: any, depth: number, numberAsFloat: boolean) {
|
|
93
|
-
let keys = Object.keys(obj)
|
|
94
|
-
if (keys.length === 0) return '{}'
|
|
95
|
-
|
|
96
|
-
let res = '{ '
|
|
97
|
-
for (let i = 0; i < keys.length; i++) {
|
|
98
|
-
let k = keys[i]!
|
|
99
|
-
if (i) res += ', '
|
|
100
|
-
|
|
101
|
-
res += BARE_KEY.test(k) ? k : formatString(k)
|
|
102
|
-
res += ' = '
|
|
103
|
-
res += stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return res + ' }'
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function stringifyArray(array: any[], depth: number, numberAsFloat: boolean) {
|
|
110
|
-
if (array.length === 0) return '[]'
|
|
111
|
-
|
|
112
|
-
let res = '[ '
|
|
113
|
-
for (let i = 0; i < array.length; i++) {
|
|
114
|
-
if (i) res += ', '
|
|
115
|
-
if (array[i] === null || array[i] === void 0) {
|
|
116
|
-
throw new TypeError('arrays cannot contain null or undefined values')
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
res += stringifyValue(array[i], extendedTypeOf(array[i]), depth - 1, numberAsFloat)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return res + ' ]'
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function stringifyArrayTable(array: any[], key: string, depth: number, numberAsFloat: boolean) {
|
|
126
|
-
if (depth === 0) {
|
|
127
|
-
throw new Error('Could not stringify the object: maximum object depth exceeded')
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
let res = ''
|
|
131
|
-
for (let i = 0; i < array.length; i++) {
|
|
132
|
-
res += `${res && '\n'}[[${key}]]\n`
|
|
133
|
-
res += stringifyTable(0, array[i], key, depth, numberAsFloat)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return res
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function stringifyTable(tableKey: string | 0, obj: any, prefix: string, depth: number, numberAsFloat: boolean) {
|
|
140
|
-
if (depth === 0) {
|
|
141
|
-
throw new Error('Could not stringify the object: maximum object depth exceeded')
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
let preamble = ''
|
|
145
|
-
let tables = ''
|
|
146
|
-
|
|
147
|
-
let keys = Object.keys(obj)
|
|
148
|
-
for (let i = 0; i < keys.length; i++) {
|
|
149
|
-
let k = keys[i]!
|
|
150
|
-
if (obj[k] !== null && obj[k] !== void 0) {
|
|
151
|
-
let type: ExtendedType = extendedTypeOf(obj[k])
|
|
152
|
-
if (type === 'symbol' || type === 'function') {
|
|
153
|
-
throw new TypeError(`cannot serialize values of type '${type}'`)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
let key = BARE_KEY.test(k) ? k : formatString(k)
|
|
157
|
-
|
|
158
|
-
if (type === 'array' && isArrayOfTables(obj[k])) {
|
|
159
|
-
tables += (tables && '\n') + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat)
|
|
160
|
-
} else if (type === 'object') {
|
|
161
|
-
let tblKey = prefix ? `${prefix}.${key}` : key
|
|
162
|
-
tables += (tables && '\n') + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat)
|
|
163
|
-
} else {
|
|
164
|
-
preamble += key
|
|
165
|
-
preamble += ' = '
|
|
166
|
-
preamble += stringifyValue(obj[k], type, depth, numberAsFloat)
|
|
167
|
-
preamble += '\n'
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (tableKey && (preamble || !tables)) // Create table only if necessary
|
|
173
|
-
preamble = preamble ? `[${tableKey}]\n${preamble}` : `[${tableKey}]`
|
|
174
|
-
|
|
175
|
-
return preamble && tables
|
|
176
|
-
? `${preamble}\n${tables}`
|
|
177
|
-
: preamble || tables
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export function stringify (
|
|
181
|
-
obj: any,
|
|
182
|
-
{ maxDepth = 1000, numbersAsFloat = false }: { maxDepth?: number, numbersAsFloat?: boolean } = {},
|
|
183
|
-
) {
|
|
184
|
-
if (extendedTypeOf(obj) !== 'object') {
|
|
185
|
-
throw new TypeError('stringify can only be called with an object')
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
let str = stringifyTable(0, obj, '', maxDepth, numbersAsFloat)
|
|
189
|
-
if (str[str.length - 1] !== '\n') return str + '\n'
|
|
190
|
-
return str
|
|
191
|
-
}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
3
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
4
|
-
*
|
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
|
7
|
-
*
|
|
8
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
-
* list of conditions and the following disclaimer.
|
|
10
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
-
* this list of conditions and the following disclaimer in the
|
|
12
|
-
* documentation and/or other materials provided with the distribution.
|
|
13
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
14
|
-
* may be used to endorse or promote products derived from this software without
|
|
15
|
-
* specific prior written permission.
|
|
16
|
-
*
|
|
17
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
21
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
22
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
23
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
24
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
25
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import { type IntegersAsBigInt, parseString } from './primitive.js'
|
|
30
|
-
import { extractValue } from './extract.js'
|
|
31
|
-
import { indexOfNewline, skipComment, skipVoid, type TomlTable, type TomlValue } from './util.js'
|
|
32
|
-
import { TomlError } from './error.js'
|
|
33
|
-
|
|
34
|
-
let KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/
|
|
35
|
-
|
|
36
|
-
/** @internal */
|
|
37
|
-
export function parseKey(str: string, ptr: number, end = '='): [string[], number] {
|
|
38
|
-
let dot = ptr - 1
|
|
39
|
-
let parsed = []
|
|
40
|
-
|
|
41
|
-
let endPtr = str.indexOf(end, ptr)
|
|
42
|
-
if (endPtr < 0) {
|
|
43
|
-
throw new TomlError('incomplete key-value: cannot find end of key', {
|
|
44
|
-
toml: str,
|
|
45
|
-
ptr: ptr,
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
do {
|
|
50
|
-
let c = str[(ptr = ++dot)]
|
|
51
|
-
|
|
52
|
-
// If it's whitespace, ignore
|
|
53
|
-
if (c !== ' ' && c !== '\t') {
|
|
54
|
-
// If it's a string
|
|
55
|
-
if (c === '"' || c === "'") {
|
|
56
|
-
if (c === str[ptr + 1] && c === str[ptr + 2]) {
|
|
57
|
-
throw new TomlError('multiline strings are not allowed in keys', {
|
|
58
|
-
toml: str,
|
|
59
|
-
ptr: ptr,
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let [part, eos] = parseString(str, ptr)
|
|
64
|
-
dot = str.indexOf('.', eos)
|
|
65
|
-
|
|
66
|
-
let strEnd = str.slice(eos, dot < 0 || dot > endPtr ? endPtr : dot)
|
|
67
|
-
let newLine = indexOfNewline(strEnd)
|
|
68
|
-
if (newLine > -1) {
|
|
69
|
-
throw new TomlError('newlines are not allowed in keys', {
|
|
70
|
-
toml: str,
|
|
71
|
-
ptr: ptr + dot + newLine,
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (strEnd.trimStart()) {
|
|
76
|
-
throw new TomlError('found extra tokens after the string part', {
|
|
77
|
-
toml: str,
|
|
78
|
-
ptr: eos,
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (endPtr < eos) {
|
|
83
|
-
endPtr = str.indexOf(end, eos)
|
|
84
|
-
if (endPtr < 0) {
|
|
85
|
-
throw new TomlError('incomplete key-value: cannot find end of key', {
|
|
86
|
-
toml: str,
|
|
87
|
-
ptr: ptr,
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
parsed.push(part)
|
|
93
|
-
} else {
|
|
94
|
-
// Normal raw key part consumption and validation
|
|
95
|
-
dot = str.indexOf('.', ptr)
|
|
96
|
-
let part = str.slice(ptr, dot < 0 || dot > endPtr ? endPtr : dot)
|
|
97
|
-
if (!KEY_PART_RE.test(part)) {
|
|
98
|
-
throw new TomlError('only letter, numbers, dashes and underscores are allowed in keys', {
|
|
99
|
-
toml: str,
|
|
100
|
-
ptr: ptr,
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
parsed.push(part.trimEnd())
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
// Until there's no more dot
|
|
108
|
-
} while (dot + 1 && dot < endPtr)
|
|
109
|
-
|
|
110
|
-
return [parsed, skipVoid(str, endPtr + 1, true, true)]
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** @internal */
|
|
114
|
-
export function parseInlineTable(str: string, ptr: number, depth: number, integersAsBigInt: IntegersAsBigInt): [TomlTable, number] {
|
|
115
|
-
let res: TomlTable = {}
|
|
116
|
-
let seen = new Set()
|
|
117
|
-
let c: string
|
|
118
|
-
|
|
119
|
-
ptr++
|
|
120
|
-
while ((c = str[ptr++]!) !== '}' && c) {
|
|
121
|
-
if (c === ',') {
|
|
122
|
-
throw new TomlError('expected value, found comma', {
|
|
123
|
-
toml: str,
|
|
124
|
-
ptr: ptr - 1,
|
|
125
|
-
})
|
|
126
|
-
} else if (c === '#') ptr = skipComment(str, ptr)
|
|
127
|
-
else if (c !== ' ' && c !== '\t' && c !== '\n' && c !== '\r') {
|
|
128
|
-
let k: string
|
|
129
|
-
let t: any = res
|
|
130
|
-
let hasOwn = false
|
|
131
|
-
|
|
132
|
-
let [key, keyEndPtr] = parseKey(str, ptr - 1)
|
|
133
|
-
for (let i = 0; i < key.length; i++) {
|
|
134
|
-
if (i) t = hasOwn! ? t[k!] : (t[k!] = {})
|
|
135
|
-
|
|
136
|
-
k = key[i]!
|
|
137
|
-
if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== 'object' || seen.has(t[k]))) {
|
|
138
|
-
throw new TomlError('trying to redefine an already defined value', {
|
|
139
|
-
toml: str,
|
|
140
|
-
ptr: ptr,
|
|
141
|
-
})
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (!hasOwn && k === '__proto__') {
|
|
145
|
-
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true })
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (hasOwn) {
|
|
150
|
-
throw new TomlError('trying to redefine an already defined value', {
|
|
151
|
-
toml: str,
|
|
152
|
-
ptr: ptr,
|
|
153
|
-
})
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
let [value, valueEndPtr] = extractValue(str, keyEndPtr, '}', depth - 1, integersAsBigInt)
|
|
157
|
-
seen.add(value)
|
|
158
|
-
|
|
159
|
-
t[k!] = value
|
|
160
|
-
ptr = valueEndPtr
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (!c) {
|
|
165
|
-
throw new TomlError('unfinished table encountered', {
|
|
166
|
-
toml: str,
|
|
167
|
-
ptr: ptr,
|
|
168
|
-
})
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return [res, ptr]
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/** @internal */
|
|
175
|
-
export function parseArray(str: string, ptr: number, depth: number, integersAsBigInt: IntegersAsBigInt): [TomlValue[], number] {
|
|
176
|
-
let res: TomlValue[] = []
|
|
177
|
-
let c
|
|
178
|
-
|
|
179
|
-
ptr++
|
|
180
|
-
while ((c = str[ptr++]) !== ']' && c) {
|
|
181
|
-
if (c === ',') {
|
|
182
|
-
throw new TomlError('expected value, found comma', {
|
|
183
|
-
toml: str,
|
|
184
|
-
ptr: ptr - 1,
|
|
185
|
-
})
|
|
186
|
-
} else if (c === '#') ptr = skipComment(str, ptr)
|
|
187
|
-
else if (c !== ' ' && c !== '\t' && c !== '\n' && c !== '\r') {
|
|
188
|
-
let e = extractValue(str, ptr - 1, ']', depth - 1, integersAsBigInt)
|
|
189
|
-
res.push(e[0])
|
|
190
|
-
ptr = e[1]
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (!c) {
|
|
195
|
-
throw new TomlError('unfinished array encountered', {
|
|
196
|
-
toml: str,
|
|
197
|
-
ptr: ptr,
|
|
198
|
-
})
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return [res, ptr]
|
|
202
|
-
}
|