Comparing version 1.1.4 to 1.2.0
@@ -28,3 +28,3 @@ /*! | ||
*/ | ||
export default class TomlDate extends Date { | ||
export declare class TomlDate extends Date { | ||
#private; | ||
@@ -31,0 +31,0 @@ constructor(date: string | Date); |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/*! | ||
@@ -28,4 +29,6 @@ * Copyright (c) Squirrel Chat et al., All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TomlDate = void 0; | ||
let DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}:\d{2}(?:\.\d+)?)?(Z|[-+]\d{2}:\d{2})?$/i; | ||
export default class TomlDate extends Date { | ||
class TomlDate extends Date { | ||
#hasDate = false; | ||
@@ -127,1 +130,2 @@ #hasTime = false; | ||
} | ||
exports.TomlDate = TomlDate; |
@@ -32,3 +32,3 @@ /*! | ||
}; | ||
export default class TomlError extends Error { | ||
export declare class TomlError extends Error { | ||
line: number; | ||
@@ -35,0 +35,0 @@ column: number; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/*! | ||
@@ -28,2 +29,4 @@ * Copyright (c) Squirrel Chat et al., All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TomlError = void 0; | ||
function getLineColFromPtr(string, ptr) { | ||
@@ -52,3 +55,3 @@ let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g); | ||
} | ||
export default class TomlError extends Error { | ||
class TomlError extends Error { | ||
line; | ||
@@ -66,1 +69,2 @@ column; | ||
} | ||
exports.TomlError = TomlError; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/*! | ||
@@ -28,6 +29,8 @@ * Copyright (c) Squirrel Chat et al., All rights reserved. | ||
*/ | ||
import { parseString, parseValue } from './primitive.js'; | ||
import { parseArray, parseInlineTable } from './struct.js'; | ||
import { indexOfNewline, skipVoid, skipUntil, skipComment, getStringEnd } from './util.js'; | ||
import TomlError from './error.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.extractValue = void 0; | ||
const primitive_js_1 = require("./primitive.js"); | ||
const struct_js_1 = require("./struct.js"); | ||
const util_js_1 = require("./util.js"); | ||
const error_js_1 = require("./error.js"); | ||
function sliceAndTrimEndOf(str, startPtr, endPtr, allowNewLines) { | ||
@@ -39,3 +42,3 @@ let value = str.slice(startPtr, endPtr); | ||
// (absence of control characters) | ||
skipComment(str, commentIdx); | ||
(0, util_js_1.skipComment)(str, commentIdx); | ||
value = value.slice(0, commentIdx); | ||
@@ -47,3 +50,3 @@ } | ||
if (newlineIdx > -1) { | ||
throw new TomlError('newlines are not allowed in inline tables', { | ||
throw new error_js_1.TomlError('newlines are not allowed in inline tables', { | ||
toml: str, | ||
@@ -56,13 +59,13 @@ ptr: startPtr + newlineIdx | ||
} | ||
export function extractValue(str, ptr, end) { | ||
function extractValue(str, ptr, end) { | ||
let c = str[ptr]; | ||
if (c === '[' || c === '{') { | ||
let [value, endPtr] = c === '[' | ||
? parseArray(str, ptr) | ||
: parseInlineTable(str, ptr); | ||
let newPtr = skipUntil(str, endPtr, ',', end); | ||
? (0, struct_js_1.parseArray)(str, ptr) | ||
: (0, struct_js_1.parseInlineTable)(str, ptr); | ||
let newPtr = (0, util_js_1.skipUntil)(str, endPtr, ',', end); | ||
if (end === '}') { | ||
let nextNewLine = indexOfNewline(str, endPtr, newPtr); | ||
let nextNewLine = (0, util_js_1.indexOfNewline)(str, endPtr, newPtr); | ||
if (nextNewLine > -1) { | ||
throw new TomlError('newlines are not allowed in inline tables', { | ||
throw new error_js_1.TomlError('newlines are not allowed in inline tables', { | ||
toml: str, | ||
@@ -77,8 +80,8 @@ ptr: nextNewLine | ||
if (c === '"' || c === "'") { | ||
endPtr = getStringEnd(str, ptr); | ||
let parsed = parseString(str, ptr, endPtr); | ||
endPtr = (0, util_js_1.getStringEnd)(str, ptr); | ||
let parsed = (0, primitive_js_1.parseString)(str, ptr, endPtr); | ||
if (end) { | ||
endPtr = skipVoid(str, endPtr, end !== ']'); | ||
endPtr = (0, util_js_1.skipVoid)(str, endPtr, end !== ']'); | ||
if (str[endPtr] && str[endPtr] !== ',' && str[endPtr] !== end && str[endPtr] !== '\n' && str[endPtr] !== '\r') { | ||
throw new TomlError('unexpected character encountered', { | ||
throw new error_js_1.TomlError('unexpected character encountered', { | ||
toml: str, | ||
@@ -92,6 +95,6 @@ ptr: endPtr, | ||
} | ||
endPtr = skipUntil(str, ptr, ',', end); | ||
endPtr = (0, util_js_1.skipUntil)(str, ptr, ',', end); | ||
let slice = sliceAndTrimEndOf(str, ptr, endPtr - (+(str[endPtr - 1] === ',')), end === ']'); | ||
if (!slice[0]) { | ||
throw new TomlError('incomplete key-value declaration: no value specified', { | ||
throw new error_js_1.TomlError('incomplete key-value declaration: no value specified', { | ||
toml: str, | ||
@@ -102,9 +105,10 @@ ptr: ptr | ||
if (end && slice[1] > -1) { | ||
endPtr = skipVoid(str, ptr + slice[1]); | ||
endPtr = (0, util_js_1.skipVoid)(str, ptr + slice[1]); | ||
endPtr += +(str[endPtr] === ','); | ||
} | ||
return [ | ||
parseValue(slice[0], str, ptr), | ||
(0, primitive_js_1.parseValue)(slice[0], str, ptr), | ||
endPtr, | ||
]; | ||
} | ||
exports.extractValue = extractValue; |
@@ -28,6 +28,6 @@ /*! | ||
*/ | ||
export { default as TomlError } from './error.js'; | ||
export { default as TomlDate } from './date.js'; | ||
export { TomlError } from './error.js'; | ||
export { TomlDate } from './date.js'; | ||
export { parse } from './parse.js'; | ||
export { stringify } from './stringify.js'; | ||
export type { TomlPrimitive } from './util.js'; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/*! | ||
@@ -28,5 +29,11 @@ * Copyright (c) Squirrel Chat et al., All rights reserved. | ||
*/ | ||
export { default as TomlError } from './error.js'; | ||
export { default as TomlDate } from './date.js'; | ||
export { parse } from './parse.js'; | ||
export { stringify } from './stringify.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringify = exports.parse = exports.TomlDate = exports.TomlError = void 0; | ||
var error_js_1 = require("./error.js"); | ||
Object.defineProperty(exports, "TomlError", { enumerable: true, get: function () { return error_js_1.TomlError; } }); | ||
var date_js_1 = require("./date.js"); | ||
Object.defineProperty(exports, "TomlDate", { enumerable: true, get: function () { return date_js_1.TomlDate; } }); | ||
var parse_js_1 = require("./parse.js"); | ||
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_js_1.parse; } }); | ||
var stringify_js_1 = require("./stringify.js"); | ||
Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return stringify_js_1.stringify; } }); |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/*! | ||
@@ -28,6 +29,8 @@ * Copyright (c) Squirrel Chat et al., All rights reserved. | ||
*/ | ||
import { parseKey } from './struct.js'; | ||
import { extractValue } from './extract.js'; | ||
import { skipVoid } from './util.js'; | ||
import TomlError from './error.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parse = void 0; | ||
const struct_js_1 = require("./struct.js"); | ||
const extract_js_1 = require("./extract.js"); | ||
const util_js_1 = require("./util.js"); | ||
const error_js_1 = require("./error.js"); | ||
function peekTable(key, table, meta, type) { | ||
@@ -97,3 +100,3 @@ let t = table; | ||
} | ||
export function parse(toml) { | ||
function parse(toml) { | ||
let res = {}; | ||
@@ -103,9 +106,9 @@ let meta = {}; | ||
let m = meta; | ||
for (let ptr = skipVoid(toml, 0); ptr < toml.length;) { | ||
for (let ptr = (0, util_js_1.skipVoid)(toml, 0); ptr < toml.length;) { | ||
if (toml[ptr] === '[') { | ||
let isTableArray = toml[++ptr] === '['; | ||
let k = parseKey(toml, ptr += +isTableArray, ']'); | ||
let k = (0, struct_js_1.parseKey)(toml, ptr += +isTableArray, ']'); | ||
if (isTableArray) { | ||
if (toml[k[1] - 1] !== ']') { | ||
throw new TomlError('expected end of table declaration', { | ||
throw new error_js_1.TomlError('expected end of table declaration', { | ||
toml: toml, | ||
@@ -119,3 +122,3 @@ ptr: k[1] - 1, | ||
if (!p) { | ||
throw new TomlError('trying to redefine an already defined table or value', { | ||
throw new error_js_1.TomlError('trying to redefine an already defined table or value', { | ||
toml: toml, | ||
@@ -130,6 +133,6 @@ ptr: ptr, | ||
else { | ||
let k = parseKey(toml, ptr); | ||
let k = (0, struct_js_1.parseKey)(toml, ptr); | ||
let p = peekTable(k[0], tbl, m, 0 /* Type.DOTTED */); | ||
if (!p) { | ||
throw new TomlError('trying to redefine an already defined table or value', { | ||
throw new error_js_1.TomlError('trying to redefine an already defined table or value', { | ||
toml: toml, | ||
@@ -139,9 +142,9 @@ ptr: ptr, | ||
} | ||
let v = extractValue(toml, k[1]); | ||
let v = (0, extract_js_1.extractValue)(toml, k[1]); | ||
p[1][p[0]] = v[0]; | ||
ptr = v[1]; | ||
} | ||
ptr = skipVoid(toml, ptr, true); | ||
ptr = (0, util_js_1.skipVoid)(toml, ptr, true); | ||
if (toml[ptr] && toml[ptr] !== '\n' && toml[ptr] !== '\r') { | ||
throw new TomlError('each key-value declaration must be followed by an end-of-line', { | ||
throw new error_js_1.TomlError('each key-value declaration must be followed by an end-of-line', { | ||
toml: toml, | ||
@@ -151,5 +154,6 @@ ptr: ptr | ||
} | ||
ptr = skipVoid(toml, ptr); | ||
ptr = (0, util_js_1.skipVoid)(toml, ptr); | ||
} | ||
return res; | ||
} | ||
exports.parse = parse; |
@@ -28,4 +28,4 @@ /*! | ||
*/ | ||
import TomlDate from './date.js'; | ||
import { TomlDate } from './date.js'; | ||
export declare function parseString(str: string, ptr?: number, endPtr?: number): string; | ||
export declare function parseValue(value: string, toml: string, ptr: number): boolean | number | TomlDate; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/*! | ||
@@ -28,5 +29,7 @@ * Copyright (c) Squirrel Chat et al., All rights reserved. | ||
*/ | ||
import { skipVoid } from './util.js'; | ||
import TomlDate from './date.js'; | ||
import TomlError from './error.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseValue = exports.parseString = void 0; | ||
const util_js_1 = require("./util.js"); | ||
const date_js_1 = require("./date.js"); | ||
const error_js_1 = require("./error.js"); | ||
let INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/; | ||
@@ -45,3 +48,3 @@ let FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/; | ||
}; | ||
export function parseString(str, ptr = 0, endPtr = str.length) { | ||
function parseString(str, ptr = 0, endPtr = str.length) { | ||
let isLiteral = str[ptr] === "'"; | ||
@@ -64,3 +67,3 @@ let isMultiline = str[ptr++] === str[ptr] && str[ptr] === str[ptr + 1]; | ||
if (!isMultiline) { | ||
throw new TomlError('newlines are not allowed in strings', { | ||
throw new error_js_1.TomlError('newlines are not allowed in strings', { | ||
toml: str, | ||
@@ -72,3 +75,3 @@ ptr: ptr - 1 | ||
else if ((c < '\x20' && c !== '\t') || c === '\x7f') { | ||
throw new TomlError('control characters are not allowed in strings', { | ||
throw new error_js_1.TomlError('control characters are not allowed in strings', { | ||
toml: str, | ||
@@ -84,3 +87,3 @@ ptr: ptr - 1 | ||
if (!ESCAPE_REGEX.test(code)) { | ||
throw new TomlError('invalid unicode escape', { | ||
throw new error_js_1.TomlError('invalid unicode escape', { | ||
toml: str, | ||
@@ -94,3 +97,3 @@ ptr: tmp | ||
catch { | ||
throw new TomlError('invalid unicode escape', { | ||
throw new error_js_1.TomlError('invalid unicode escape', { | ||
toml: str, | ||
@@ -103,5 +106,5 @@ ptr: tmp | ||
// Multiline escape | ||
ptr = skipVoid(str, ptr - 1, true); | ||
ptr = (0, util_js_1.skipVoid)(str, ptr - 1, true); | ||
if (str[ptr] !== '\n' && str[ptr] !== '\r') { | ||
throw new TomlError('invalid escape: only line-ending whitespace may be escaped', { | ||
throw new error_js_1.TomlError('invalid escape: only line-ending whitespace may be escaped', { | ||
toml: str, | ||
@@ -111,3 +114,3 @@ ptr: tmp | ||
} | ||
ptr = skipVoid(str, ptr); | ||
ptr = (0, util_js_1.skipVoid)(str, ptr); | ||
} | ||
@@ -119,3 +122,3 @@ else if (c in ESC_MAP) { | ||
else { | ||
throw new TomlError('unrecognized escape sequence', { | ||
throw new error_js_1.TomlError('unrecognized escape sequence', { | ||
toml: str, | ||
@@ -135,3 +138,4 @@ ptr: tmp | ||
} | ||
export function parseValue(value, toml, ptr) { | ||
exports.parseString = parseString; | ||
function parseValue(value, toml, ptr) { | ||
// Constant values | ||
@@ -154,3 +158,3 @@ if (value === 'true') | ||
if (LEADING_ZERO.test(value)) { | ||
throw new TomlError('leading zeroes are not allowed', { | ||
throw new error_js_1.TomlError('leading zeroes are not allowed', { | ||
toml: toml, | ||
@@ -162,3 +166,3 @@ ptr: ptr | ||
if (isNaN(numeric)) { | ||
throw new TomlError('invalid number', { | ||
throw new error_js_1.TomlError('invalid number', { | ||
toml: toml, | ||
@@ -169,3 +173,3 @@ ptr: ptr | ||
if (isInt && !Number.isSafeInteger(numeric)) { | ||
throw new TomlError('integer value cannot be represented losslessly', { | ||
throw new error_js_1.TomlError('integer value cannot be represented losslessly', { | ||
toml: toml, | ||
@@ -177,5 +181,5 @@ ptr: ptr | ||
} | ||
let date = new TomlDate(value); | ||
let date = new date_js_1.TomlDate(value); | ||
if (!date.isValid()) { | ||
throw new TomlError('invalid value', { | ||
throw new error_js_1.TomlError('invalid value', { | ||
toml: toml, | ||
@@ -187,1 +191,2 @@ ptr: ptr | ||
} | ||
exports.parseValue = parseValue; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/*! | ||
@@ -28,2 +29,4 @@ * Copyright (c) Squirrel Chat et al., All rights reserved. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringify = void 0; | ||
const BARE_KEY = /^[a-z0-9-_]+$/i; | ||
@@ -148,3 +151,3 @@ function extendedTypeOf(obj) { | ||
} | ||
export function stringify(obj) { | ||
function stringify(obj) { | ||
if (extendedTypeOf(obj) !== 'object') { | ||
@@ -155,1 +158,2 @@ throw new TypeError('stringify can only be called with an object'); | ||
} | ||
exports.stringify = stringify; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/*! | ||
@@ -28,8 +29,10 @@ * Copyright (c) Squirrel Chat et al., All rights reserved. | ||
*/ | ||
import { parseString } from './primitive.js'; | ||
import { extractValue } from './extract.js'; | ||
import { skipComment, indexOfNewline, getStringEnd, skipVoid } from './util.js'; | ||
import TomlError from './error.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseArray = exports.parseInlineTable = exports.parseKey = void 0; | ||
const primitive_js_1 = require("./primitive.js"); | ||
const extract_js_1 = require("./extract.js"); | ||
const util_js_1 = require("./util.js"); | ||
const error_js_1 = require("./error.js"); | ||
let KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/; | ||
export function parseKey(str, ptr, end = '=') { | ||
function parseKey(str, ptr, end = '=') { | ||
let dot = ptr - 1; | ||
@@ -39,3 +42,3 @@ let parsed = []; | ||
if (endPtr < 0) { | ||
throw new TomlError('incomplete key-value: cannot find end of key', { | ||
throw new error_js_1.TomlError('incomplete key-value: cannot find end of key', { | ||
toml: str, | ||
@@ -52,3 +55,3 @@ ptr: ptr | ||
if (c === str[ptr + 1] && c === str[ptr + 2]) { | ||
throw new TomlError('multiline strings are not allowed in keys', { | ||
throw new error_js_1.TomlError('multiline strings are not allowed in keys', { | ||
toml: str, | ||
@@ -58,5 +61,5 @@ ptr: ptr, | ||
} | ||
let eos = getStringEnd(str, ptr); | ||
let eos = (0, util_js_1.getStringEnd)(str, ptr); | ||
if (eos < 0) { | ||
throw new TomlError('unfinished string encountered', { | ||
throw new error_js_1.TomlError('unfinished string encountered', { | ||
toml: str, | ||
@@ -68,5 +71,5 @@ ptr: ptr, | ||
let strEnd = str.slice(eos, dot < 0 || dot > endPtr ? endPtr : dot); | ||
let newLine = indexOfNewline(strEnd); | ||
let newLine = (0, util_js_1.indexOfNewline)(strEnd); | ||
if (newLine > -1) { | ||
throw new TomlError('newlines are not allowed in keys', { | ||
throw new error_js_1.TomlError('newlines are not allowed in keys', { | ||
toml: str, | ||
@@ -77,3 +80,3 @@ ptr: ptr + dot + newLine, | ||
if (strEnd.trimStart()) { | ||
throw new TomlError('found extra tokens after the string part', { | ||
throw new error_js_1.TomlError('found extra tokens after the string part', { | ||
toml: str, | ||
@@ -86,3 +89,3 @@ ptr: eos, | ||
if (endPtr < 0) { | ||
throw new TomlError('incomplete key-value: cannot find end of key', { | ||
throw new error_js_1.TomlError('incomplete key-value: cannot find end of key', { | ||
toml: str, | ||
@@ -93,3 +96,3 @@ ptr: ptr, | ||
} | ||
parsed.push(parseString(str, ptr, eos)); | ||
parsed.push((0, primitive_js_1.parseString)(str, ptr, eos)); | ||
} | ||
@@ -101,3 +104,3 @@ else { | ||
if (!KEY_PART_RE.test(part)) { | ||
throw new TomlError('only letter, numbers, dashes and underscores are allowed in keys', { | ||
throw new error_js_1.TomlError('only letter, numbers, dashes and underscores are allowed in keys', { | ||
toml: str, | ||
@@ -112,5 +115,6 @@ ptr: ptr, | ||
} while (dot + 1 && dot < endPtr); | ||
return [parsed, skipVoid(str, endPtr + 1, true, true)]; | ||
return [parsed, (0, util_js_1.skipVoid)(str, endPtr + 1, true, true)]; | ||
} | ||
export function parseInlineTable(str, ptr) { | ||
exports.parseKey = parseKey; | ||
function parseInlineTable(str, ptr) { | ||
let res = {}; | ||
@@ -123,3 +127,3 @@ let seen = new Set(); | ||
if (c === '\n') { | ||
throw new TomlError('newlines are not allowed in inline tables', { | ||
throw new error_js_1.TomlError('newlines are not allowed in inline tables', { | ||
toml: str, | ||
@@ -130,3 +134,3 @@ ptr: ptr - 1 | ||
else if (c === '#') { | ||
throw new TomlError('inline tables cannot contain comments', { | ||
throw new error_js_1.TomlError('inline tables cannot contain comments', { | ||
toml: str, | ||
@@ -137,3 +141,3 @@ ptr: ptr - 1 | ||
else if (c === ',') { | ||
throw new TomlError('expected key-value, found comma', { | ||
throw new error_js_1.TomlError('expected key-value, found comma', { | ||
toml: str, | ||
@@ -153,3 +157,3 @@ ptr: ptr - 1 | ||
if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== 'object' || seen.has(t[k]))) { | ||
throw new TomlError('trying to redefine an already defined value', { | ||
throw new error_js_1.TomlError('trying to redefine an already defined value', { | ||
toml: str, | ||
@@ -164,3 +168,3 @@ ptr: ptr | ||
if (hasOwn) { | ||
throw new TomlError('trying to redefine an already defined value', { | ||
throw new error_js_1.TomlError('trying to redefine an already defined value', { | ||
toml: str, | ||
@@ -170,3 +174,3 @@ ptr: ptr | ||
} | ||
let [value, valueEndPtr] = extractValue(str, keyEndPtr, '}'); | ||
let [value, valueEndPtr] = (0, extract_js_1.extractValue)(str, keyEndPtr, '}'); | ||
seen.add(value); | ||
@@ -179,3 +183,3 @@ t[k] = value; | ||
if (comma) { | ||
throw new TomlError('trailing commas are not allowed in inline tables', { | ||
throw new error_js_1.TomlError('trailing commas are not allowed in inline tables', { | ||
toml: str, | ||
@@ -186,3 +190,3 @@ ptr: comma | ||
if (!c) { | ||
throw new TomlError('unfinished table encountered', { | ||
throw new error_js_1.TomlError('unfinished table encountered', { | ||
toml: str, | ||
@@ -194,3 +198,4 @@ ptr: ptr | ||
} | ||
export function parseArray(str, ptr) { | ||
exports.parseInlineTable = parseInlineTable; | ||
function parseArray(str, ptr) { | ||
let res = []; | ||
@@ -201,3 +206,3 @@ let c; | ||
if (c === ',') { | ||
throw new TomlError('expected value, found comma', { | ||
throw new error_js_1.TomlError('expected value, found comma', { | ||
toml: str, | ||
@@ -208,5 +213,5 @@ ptr: ptr - 1 | ||
else if (c === '#') | ||
ptr = skipComment(str, ptr); | ||
ptr = (0, util_js_1.skipComment)(str, ptr); | ||
else if (c !== ' ' && c !== '\t' && c !== '\n' && c !== '\r') { | ||
let e = extractValue(str, ptr - 1, ']'); | ||
let e = (0, extract_js_1.extractValue)(str, ptr - 1, ']'); | ||
res.push(e[0]); | ||
@@ -217,3 +222,3 @@ ptr = e[1]; | ||
if (!c) { | ||
throw new TomlError('unfinished array encountered', { | ||
throw new error_js_1.TomlError('unfinished array encountered', { | ||
toml: str, | ||
@@ -225,1 +230,2 @@ ptr: ptr | ||
} | ||
exports.parseArray = parseArray; |
@@ -28,3 +28,3 @@ /*! | ||
*/ | ||
import TomlDate from './date.js'; | ||
import type { TomlDate } from './date.js'; | ||
export type TomlPrimitive = string | number | boolean | TomlDate | { | ||
@@ -31,0 +31,0 @@ [key: string]: TomlPrimitive; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/*! | ||
@@ -28,4 +29,6 @@ * Copyright (c) Squirrel Chat et al., All rights reserved. | ||
*/ | ||
import TomlError from './error.js'; | ||
export function indexOfNewline(str, start = 0, end = str.length) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getStringEnd = exports.skipUntil = exports.skipVoid = exports.skipComment = exports.indexOfNewline = void 0; | ||
const error_js_1 = require("./error.js"); | ||
function indexOfNewline(str, start = 0, end = str.length) { | ||
let idx = str.indexOf('\n', start); | ||
@@ -36,3 +39,4 @@ if (str[idx - 1] === '\r') | ||
} | ||
export function skipComment(str, ptr) { | ||
exports.indexOfNewline = indexOfNewline; | ||
function skipComment(str, ptr) { | ||
for (let i = ptr; i < str.length; i++) { | ||
@@ -45,3 +49,3 @@ let c = str[i]; | ||
if ((c < '\x20' && c !== '\t') || c === '\x7f') { | ||
throw new TomlError('control characters are not allowed in comments', { | ||
throw new error_js_1.TomlError('control characters are not allowed in comments', { | ||
toml: str, | ||
@@ -54,3 +58,4 @@ ptr: ptr, | ||
} | ||
export function skipVoid(str, ptr, banNewLines, banComments) { | ||
exports.skipComment = skipComment; | ||
function skipVoid(str, ptr, banNewLines, banComments) { | ||
let c; | ||
@@ -63,3 +68,4 @@ while ((c = str[ptr]) === ' ' || c === '\t' || (!banNewLines && (c === '\n' || c === '\r' && str[ptr + 1] === '\n'))) | ||
} | ||
export function skipUntil(str, ptr, sep, end, banNewLines = false) { | ||
exports.skipVoid = skipVoid; | ||
function skipUntil(str, ptr, sep, end, banNewLines = false) { | ||
if (!end) { | ||
@@ -84,3 +90,3 @@ ptr = indexOfNewline(str, ptr); | ||
} | ||
throw new TomlError('cannot find end of structure', { | ||
throw new error_js_1.TomlError('cannot find end of structure', { | ||
toml: str, | ||
@@ -90,3 +96,4 @@ ptr: ptr | ||
} | ||
export function getStringEnd(str, seek) { | ||
exports.skipUntil = skipUntil; | ||
function getStringEnd(str, seek) { | ||
let first = str[seek]; | ||
@@ -111,1 +118,2 @@ let target = first === str[seek + 1] && str[seek + 1] === str[seek + 2] | ||
} | ||
exports.getStringEnd = getStringEnd; |
{ | ||
"name": "smol-toml", | ||
"version": "1.1.4", | ||
"version": "1.2.0", | ||
"keywords": [ | ||
@@ -10,9 +10,11 @@ "toml", | ||
"description": "A small, fast, and correct TOML parser/serializer", | ||
"repository": "git@github.com:squirrelchat/smol-toml.git", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/squirrelchat/smol-toml.git" | ||
}, | ||
"author": "Cynthia <cyyynthia@borkenware.com>", | ||
"license": "BSD-3-Clause", | ||
"type": "module", | ||
"engines": { | ||
"node": ">= 18", | ||
"pnpm": ">= 8" | ||
"pnpm": ">= 9" | ||
}, | ||
@@ -28,9 +30,9 @@ "scripts": { | ||
"@ltd/j-toml": "^1.38.0", | ||
"@tsconfig/node-lts": "^20.1.1", | ||
"@tsconfig/strictest": "^2.0.2", | ||
"@types/node": "^20.11.5", | ||
"@vitest/ui": "^1.2.1", | ||
"@tsconfig/node-lts": "^20.1.3", | ||
"@tsconfig/strictest": "^2.0.5", | ||
"@types/node": "^20.12.11", | ||
"@vitest/ui": "^1.6.0", | ||
"fast-toml": "^0.5.4", | ||
"typescript": "^5.3.3", | ||
"vitest": "^1.2.1" | ||
"typescript": "^5.4.5", | ||
"vitest": "^1.6.0" | ||
}, | ||
@@ -37,0 +39,0 @@ "exports": { |
@@ -14,4 +14,5 @@ # smol-toml | ||
smol-toml passes most of the tests from [BurntSushi's `toml-test` suite](https://github.com/BurntSushi/toml-test). | ||
However, due to the nature of JavaScript and the limits of the language, it doesn't pass certain tests, namely: | ||
smol-toml passes most of the tests from the [`toml-test` suite](https://github.com/toml-lang/toml-test); use the | ||
`run-toml-test.bash` script to run the tests. Due to the nature of JavaScript and the limits of the language, | ||
it doesn't pass certain tests, namely: | ||
- Invalid UTF-8 strings are not rejected | ||
@@ -23,21 +24,2 @@ - Certain invalid UTF-8 codepoints are not rejected | ||
smol-toml also passes all of the tests in https://github.com/iarna/toml-spec-tests. | ||
<details> | ||
<summary>List of failed `toml-test` cases</summary> | ||
These tests were done by modifying `primitive.ts` and make the implementation return bigints for integers. This allows | ||
verifying the parser correctly intents a number to be an integer or a float. | ||
*Ideally, this becomes an option of the library, but for now...* | ||
The following parse tests are failing: | ||
- invalid/encoding/bad-utf8-in-comment | ||
- invalid/encoding/bad-utf8-in-multiline-literal | ||
- invalid/encoding/bad-utf8-in-multiline | ||
- invalid/encoding/bad-utf8-in-string-literal | ||
- invalid/encoding/bad-utf8-in-string | ||
- invalid/string/bad-codepoint | ||
</details> | ||
## Installation | ||
@@ -60,2 +42,9 @@ ``` | ||
Alternatively, if you prefer something similar to the JSON global, you can import the library as follows | ||
```js | ||
import TOML from 'smol-toml' | ||
TOML.stringify({ ... }) | ||
``` | ||
A few notes on the `stringify` function: | ||
@@ -115,6 +104,7 @@ - `undefined` and `null` values on objects are ignored (does not produce a key/value). | ||
outperform other parsers, mostly due to their lack of compliance with the spec. For example, to parse a string, | ||
`fast-toml` skips the entire string while `smol-toml` does validate the string, costing a fair chair of performance. | ||
`fast-toml` skips the entire string while `smol-toml` does validate the string, costing a fair share of performance. | ||
The ~5MB test file used for benchmark here is filled with random data which attempts to be close-ish to reality. The | ||
idea is to have a file relatively close to a real-world application. | ||
The ~5MB test file used for benchmark here is filled with random data which attempts to be close-ish to reality in | ||
terms of structure. The idea is to have a file relatively close to a real-world application, with moderately sized | ||
strings etc. | ||
@@ -196,5 +186,5 @@ The large TOML generator can be found [here](https://gist.github.com/cyyynthia/e77c744cb6494dabe37d0182506526b9) | ||
For the reference anyways, `toml-nodejs` (with proper imports) is ~8x slower on both parse benchmark with: | ||
For the reference anyway, `toml-nodejs` (with proper imports) is ~8x slower on both parse benchmark with: | ||
- spec example: 7,543.47 op/s | ||
- 5mb mixed: 0.7006 op/s | ||
</details> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
73708
1439
0
186
No