smol-toml 1.2.2 → 1.3.0

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/dist/index.d.ts CHANGED
@@ -25,8 +25,16 @@
25
25
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
26
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
- export { TomlError } from './error.js';
29
- export { TomlDate } from './date.js';
30
- export { parse } from './parse.js';
31
- export { stringify } from './stringify.js';
28
+ import { parse } from './parse.js';
29
+ import { stringify } from './stringify.js';
30
+ import { TomlDate } from './date.js';
31
+ import { TomlError } from './error.js';
32
32
  export type { TomlPrimitive } from './util.js';
33
+ declare const _default: {
34
+ parse: typeof parse;
35
+ stringify: typeof stringify;
36
+ TomlDate: typeof TomlDate;
37
+ TomlError: typeof TomlError;
38
+ };
39
+ export default _default;
40
+ export { parse, stringify, TomlDate, TomlError };
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /*!
3
2
  * Copyright (c) Squirrel Chat et al., All rights reserved.
4
3
  * SPDX-License-Identifier: BSD-3-Clause
@@ -26,13 +25,9 @@
26
25
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
26
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
27
  */
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.stringify = exports.parse = exports.TomlDate = exports.TomlError = void 0;
31
- var error_js_1 = require("./error.js");
32
- Object.defineProperty(exports, "TomlError", { enumerable: true, get: function () { return error_js_1.TomlError; } });
33
- var date_js_1 = require("./date.js");
34
- Object.defineProperty(exports, "TomlDate", { enumerable: true, get: function () { return date_js_1.TomlDate; } });
35
- var parse_js_1 = require("./parse.js");
36
- Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_js_1.parse; } });
37
- var stringify_js_1 = require("./stringify.js");
38
- Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return stringify_js_1.stringify; } });
28
+ import { parse } from './parse.js';
29
+ import { stringify } from './stringify.js';
30
+ import { TomlDate } from './date.js';
31
+ import { TomlError } from './error.js';
32
+ export default { parse, stringify, TomlDate, TomlError };
33
+ export { parse, stringify, TomlDate, TomlError };
package/dist/parse.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /*!
3
2
  * Copyright (c) Squirrel Chat et al., All rights reserved.
4
3
  * SPDX-License-Identifier: BSD-3-Clause
@@ -26,12 +25,10 @@
26
25
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
26
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
27
  */
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.parse = void 0;
31
- const struct_js_1 = require("./struct.js");
32
- const extract_js_1 = require("./extract.js");
33
- const util_js_1 = require("./util.js");
34
- const error_js_1 = require("./error.js");
28
+ import { parseKey } from './struct.js';
29
+ import { extractValue } from './extract.js';
30
+ import { skipVoid } from './util.js';
31
+ import { TomlError } from './error.js';
35
32
  function peekTable(key, table, meta, type) {
36
33
  let t = table;
37
34
  let m = meta;
@@ -96,18 +93,18 @@ function peekTable(key, table, meta, type) {
96
93
  }
97
94
  return [k, t, state.c];
98
95
  }
99
- function parse(toml) {
96
+ export function parse(toml) {
100
97
  let res = {};
101
98
  let meta = {};
102
99
  let tbl = res;
103
100
  let m = meta;
104
- for (let ptr = (0, util_js_1.skipVoid)(toml, 0); ptr < toml.length;) {
101
+ for (let ptr = skipVoid(toml, 0); ptr < toml.length;) {
105
102
  if (toml[ptr] === '[') {
106
103
  let isTableArray = toml[++ptr] === '[';
107
- let k = (0, struct_js_1.parseKey)(toml, ptr += +isTableArray, ']');
104
+ let k = parseKey(toml, ptr += +isTableArray, ']');
108
105
  if (isTableArray) {
109
106
  if (toml[k[1] - 1] !== ']') {
110
- throw new error_js_1.TomlError('expected end of table declaration', {
107
+ throw new TomlError('expected end of table declaration', {
111
108
  toml: toml,
112
109
  ptr: k[1] - 1,
113
110
  });
@@ -116,7 +113,7 @@ function parse(toml) {
116
113
  }
117
114
  let p = peekTable(k[0], res, meta, isTableArray ? 2 /* Type.ARRAY */ : 1 /* Type.EXPLICIT */);
118
115
  if (!p) {
119
- throw new error_js_1.TomlError('trying to redefine an already defined table or value', {
116
+ throw new TomlError('trying to redefine an already defined table or value', {
120
117
  toml: toml,
121
118
  ptr: ptr,
122
119
  });
@@ -126,27 +123,26 @@ function parse(toml) {
126
123
  ptr = k[1];
127
124
  }
128
125
  else {
129
- let k = (0, struct_js_1.parseKey)(toml, ptr);
126
+ let k = parseKey(toml, ptr);
130
127
  let p = peekTable(k[0], tbl, m, 0 /* Type.DOTTED */);
131
128
  if (!p) {
132
- throw new error_js_1.TomlError('trying to redefine an already defined table or value', {
129
+ throw new TomlError('trying to redefine an already defined table or value', {
133
130
  toml: toml,
134
131
  ptr: ptr,
135
132
  });
136
133
  }
137
- let v = (0, extract_js_1.extractValue)(toml, k[1]);
134
+ let v = extractValue(toml, k[1]);
138
135
  p[1][p[0]] = v[0];
139
136
  ptr = v[1];
140
137
  }
141
- ptr = (0, util_js_1.skipVoid)(toml, ptr, true);
138
+ ptr = skipVoid(toml, ptr, true);
142
139
  if (toml[ptr] && toml[ptr] !== '\n' && toml[ptr] !== '\r') {
143
- throw new error_js_1.TomlError('each key-value declaration must be followed by an end-of-line', {
140
+ throw new TomlError('each key-value declaration must be followed by an end-of-line', {
144
141
  toml: toml,
145
142
  ptr: ptr
146
143
  });
147
144
  }
148
- ptr = (0, util_js_1.skipVoid)(toml, ptr);
145
+ ptr = skipVoid(toml, ptr);
149
146
  }
150
147
  return res;
151
148
  }
152
- exports.parse = parse;
package/dist/primitive.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /*!
3
2
  * Copyright (c) Squirrel Chat et al., All rights reserved.
4
3
  * SPDX-License-Identifier: BSD-3-Clause
@@ -26,11 +25,9 @@
26
25
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
26
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
27
  */
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.parseValue = exports.parseString = void 0;
31
- const util_js_1 = require("./util.js");
32
- const date_js_1 = require("./date.js");
33
- const error_js_1 = require("./error.js");
28
+ import { skipVoid } from './util.js';
29
+ import { TomlDate } from './date.js';
30
+ import { TomlError } from './error.js';
34
31
  let INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
35
32
  let FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
36
33
  let LEADING_ZERO = /^[+-]?0[0-9_]/;
@@ -44,7 +41,7 @@ let ESC_MAP = {
44
41
  '"': '"',
45
42
  '\\': '\\',
46
43
  };
47
- function parseString(str, ptr = 0, endPtr = str.length) {
44
+ export function parseString(str, ptr = 0, endPtr = str.length) {
48
45
  let isLiteral = str[ptr] === "'";
49
46
  let isMultiline = str[ptr++] === str[ptr] && str[ptr] === str[ptr + 1];
50
47
  if (isMultiline) {
@@ -62,14 +59,14 @@ function parseString(str, ptr = 0, endPtr = str.length) {
62
59
  let c = str[ptr++];
63
60
  if (c === '\n' || (c === '\r' && str[ptr] === '\n')) {
64
61
  if (!isMultiline) {
65
- throw new error_js_1.TomlError('newlines are not allowed in strings', {
62
+ throw new TomlError('newlines are not allowed in strings', {
66
63
  toml: str,
67
64
  ptr: ptr - 1
68
65
  });
69
66
  }
70
67
  }
71
68
  else if ((c < '\x20' && c !== '\t') || c === '\x7f') {
72
- throw new error_js_1.TomlError('control characters are not allowed in strings', {
69
+ throw new TomlError('control characters are not allowed in strings', {
73
70
  toml: str,
74
71
  ptr: ptr - 1
75
72
  });
@@ -80,7 +77,7 @@ function parseString(str, ptr = 0, endPtr = str.length) {
80
77
  // Unicode escape
81
78
  let code = str.slice(ptr, (ptr += (c === 'u' ? 4 : 8)));
82
79
  if (!ESCAPE_REGEX.test(code)) {
83
- throw new error_js_1.TomlError('invalid unicode escape', {
80
+ throw new TomlError('invalid unicode escape', {
84
81
  toml: str,
85
82
  ptr: tmp
86
83
  });
@@ -89,7 +86,7 @@ function parseString(str, ptr = 0, endPtr = str.length) {
89
86
  parsed += String.fromCodePoint(parseInt(code, 16));
90
87
  }
91
88
  catch {
92
- throw new error_js_1.TomlError('invalid unicode escape', {
89
+ throw new TomlError('invalid unicode escape', {
93
90
  toml: str,
94
91
  ptr: tmp
95
92
  });
@@ -97,21 +94,21 @@ function parseString(str, ptr = 0, endPtr = str.length) {
97
94
  }
98
95
  else if (isMultiline && (c === '\n' || c === ' ' || c === '\t' || c === '\r')) {
99
96
  // Multiline escape
100
- ptr = (0, util_js_1.skipVoid)(str, ptr - 1, true);
97
+ ptr = skipVoid(str, ptr - 1, true);
101
98
  if (str[ptr] !== '\n' && str[ptr] !== '\r') {
102
- throw new error_js_1.TomlError('invalid escape: only line-ending whitespace may be escaped', {
99
+ throw new TomlError('invalid escape: only line-ending whitespace may be escaped', {
103
100
  toml: str,
104
101
  ptr: tmp
105
102
  });
106
103
  }
107
- ptr = (0, util_js_1.skipVoid)(str, ptr);
104
+ ptr = skipVoid(str, ptr);
108
105
  }
109
106
  else if (c in ESC_MAP) {
110
107
  // Classic escape
111
108
  parsed += ESC_MAP[c];
112
109
  }
113
110
  else {
114
- throw new error_js_1.TomlError('unrecognized escape sequence', {
111
+ throw new TomlError('unrecognized escape sequence', {
115
112
  toml: str,
116
113
  ptr: tmp
117
114
  });
@@ -126,8 +123,7 @@ function parseString(str, ptr = 0, endPtr = str.length) {
126
123
  }
127
124
  return parsed + str.slice(sliceStart, endPtr - 1);
128
125
  }
129
- exports.parseString = parseString;
130
- function parseValue(value, toml, ptr) {
126
+ export function parseValue(value, toml, ptr) {
131
127
  // Constant values
132
128
  if (value === 'true')
133
129
  return true;
@@ -145,33 +141,32 @@ function parseValue(value, toml, ptr) {
145
141
  let isInt;
146
142
  if ((isInt = INT_REGEX.test(value)) || FLOAT_REGEX.test(value)) {
147
143
  if (LEADING_ZERO.test(value)) {
148
- throw new error_js_1.TomlError('leading zeroes are not allowed', {
144
+ throw new TomlError('leading zeroes are not allowed', {
149
145
  toml: toml,
150
146
  ptr: ptr
151
147
  });
152
148
  }
153
149
  let numeric = +(value.replace(/_/g, ''));
154
150
  if (isNaN(numeric)) {
155
- throw new error_js_1.TomlError('invalid number', {
151
+ throw new TomlError('invalid number', {
156
152
  toml: toml,
157
153
  ptr: ptr
158
154
  });
159
155
  }
160
156
  if (isInt && !Number.isSafeInteger(numeric)) {
161
- throw new error_js_1.TomlError('integer value cannot be represented losslessly', {
157
+ throw new TomlError('integer value cannot be represented losslessly', {
162
158
  toml: toml,
163
159
  ptr: ptr
164
160
  });
165
161
  }
166
162
  return numeric;
167
163
  }
168
- let date = new date_js_1.TomlDate(value);
164
+ let date = new TomlDate(value);
169
165
  if (!date.isValid()) {
170
- throw new error_js_1.TomlError('invalid value', {
166
+ throw new TomlError('invalid value', {
171
167
  toml: toml,
172
168
  ptr: ptr
173
169
  });
174
170
  }
175
171
  return date;
176
172
  }
177
- exports.parseValue = parseValue;
package/dist/stringify.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /*!
3
2
  * Copyright (c) Squirrel Chat et al., All rights reserved.
4
3
  * SPDX-License-Identifier: BSD-3-Clause
@@ -26,8 +25,6 @@
26
25
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
26
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
27
  */
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.stringify = void 0;
31
28
  const BARE_KEY = /^[a-z0-9-_]+$/i;
32
29
  function extendedTypeOf(obj) {
33
30
  let type = typeof obj;
@@ -147,10 +144,9 @@ function stringifyTable(obj, prefix = '') {
147
144
  }
148
145
  return `${preamble}\n${tables}`.trim();
149
146
  }
150
- function stringify(obj) {
147
+ export function stringify(obj) {
151
148
  if (extendedTypeOf(obj) !== 'object') {
152
149
  throw new TypeError('stringify can only be called with an object');
153
150
  }
154
151
  return stringifyTable(obj);
155
152
  }
156
- exports.stringify = stringify;
package/dist/struct.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /*!
3
2
  * Copyright (c) Squirrel Chat et al., All rights reserved.
4
3
  * SPDX-License-Identifier: BSD-3-Clause
@@ -26,19 +25,17 @@
26
25
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
26
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
27
  */
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.parseArray = exports.parseInlineTable = exports.parseKey = void 0;
31
- const primitive_js_1 = require("./primitive.js");
32
- const extract_js_1 = require("./extract.js");
33
- const util_js_1 = require("./util.js");
34
- const error_js_1 = require("./error.js");
28
+ import { parseString } from './primitive.js';
29
+ import { extractValue } from './extract.js';
30
+ import { skipComment, indexOfNewline, getStringEnd, skipVoid } from './util.js';
31
+ import { TomlError } from './error.js';
35
32
  let KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/;
36
- function parseKey(str, ptr, end = '=') {
33
+ export function parseKey(str, ptr, end = '=') {
37
34
  let dot = ptr - 1;
38
35
  let parsed = [];
39
36
  let endPtr = str.indexOf(end, ptr);
40
37
  if (endPtr < 0) {
41
- throw new error_js_1.TomlError('incomplete key-value: cannot find end of key', {
38
+ throw new TomlError('incomplete key-value: cannot find end of key', {
42
39
  toml: str,
43
40
  ptr: ptr
44
41
  });
@@ -50,29 +47,29 @@ function parseKey(str, ptr, end = '=') {
50
47
  // If it's a string
51
48
  if (c === '"' || c === "'") {
52
49
  if (c === str[ptr + 1] && c === str[ptr + 2]) {
53
- throw new error_js_1.TomlError('multiline strings are not allowed in keys', {
50
+ throw new TomlError('multiline strings are not allowed in keys', {
54
51
  toml: str,
55
52
  ptr: ptr,
56
53
  });
57
54
  }
58
- let eos = (0, util_js_1.getStringEnd)(str, ptr);
55
+ let eos = getStringEnd(str, ptr);
59
56
  if (eos < 0) {
60
- throw new error_js_1.TomlError('unfinished string encountered', {
57
+ throw new TomlError('unfinished string encountered', {
61
58
  toml: str,
62
59
  ptr: ptr,
63
60
  });
64
61
  }
65
62
  dot = str.indexOf('.', eos);
66
63
  let strEnd = str.slice(eos, dot < 0 || dot > endPtr ? endPtr : dot);
67
- let newLine = (0, util_js_1.indexOfNewline)(strEnd);
64
+ let newLine = indexOfNewline(strEnd);
68
65
  if (newLine > -1) {
69
- throw new error_js_1.TomlError('newlines are not allowed in keys', {
66
+ throw new TomlError('newlines are not allowed in keys', {
70
67
  toml: str,
71
68
  ptr: ptr + dot + newLine,
72
69
  });
73
70
  }
74
71
  if (strEnd.trimStart()) {
75
- throw new error_js_1.TomlError('found extra tokens after the string part', {
72
+ throw new TomlError('found extra tokens after the string part', {
76
73
  toml: str,
77
74
  ptr: eos,
78
75
  });
@@ -80,20 +77,20 @@ function parseKey(str, ptr, end = '=') {
80
77
  if (endPtr < eos) {
81
78
  endPtr = str.indexOf(end, eos);
82
79
  if (endPtr < 0) {
83
- throw new error_js_1.TomlError('incomplete key-value: cannot find end of key', {
80
+ throw new TomlError('incomplete key-value: cannot find end of key', {
84
81
  toml: str,
85
82
  ptr: ptr,
86
83
  });
87
84
  }
88
85
  }
89
- parsed.push((0, primitive_js_1.parseString)(str, ptr, eos));
86
+ parsed.push(parseString(str, ptr, eos));
90
87
  }
91
88
  else {
92
89
  // Normal raw key part consumption and validation
93
90
  dot = str.indexOf('.', ptr);
94
91
  let part = str.slice(ptr, dot < 0 || dot > endPtr ? endPtr : dot);
95
92
  if (!KEY_PART_RE.test(part)) {
96
- throw new error_js_1.TomlError('only letter, numbers, dashes and underscores are allowed in keys', {
93
+ throw new TomlError('only letter, numbers, dashes and underscores are allowed in keys', {
97
94
  toml: str,
98
95
  ptr: ptr,
99
96
  });
@@ -103,10 +100,9 @@ function parseKey(str, ptr, end = '=') {
103
100
  }
104
101
  // Until there's no more dot
105
102
  } while (dot + 1 && dot < endPtr);
106
- return [parsed, (0, util_js_1.skipVoid)(str, endPtr + 1, true, true)];
103
+ return [parsed, skipVoid(str, endPtr + 1, true, true)];
107
104
  }
108
- exports.parseKey = parseKey;
109
- function parseInlineTable(str, ptr) {
105
+ export function parseInlineTable(str, ptr) {
110
106
  let res = {};
111
107
  let seen = new Set();
112
108
  let c;
@@ -114,19 +110,19 @@ function parseInlineTable(str, ptr) {
114
110
  ptr++;
115
111
  while ((c = str[ptr++]) !== '}' && c) {
116
112
  if (c === '\n') {
117
- throw new error_js_1.TomlError('newlines are not allowed in inline tables', {
113
+ throw new TomlError('newlines are not allowed in inline tables', {
118
114
  toml: str,
119
115
  ptr: ptr - 1
120
116
  });
121
117
  }
122
118
  else if (c === '#') {
123
- throw new error_js_1.TomlError('inline tables cannot contain comments', {
119
+ throw new TomlError('inline tables cannot contain comments', {
124
120
  toml: str,
125
121
  ptr: ptr - 1
126
122
  });
127
123
  }
128
124
  else if (c === ',') {
129
- throw new error_js_1.TomlError('expected key-value, found comma', {
125
+ throw new TomlError('expected key-value, found comma', {
130
126
  toml: str,
131
127
  ptr: ptr - 1
132
128
  });
@@ -141,7 +137,7 @@ function parseInlineTable(str, ptr) {
141
137
  t = hasOwn ? t[k] : (t[k] = {});
142
138
  k = key[i];
143
139
  if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== 'object' || seen.has(t[k]))) {
144
- throw new error_js_1.TomlError('trying to redefine an already defined value', {
140
+ throw new TomlError('trying to redefine an already defined value', {
145
141
  toml: str,
146
142
  ptr: ptr
147
143
  });
@@ -151,12 +147,12 @@ function parseInlineTable(str, ptr) {
151
147
  }
152
148
  }
153
149
  if (hasOwn) {
154
- throw new error_js_1.TomlError('trying to redefine an already defined value', {
150
+ throw new TomlError('trying to redefine an already defined value', {
155
151
  toml: str,
156
152
  ptr: ptr
157
153
  });
158
154
  }
159
- let [value, valueEndPtr] = (0, extract_js_1.extractValue)(str, keyEndPtr, '}');
155
+ let [value, valueEndPtr] = extractValue(str, keyEndPtr, '}');
160
156
  seen.add(value);
161
157
  t[k] = value;
162
158
  ptr = valueEndPtr;
@@ -164,45 +160,43 @@ function parseInlineTable(str, ptr) {
164
160
  }
165
161
  }
166
162
  if (comma) {
167
- throw new error_js_1.TomlError('trailing commas are not allowed in inline tables', {
163
+ throw new TomlError('trailing commas are not allowed in inline tables', {
168
164
  toml: str,
169
165
  ptr: comma
170
166
  });
171
167
  }
172
168
  if (!c) {
173
- throw new error_js_1.TomlError('unfinished table encountered', {
169
+ throw new TomlError('unfinished table encountered', {
174
170
  toml: str,
175
171
  ptr: ptr
176
172
  });
177
173
  }
178
174
  return [res, ptr];
179
175
  }
180
- exports.parseInlineTable = parseInlineTable;
181
- function parseArray(str, ptr) {
176
+ export function parseArray(str, ptr) {
182
177
  let res = [];
183
178
  let c;
184
179
  ptr++;
185
180
  while ((c = str[ptr++]) !== ']' && c) {
186
181
  if (c === ',') {
187
- throw new error_js_1.TomlError('expected value, found comma', {
182
+ throw new TomlError('expected value, found comma', {
188
183
  toml: str,
189
184
  ptr: ptr - 1
190
185
  });
191
186
  }
192
187
  else if (c === '#')
193
- ptr = (0, util_js_1.skipComment)(str, ptr);
188
+ ptr = skipComment(str, ptr);
194
189
  else if (c !== ' ' && c !== '\t' && c !== '\n' && c !== '\r') {
195
- let e = (0, extract_js_1.extractValue)(str, ptr - 1, ']');
190
+ let e = extractValue(str, ptr - 1, ']');
196
191
  res.push(e[0]);
197
192
  ptr = e[1];
198
193
  }
199
194
  }
200
195
  if (!c) {
201
- throw new error_js_1.TomlError('unfinished array encountered', {
196
+ throw new TomlError('unfinished array encountered', {
202
197
  toml: str,
203
198
  ptr: ptr
204
199
  });
205
200
  }
206
201
  return [res, ptr];
207
202
  }
208
- exports.parseArray = parseArray;
package/dist/util.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /*!
3
2
  * Copyright (c) Squirrel Chat et al., All rights reserved.
4
3
  * SPDX-License-Identifier: BSD-3-Clause
@@ -26,17 +25,14 @@
26
25
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
26
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
27
  */
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.getStringEnd = exports.skipUntil = exports.skipVoid = exports.skipComment = exports.indexOfNewline = void 0;
31
- const error_js_1 = require("./error.js");
32
- function indexOfNewline(str, start = 0, end = str.length) {
28
+ import { TomlError } from './error.js';
29
+ export function indexOfNewline(str, start = 0, end = str.length) {
33
30
  let idx = str.indexOf('\n', start);
34
31
  if (str[idx - 1] === '\r')
35
32
  idx--;
36
33
  return idx <= end ? idx : -1;
37
34
  }
38
- exports.indexOfNewline = indexOfNewline;
39
- function skipComment(str, ptr) {
35
+ export function skipComment(str, ptr) {
40
36
  for (let i = ptr; i < str.length; i++) {
41
37
  let c = str[i];
42
38
  if (c === '\n')
@@ -44,7 +40,7 @@ function skipComment(str, ptr) {
44
40
  if (c === '\r' && str[i + 1] === '\n')
45
41
  return i + 1;
46
42
  if ((c < '\x20' && c !== '\t') || c === '\x7f') {
47
- throw new error_js_1.TomlError('control characters are not allowed in comments', {
43
+ throw new TomlError('control characters are not allowed in comments', {
48
44
  toml: str,
49
45
  ptr: ptr,
50
46
  });
@@ -52,8 +48,7 @@ function skipComment(str, ptr) {
52
48
  }
53
49
  return str.length;
54
50
  }
55
- exports.skipComment = skipComment;
56
- function skipVoid(str, ptr, banNewLines, banComments) {
51
+ export function skipVoid(str, ptr, banNewLines, banComments) {
57
52
  let c;
58
53
  while ((c = str[ptr]) === ' ' || c === '\t' || (!banNewLines && (c === '\n' || c === '\r' && str[ptr + 1] === '\n')))
59
54
  ptr++;
@@ -61,8 +56,7 @@ function skipVoid(str, ptr, banNewLines, banComments) {
61
56
  ? ptr
62
57
  : skipVoid(str, skipComment(str, ptr), banNewLines);
63
58
  }
64
- exports.skipVoid = skipVoid;
65
- function skipUntil(str, ptr, sep, end, banNewLines = false) {
59
+ export function skipUntil(str, ptr, sep, end, banNewLines = false) {
66
60
  if (!end) {
67
61
  ptr = indexOfNewline(str, ptr);
68
62
  return ptr < 0 ? str.length : ptr;
@@ -82,13 +76,12 @@ function skipUntil(str, ptr, sep, end, banNewLines = false) {
82
76
  return i;
83
77
  }
84
78
  }
85
- throw new error_js_1.TomlError('cannot find end of structure', {
79
+ throw new TomlError('cannot find end of structure', {
86
80
  toml: str,
87
81
  ptr: ptr
88
82
  });
89
83
  }
90
- exports.skipUntil = skipUntil;
91
- function getStringEnd(str, seek) {
84
+ export function getStringEnd(str, seek) {
92
85
  let first = str[seek];
93
86
  let target = first === str[seek + 1] && str[seek + 1] === str[seek + 2]
94
87
  ? str.slice(seek, seek + 3)
@@ -108,4 +101,3 @@ function getStringEnd(str, seek) {
108
101
  }
109
102
  return seek;
110
103
  }
111
- exports.getStringEnd = getStringEnd;
package/package.json CHANGED
@@ -1,40 +1,50 @@
1
1
  {
2
2
  "name": "smol-toml",
3
- "version": "1.2.2",
3
+ "license": "BSD-3-Clause",
4
+ "version": "1.3.0",
5
+ "description": "A small, fast, and correct TOML parser/serializer",
6
+ "author": "Cynthia <cyyynthia@borkenware.com>",
7
+ "repository": "github:squirrelchat/smol-toml",
8
+ "bugs": "https://github.com/squirrelchat/smol-toml/issues",
9
+ "funding": "https://github.com/sponsors/cyyynthia",
4
10
  "keywords": [
5
11
  "toml",
6
12
  "parser",
7
13
  "serializer"
8
14
  ],
9
- "description": "A small, fast, and correct TOML parser/serializer",
10
- "repository": {
11
- "type": "git",
12
- "url": "git+ssh://git@github.com/squirrelchat/smol-toml.git"
13
- },
14
- "author": "Cynthia <cyyynthia@borkenware.com>",
15
- "license": "BSD-3-Clause",
15
+ "type": "module",
16
+ "packageManager": "pnpm@9.4.0",
16
17
  "engines": {
17
18
  "node": ">= 18"
18
19
  },
19
20
  "scripts": {
20
- "build": "tsc",
21
21
  "test": "vitest",
22
22
  "test-ui": "vitest --ui",
23
- "bench": "vitest bench"
23
+ "bench": "vitest bench",
24
+ "build": "pnpm run build:mjs && pnpm run build:cjs && node test/package/package-test.mjs",
25
+ "build:mjs": "tsc",
26
+ "build:cjs": "esbuild dist/index.js --bundle --platform=node --target=node18 --format=cjs --outfile=dist/index.cjs"
24
27
  },
25
28
  "devDependencies": {
26
29
  "@iarna/toml": "3.0.0",
27
30
  "@ltd/j-toml": "^1.38.0",
28
31
  "@tsconfig/node-lts": "^20.1.3",
29
32
  "@tsconfig/strictest": "^2.0.5",
30
- "@types/node": "^20.12.11",
31
- "@vitest/ui": "^1.6.0",
33
+ "@types/node": "^20.14.10",
34
+ "@vitest/ui": "^2.0.3",
35
+ "esbuild": "^0.23.0",
32
36
  "fast-toml": "^0.5.4",
33
- "typescript": "^5.4.5",
34
- "vitest": "^1.6.0"
37
+ "typescript": "^5.5.3",
38
+ "vitest": "^2.0.3"
35
39
  },
36
- "main": "./dist/index.js",
40
+ "main": "./dist/index.cjs",
41
+ "module": "./dist/index.js",
37
42
  "types": "./dist/index.d.ts",
43
+ "exports": {
44
+ "types": "./dist/index.d.ts",
45
+ "import": "./dist/index.js",
46
+ "require": "./dist/index.cjs"
47
+ },
38
48
  "files": [
39
49
  "README.md",
40
50
  "LICENSE",