vlt
Version:
The vlt CLI
118 lines (114 loc) • 4.12 kB
JavaScript
var global = globalThis;
import {Buffer} from "node:buffer";
import {setTimeout,clearTimeout,setImmediate,clearImmediate,setInterval,clearInterval} from "node:timers";
import {createRequire as _vlt_createRequire} from "node:module";
var require = _vlt_createRequire(import.meta.filename);
// ../../node_modules/.pnpm/polite-json@5.0.0/node_modules/polite-json/dist/esm/index.js
var hexify = (s) => Array.from(s).map((c) => "0x" + c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")).join("");
var parseError = (e, txt, context) => {
if (!txt) {
return {
message: e.message + " while parsing empty string",
position: 0
};
}
const badToken = e.message.match(/^Unexpected (?:token (.*?))?/i);
const atPos = e.message.match(/at positions? (\d+)/);
const errIdx = /^Unexpected end of JSON|Unterminated string in JSON/i.test(e.message) ? txt.length - 1 : atPos && atPos[1] ? +atPos[1] : /is not valid JSON$/.test(e.message) ? 0 : null;
const msg = badToken && badToken[1] ? e.message.replace(/^Unexpected token ./, `Unexpected token ${JSON.stringify(badToken[1])} (${hexify(badToken[1])})`) : e.message;
if (errIdx !== null && errIdx !== void 0) {
const start = errIdx <= context ? 0 : errIdx - context;
const end = errIdx + context >= txt.length ? txt.length : errIdx + context;
const slice = (start === 0 ? "" : "...") + txt.slice(start, end) + (end === txt.length ? "" : "...");
const near = txt === slice ? "" : "near ";
return {
message: msg + ` while parsing ${near}${JSON.stringify(slice)}`,
position: errIdx
};
} else {
return {
message: msg + ` while parsing '${txt.slice(0, context * 2)}'`,
position: 0
};
}
};
var JSONParseError = class extends SyntaxError {
code;
cause;
position;
constructor(er, txt, context = 20, caller) {
const { message, position } = parseError(er, txt, context);
super(message);
this.cause = er;
this.position = position;
this.code = "EJSONPARSE";
Error.captureStackTrace(this, caller || this.constructor);
}
get name() {
return this.constructor.name;
}
set name(_) {
}
get [Symbol.toStringTag]() {
return this.constructor.name;
}
};
var kIndent = Symbol.for("indent");
var kNewline = Symbol.for("newline");
var formatRE = /^\s*[{\[]((?:\r?\n)+)([\s\t]*)/;
var emptyRE = /^(?:\{\}|\[\])((?:\r?\n)+)?$/;
var parse = (txt, reviver, context) => {
const parseText = stripBOM(String(txt));
if (!reviver)
reviver = void 0;
context = context || 20;
try {
const [, newline = "\n", indent = " "] = parseText.match(emptyRE) || parseText.match(formatRE) || [, "", ""];
const result = JSON.parse(parseText, reviver);
if (result && typeof result === "object") {
result[kNewline] = newline;
result[kIndent] = indent;
}
return result;
} catch (e) {
if (typeof txt !== "string" && !Buffer.isBuffer(txt)) {
const isEmptyArray = Array.isArray(txt) && txt.length === 0;
throw Object.assign(new TypeError(`Cannot parse ${isEmptyArray ? "an empty array" : String(txt)}`), {
code: "EJSONPARSE",
systemError: e
});
}
throw new JSONParseError(e, parseText, context, parse);
}
};
var stripBOM = (txt) => String(txt).replace(/^\uFEFF/, "");
var stringify = (obj, replacer, indent) => {
const space = indent === void 0 ? obj[kIndent] : indent;
const res = (
/* c8 ignore start */
typeof replacer === "function" ? JSON.stringify(obj, replacer, space) : JSON.stringify(obj, replacer, space)
);
const nl = obj[kNewline] || "\n";
return space ? (nl === "\n" ? res : res.split("\n").join(nl)) + nl : res;
};
// ../../node_modules/.pnpm/walk-up-path@4.0.0/node_modules/walk-up-path/dist/esm/index.js
import { dirname, resolve } from "node:path";
var walkUp = function* (path) {
for (path = resolve(path); path; ) {
yield path;
const pp = dirname(path);
if (pp === path) {
break;
} else {
path = pp;
}
}
};
export {
kIndent,
kNewline,
parse,
stringify,
walkUp
};
//# sourceMappingURL=chunk-SGEQHKFC.js.map