{"version":3,"file":"toml-DiUM0_qs.js","sources":["../node_modules/polyscript/esm/3rd-party/toml.js"],"sourcesContent":["/* c8 ignore start */\n/*! (c) Andrea Giammarchi - ISC */\n\nconst {isArray} = Array;\nconst {parse: jsonParse} = JSON;\n\n/** @typedef {{s: string[], d: Date[]}} Foreign foreign strings and dates */\n\n/**\n * Transform quoted keys into regular keys.\n * @param {string} str the key to eventually normalize\n * @param {Foreign} foreign foreign strings and dates\n * @returns \n */\nconst getKey = (str, {s}) => str.replace(/\"s(\\d+)\"/g, (_, $1) => s[$1]);\n\n/**\n * Given a `'string'` or a `\"string\"` returns a JSON compatible string.\n * @param {string} str a TOML entry to parse\n * @param {Foreign} foreign foreign strings and dates\n * @returns {string}\n */\nconst getValue = (str, foreign) => jsonParse(\n str.replace(/(\\S+?)\\s*=/g, '\"$1\":'),\n (_, value) => typeof value === 'string' ?\n foreign[value[0]][value.slice(1)] :\n value\n);\n\n/**\n * Crawl the `json` object via the given array of keys and handle array entries.\n * @param {string[]} keys a path with all keys to reach the entry\n * @param {Foreign} foreign foreign strings and dates\n * @param {object} entry the root entry of the TOML\n * @param {boolean} asArray handle array entries\n * @returns {object} the current entry to handle\n */\nconst getPath = (keys, foreign, entry, asArray) => {\n for (let i = 0, {length} = keys, last = length - 1; i < length; i++) {\n const key = getKey(keys[i], foreign);\n entry = entry[key] || (entry[key] = (asArray && (i === last) ? [] : {}));\n if (isArray(entry)) {\n if ((i === last) || !entry.length)\n entry.push({});\n entry = entry.at(-1);\n }\n }\n return entry;\n};\n\n/**\n * Given a TOML text, removes stirngs and dates for easier parsing +\n * remove multi-line arrays to not need evaluation.\n * @param {string} toml the TOML text to map\n * @param {string[]} strings mapped strings\n * @param {Date[]} dates mapped Dates\n * @returns {[string, Foreign]}\n */\nconst mapForeign = (toml, strings, dates) => [\n toml\n // map strings in the TOML\n .replace(\n /([\"'])(?:(?=(\\\\?))\\2.)*?\\1/g,\n value => `\"s${strings.push(value.slice(1, -1)) - 1}\"`\n )\n // map dates in the TOML\n .replace(\n /\\d{2,}([:-]\\d{2}){2}([ T:-][\\dZ:-]+)?/g,\n value => `\"d${dates.push(new Date(value)) - 1}\"`\n )\n // avoid multi-line array entries\n .replace(/,\\s*[\\r\\n]+/g, ', ')\n .replace(/\\[\\s*[\\r\\n]+/g, '[')\n .replace(/[\\r\\n]+\\s*]/g, ']'),\n {s: strings, d: dates}\n];\n\n/**\n * Given a simple subset of a TOML file, returns its JS equivalent.\n * @param {string} toml the TOML text to parse\n * @returns {object} the TOML equivalent as JSON serializable\n */\nconst parse = toml => {\n const [text, foreign] = mapForeign(toml, [], []);\n const json = {};\n let entry = json;\n for (let line of text.split(/[\\r\\n]+/)) {\n if ((line = line.trim()) && !line.startsWith('#')) {\n if (/^(\\[+)(.*?)\\]+/.test(line))\n entry = getPath(RegExp.$2.trim().split('.'), foreign, json, RegExp.$1 !== '[');\n else if (/^(\\S+?)\\s*=([^#]+)/.test(line)) {\n const {$1: key, $2: value} = RegExp;\n entry[getKey(key, foreign)] = getValue(value.trim(), foreign);\n }\n }\n }\n return json;\n};\n\nexport { parse };\n\n/* c8 ignore stop */\n"],"names":["isArray","Array","parse","jsonParse","JSON","getKey","str","s","replace","_","$1","getValue","foreign","value","slice","getPath","keys","entry","asArray","i","length","last","key","push","at","toml","text","strings","dates","Date","d","mapForeign","json","line","split","trim","startsWith","test","RegExp","$2"],"mappings":";AAGA,MAAMA,QAACA,GAAWC,OACXC,MAAOC,GAAaC,KAUrBC,EAAS,CAACC,GAAMC,OAAOD,EAAIE,QAAQ,aAAa,CAACC,EAAGC,IAAOH,EAAEG,KAQ7DC,EAAW,CAACL,EAAKM,IAAYT,EACjCG,EAAIE,QAAQ,cAAe,UAC3B,CAACC,EAAGI,IAA2B,iBAAVA,EACnBD,EAAQC,EAAM,IAAIA,EAAMC,MAAM,IAC9BD,IAWEE,EAAU,CAACC,EAAMJ,EAASK,EAAOC,KACrC,IAAK,IAAIC,EAAI,GAAGC,OAACA,GAAUJ,EA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