UNPKG

sheetxl

Version:

SheetXL - Command line tool

556 lines (555 loc) 30.6 kB
/** * @license sheetxl - SheetXL - Command line tool - v0.7.26 * * (C) 2025-present SheetXL Inc. & Michael T. Ford * License: The license can be found at https://www.sheetxl.com/license. */ import { l as e } from "../cli.js"; import t from "stream"; function i(e3, t2) { for (var i2 = 0; i2 < t2.length; i2++) { const r2 = t2[i2]; if ("string" != typeof r2 && !Array.isArray(r2)) { for (const t3 in r2) if ("default" !== t3 && !(t3 in e3)) { const i3 = Object.getOwnPropertyDescriptor(r2, t3); i3 && Object.defineProperty(e3, t3, i3.get ? i3 : { enumerable: true, get: () => r2[t3] }); } } } return Object.freeze(Object.defineProperty(e3, Symbol.toStringTag, { value: "Module" })); } var r, n = { exports: {} }; var s = (r || (r = 1, n.exports = (function e2() { var i2 = "undefined" != typeof self ? self : "undefined" != typeof window ? window : void 0 !== i2 ? i2 : {}; function r2() { var t2 = i2.URL || i2.webkitURL || null, r3 = e2.toString(); return h.BLOB_URL || (h.BLOB_URL = t2.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ", "(", r3, ")();"], { type: "text/javascript" }))); } var n2 = !i2.document && !!i2.postMessage, s2 = i2.IS_PAPA_WORKER || false, a2 = {}, o = 0, h = {}; if (h.parse = f, h.unparse = d, h.RECORD_SEP = String.fromCharCode(30), h.UNIT_SEP = String.fromCharCode(31), h.BYTE_ORDER_MARK = "\uFEFF", h.BAD_DELIMITERS = ["\r", "\n", '"', h.BYTE_ORDER_MARK], h.WORKERS_SUPPORTED = !n2 && !!i2.Worker, h.NODE_STREAM_INPUT = 1, h.LocalChunkSize = 10485760, h.RemoteChunkSize = 5242880, h.DefaultDelimiter = ",", h.Parser = k, h.ParserHandle = y, h.NetworkStreamer = c, h.FileStreamer = p, h.StringStreamer = _, h.ReadableStreamStreamer = g, "undefined" == typeof PAPA_BROWSER_CONTEXT && (h.DuplexStreamStreamer = m), i2.jQuery) { var u = i2.jQuery; u.fn.parse = function(e3) { var t2 = e3.config || {}, r3 = []; return this.each(function(e4) { if ("INPUT" !== u(this).prop("tagName").toUpperCase() || "file" !== u(this).attr("type").toLowerCase() || !i2.FileReader || !this.files || 0 === this.files.length) return true; for (var n4 = 0; n4 < this.files.length; n4++) r3.push({ file: this.files[n4], inputElem: this, instanceConfig: u.extend({}, t2) }); }), n3(), this; function n3() { if (0 !== r3.length) { var t3 = r3[0]; if (x(e3.before)) { var i3 = e3.before(t3.file, t3.inputElem); if ("object" == typeof i3) { if ("abort" === i3.action) return void s3("AbortError", t3.file, t3.inputElem, i3.reason); if ("skip" === i3.action) return void a3(); "object" == typeof i3.config && (t3.instanceConfig = u.extend(t3.instanceConfig, i3.config)); } else if ("skip" === i3) return void a3(); } var n4 = t3.instanceConfig.complete; t3.instanceConfig.complete = function(e4) { x(n4) && n4(e4, t3.file, t3.inputElem), a3(); }, h.parse(t3.file, t3.instanceConfig); } else x(e3.complete) && e3.complete(); } function s3(t3, i3, r4, n4) { x(e3.error) && e3.error({ name: t3 }, i3, r4, n4); } function a3() { r3.splice(0, 1), n3(); } }; } function f(e3, t2) { var r3 = (t2 = t2 || {}).dynamicTyping || false; if (x(r3) && (t2.dynamicTypingFunction = r3, r3 = {}), t2.dynamicTyping = r3, t2.transform = !!x(t2.transform) && t2.transform, t2.worker && h.WORKERS_SUPPORTED) { var n3 = b(); return n3.userStep = t2.step, n3.userChunk = t2.chunk, n3.userComplete = t2.complete, n3.userError = t2.error, t2.step = x(t2.step), t2.chunk = x(t2.chunk), t2.complete = x(t2.complete), t2.error = x(t2.error), delete t2.worker, void n3.postMessage({ input: e3, config: t2, workerId: n3.id }); } var s3 = null; return e3 === h.NODE_STREAM_INPUT && "undefined" == typeof PAPA_BROWSER_CONTEXT ? (s3 = new m(t2)).getStream() : ("string" == typeof e3 ? (e3 = a3(e3), s3 = t2.download ? new c(t2) : new _(t2)) : true === e3.readable && x(e3.read) && x(e3.on) ? s3 = new g(t2) : (i2.File && e3 instanceof File || e3 instanceof Object) && (s3 = new p(t2)), s3.stream(e3)); function a3(e4) { return 65279 === e4.charCodeAt(0) ? e4.slice(1) : e4; } } function d(e3, t2) { var i3 = false, r3 = true, n3 = ",", s3 = "\r\n", a3 = '"', o2 = a3 + a3, u2 = false, f2 = null, d2 = false; c2(); var l2 = new RegExp(v(a3), "g"); if ("string" == typeof e3 && (e3 = JSON.parse(e3)), Array.isArray(e3)) { if (!e3.length || Array.isArray(e3[0])) return p2(null, e3, u2); if ("object" == typeof e3[0]) return p2(f2 || Object.keys(e3[0]), e3, u2); } else if ("object" == typeof e3) return "string" == typeof e3.data && (e3.data = JSON.parse(e3.data)), Array.isArray(e3.data) && (e3.fields || (e3.fields = e3.meta && e3.meta.fields || f2), e3.fields || (e3.fields = Array.isArray(e3.data[0]) ? e3.fields : "object" == typeof e3.data[0] ? Object.keys(e3.data[0]) : []), Array.isArray(e3.data[0]) || "object" == typeof e3.data[0] || (e3.data = [e3.data])), p2(e3.fields || [], e3.data || [], u2); throw new Error("Unable to serialize unrecognized input"); function c2() { if ("object" == typeof t2) { if ("string" != typeof t2.delimiter || h.BAD_DELIMITERS.filter(function(e4) { return -1 !== t2.delimiter.indexOf(e4); }).length || (n3 = t2.delimiter), ("boolean" == typeof t2.quotes || "function" == typeof t2.quotes || Array.isArray(t2.quotes)) && (i3 = t2.quotes), "boolean" != typeof t2.skipEmptyLines && "string" != typeof t2.skipEmptyLines || (u2 = t2.skipEmptyLines), "string" == typeof t2.newline && (s3 = t2.newline), "string" == typeof t2.quoteChar && (a3 = t2.quoteChar), "boolean" == typeof t2.header && (r3 = t2.header), Array.isArray(t2.columns)) { if (0 === t2.columns.length) throw new Error("Option columns is empty"); f2 = t2.columns; } void 0 !== t2.escapeChar && (o2 = t2.escapeChar + a3), t2.escapeFormulae instanceof RegExp ? d2 = t2.escapeFormulae : "boolean" == typeof t2.escapeFormulae && t2.escapeFormulae && (d2 = /^[=+\-@\t\r].*$/); } } function p2(e4, t3, i4) { var a4 = ""; "string" == typeof e4 && (e4 = JSON.parse(e4)), "string" == typeof t3 && (t3 = JSON.parse(t3)); var o3 = Array.isArray(e4) && e4.length > 0, h2 = !Array.isArray(t3[0]); if (o3 && r3) { for (var u3 = 0; u3 < e4.length; u3++) u3 > 0 && (a4 += n3), a4 += _2(e4[u3], u3); t3.length > 0 && (a4 += s3); } for (var f3 = 0; f3 < t3.length; f3++) { var d3 = o3 ? e4.length : t3[f3].length, l3 = false, c3 = o3 ? 0 === Object.keys(t3[f3]).length : 0 === t3[f3].length; if (i4 && !o3 && (l3 = "greedy" === i4 ? "" === t3[f3].join("").trim() : 1 === t3[f3].length && 0 === t3[f3][0].length), "greedy" === i4 && o3) { for (var p3 = [], g3 = 0; g3 < d3; g3++) { var m2 = h2 ? e4[g3] : g3; p3.push(t3[f3][m2]); } l3 = "" === p3.join("").trim(); } if (!l3) { for (var y2 = 0; y2 < d3; y2++) { y2 > 0 && !c3 && (a4 += n3); var v2 = o3 && h2 ? e4[y2] : y2; a4 += _2(t3[f3][v2], y2); } f3 < t3.length - 1 && (!i4 || d3 > 0 && !c3) && (a4 += s3); } } return a4; } function _2(e4, t3) { if (null == e4) return ""; if (e4.constructor === Date) return JSON.stringify(e4).slice(1, 25); var r4 = false; d2 && "string" == typeof e4 && d2.test(e4) && (e4 = "'" + e4, r4 = true); var s4 = e4.toString().replace(l2, o2); return (r4 = r4 || true === i3 || "function" == typeof i3 && i3(e4, t3) || Array.isArray(i3) && i3[t3] || g2(s4, h.BAD_DELIMITERS) || s4.indexOf(n3) > -1 || " " === s4.charAt(0) || " " === s4.charAt(s4.length - 1)) ? a3 + s4 + a3 : s4; } function g2(e4, t3) { for (var i4 = 0; i4 < t3.length; i4++) if (e4.indexOf(t3[i4]) > -1) return true; return false; } } function l(e3) { function t2(e4) { var t3 = S(e4); t3.chunkSize = parseInt(t3.chunkSize), e4.step || e4.chunk || (t3.chunkSize = null), this._handle = new y(t3), this._handle.streamer = this, this._config = t3; } this._handle = null, this._finished = false, this._completed = false, this._halted = false, this._input = null, this._baseIndex = 0, this._partialLine = "", this._rowCount = 0, this._start = 0, this._nextChunk = null, this.isFirstChunk = true, this._completeResults = { data: [], errors: [], meta: {} }, t2.call(this, e3), this.parseChunk = function(e4, t3) { const r3 = parseInt(this._config.skipFirstNLines) || 0; if (this.isFirstChunk && r3 > 0) { let t4 = this._config.newline; if (!t4) { const i4 = this._config.quoteChar || '"'; t4 = this._handle.guessLineEndings(e4, i4); } const i3 = e4.split(t4); e4 = [...i3.slice(r3)].join(t4); } if (this.isFirstChunk && x(this._config.beforeFirstChunk)) { var n3 = this._config.beforeFirstChunk(e4); void 0 !== n3 && (e4 = n3); } this.isFirstChunk = false, this._halted = false; var a3 = this._partialLine + e4; this._partialLine = ""; var o2 = this._handle.parse(a3, this._baseIndex, !this._finished); if (!this._handle.paused() && !this._handle.aborted()) { var u2 = o2.meta.cursor; this._finished || (this._partialLine = a3.substring(u2 - this._baseIndex), this._baseIndex = u2), o2 && o2.data && (this._rowCount += o2.data.length); var f2 = this._finished || this._config.preview && this._rowCount >= this._config.preview; if (s2) i2.postMessage({ results: o2, workerId: h.WORKER_ID, finished: f2 }); else if (x(this._config.chunk) && !t3) { if (this._config.chunk(o2, this._handle), this._handle.paused() || this._handle.aborted()) return void (this._halted = true); o2 = void 0, this._completeResults = void 0; } return this._config.step || this._config.chunk || (this._completeResults.data = this._completeResults.data.concat(o2.data), this._completeResults.errors = this._completeResults.errors.concat(o2.errors), this._completeResults.meta = o2.meta), this._completed || !f2 || !x(this._config.complete) || o2 && o2.meta.aborted || (this._config.complete(this._completeResults, this._input), this._completed = true), f2 || o2 && o2.meta.paused || this._nextChunk(), o2; } this._halted = true; }, this._sendError = function(e4) { x(this._config.error) ? this._config.error(e4) : s2 && this._config.error && i2.postMessage({ workerId: h.WORKER_ID, error: e4, finished: false }); }; } function c(e3) { var t2; function i3(e4) { var t3 = e4.getResponseHeader("Content-Range"); return null === t3 ? -1 : parseInt(t3.substring(t3.lastIndexOf("/") + 1)); } (e3 = e3 || {}).chunkSize || (e3.chunkSize = h.RemoteChunkSize), l.call(this, e3), this._nextChunk = n2 ? function() { this._readChunk(), this._chunkLoaded(); } : function() { this._readChunk(); }, this.stream = function(e4) { this._input = e4, this._nextChunk(); }, this._readChunk = function() { if (this._finished) this._chunkLoaded(); else { if (t2 = new XMLHttpRequest(), this._config.withCredentials && (t2.withCredentials = this._config.withCredentials), n2 || (t2.onload = O(this._chunkLoaded, this), t2.onerror = O(this._chunkError, this)), t2.open(this._config.downloadRequestBody ? "POST" : "GET", this._input, !n2), this._config.downloadRequestHeaders) { var e4 = this._config.downloadRequestHeaders; for (var i4 in e4) t2.setRequestHeader(i4, e4[i4]); } if (this._config.chunkSize) { var r3 = this._start + this._config.chunkSize - 1; t2.setRequestHeader("Range", "bytes=" + this._start + "-" + r3); } try { t2.send(this._config.downloadRequestBody); } catch (e5) { this._chunkError(e5.message); } n2 && 0 === t2.status && this._chunkError(); } }, this._chunkLoaded = function() { 4 === t2.readyState && (t2.status < 200 || t2.status >= 400 ? this._chunkError() : (this._start += this._config.chunkSize ? this._config.chunkSize : t2.responseText.length, this._finished = !this._config.chunkSize || this._start >= i3(t2), this.parseChunk(t2.responseText))); }, this._chunkError = function(e4) { var i4 = t2.statusText || e4; this._sendError(new Error(i4)); }; } function p(e3) { var t2, i3; (e3 = e3 || {}).chunkSize || (e3.chunkSize = h.LocalChunkSize), l.call(this, e3); var r3 = "undefined" != typeof FileReader; this.stream = function(e4) { this._input = e4, i3 = e4.slice || e4.webkitSlice || e4.mozSlice, r3 ? ((t2 = new FileReader()).onload = O(this._chunkLoaded, this), t2.onerror = O(this._chunkError, this)) : t2 = new FileReaderSync(), this._nextChunk(); }, this._nextChunk = function() { this._finished || this._config.preview && !(this._rowCount < this._config.preview) || this._readChunk(); }, this._readChunk = function() { var e4 = this._input; if (this._config.chunkSize) { var n3 = Math.min(this._start + this._config.chunkSize, this._input.size); e4 = i3.call(e4, this._start, n3); } var s3 = t2.readAsText(e4, this._config.encoding); r3 || this._chunkLoaded({ target: { result: s3 } }); }, this._chunkLoaded = function(e4) { this._start += this._config.chunkSize, this._finished = !this._config.chunkSize || this._start >= this._input.size, this.parseChunk(e4.target.result); }, this._chunkError = function() { this._sendError(t2.error); }; } function _(e3) { var t2; e3 = e3 || {}, l.call(this, e3), this.stream = function(e4) { return t2 = e4, this._nextChunk(); }, this._nextChunk = function() { if (!this._finished) { var e4, i3 = this._config.chunkSize; return i3 ? (e4 = t2.substring(0, i3), t2 = t2.substring(i3)) : (e4 = t2, t2 = ""), this._finished = !t2, this.parseChunk(e4); } }; } function g(e3) { e3 = e3 || {}, l.call(this, e3); var t2 = [], i3 = true, r3 = false; this.pause = function() { l.prototype.pause.apply(this, arguments), this._input.pause(); }, this.resume = function() { l.prototype.resume.apply(this, arguments), this._input.resume(); }, this.stream = function(e4) { this._input = e4, this._input.on("data", this._streamData), this._input.on("end", this._streamEnd), this._input.on("error", this._streamError); }, this._checkIsFinished = function() { r3 && 1 === t2.length && (this._finished = true); }, this._nextChunk = function() { this._checkIsFinished(), t2.length ? this.parseChunk(t2.shift()) : i3 = true; }, this._streamData = O(function(e4) { try { t2.push("string" == typeof e4 ? e4 : e4.toString(this._config.encoding)), i3 && (i3 = false, this._checkIsFinished(), this.parseChunk(t2.shift())); } catch (e5) { this._streamError(e5); } }, this), this._streamError = O(function(e4) { this._streamCleanUp(), this._sendError(e4); }, this), this._streamEnd = O(function() { this._streamCleanUp(), r3 = true, this._streamData(""); }, this), this._streamCleanUp = O(function() { this._input.removeListener("data", this._streamData), this._input.removeListener("end", this._streamEnd), this._input.removeListener("error", this._streamError); }, this); } function m(e3) { var i3 = t.Duplex, r3 = S(e3), n3 = true, s3 = false, a3 = [], o2 = null; this._onCsvData = function(e4) { var t2 = e4.data; o2.push(t2) || this._handle.paused() || this._handle.pause(); }, this._onCsvComplete = function() { o2.push(null); }, r3.step = O(this._onCsvData, this), r3.complete = O(this._onCsvComplete, this), l.call(this, r3), this._nextChunk = function() { s3 && 1 === a3.length && (this._finished = true), a3.length ? a3.shift()() : n3 = true; }, this._addToParseQueue = function(e4, t2) { a3.push(O(function() { if (this.parseChunk("string" == typeof e4 ? e4 : e4.toString(r3.encoding)), x(t2)) return t2(); }, this)), n3 && (n3 = false, this._nextChunk()); }, this._onRead = function() { this._handle.paused() && this._handle.resume(); }, this._onWrite = function(e4, t2, i4) { this._addToParseQueue(e4, i4); }, this._onWriteComplete = function() { s3 = true, this._addToParseQueue(""); }, this.getStream = function() { return o2; }, (o2 = new i3({ readableObjectMode: true, decodeStrings: false, read: O(this._onRead, this), write: O(this._onWrite, this) })).once("finish", O(this._onWriteComplete, this)); } function y(e3) { var t2, i3, r3, n3 = Math.pow(2, 53), s3 = -n3, a3 = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/, o2 = /^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/, u2 = this, f2 = 0, d2 = 0, l2 = false, c2 = false, p2 = [], _2 = { data: [], errors: [], meta: {} }; if (x(e3.step)) { var g2 = e3.step; e3.step = function(t3) { if (_2 = t3, E2()) b2(); else { if (b2(), 0 === _2.data.length) return; f2 += t3.data.length, e3.preview && f2 > e3.preview ? i3.abort() : (_2.data = _2.data[0], g2(_2, u2)); } }; } function m2(t3) { return "greedy" === e3.skipEmptyLines ? "" === t3.join("").trim() : 1 === t3.length && 0 === t3[0].length; } function y2(e4) { if (a3.test(e4)) { var t3 = parseFloat(e4); if (t3 > s3 && t3 < n3) return true; } return false; } function b2() { return _2 && r3 && (A("Delimiter", "UndetectableDelimiter", "Unable to auto-detect delimiting character; defaulted to '" + h.DefaultDelimiter + "'"), r3 = false), e3.skipEmptyLines && (_2.data = _2.data.filter(function(e4) { return !m2(e4); })), E2() && w2(), O2(); } function E2() { return e3.header && 0 === p2.length; } function w2() { if (_2) if (Array.isArray(_2.data[0])) { for (var t3 = 0; E2() && t3 < _2.data.length; t3++) _2.data[t3].forEach(i4); _2.data.splice(0, 1); } else _2.data.forEach(i4); function i4(t4, i5) { x(e3.transformHeader) && (t4 = e3.transformHeader(t4, i5)), p2.push(t4); } } function C2(t3) { return e3.dynamicTypingFunction && void 0 === e3.dynamicTyping[t3] && (e3.dynamicTyping[t3] = e3.dynamicTypingFunction(t3)), true === (e3.dynamicTyping[t3] || e3.dynamicTyping); } function R2(e4, t3) { return C2(e4) ? "true" === t3 || "TRUE" === t3 || "false" !== t3 && "FALSE" !== t3 && (y2(t3) ? parseFloat(t3) : o2.test(t3) ? new Date(t3) : "" === t3 ? null : t3) : t3; } function O2() { if (!_2 || !e3.header && !e3.dynamicTyping && !e3.transform) return _2; function t3(t4, i5) { var r4, n4 = e3.header ? {} : []; for (r4 = 0; r4 < t4.length; r4++) { var s4 = r4, a4 = t4[r4]; e3.header && (s4 = r4 >= p2.length ? "__parsed_extra" : p2[r4]), e3.transform && (a4 = e3.transform(a4, s4)), a4 = R2(s4, a4), "__parsed_extra" === s4 ? (n4[s4] = n4[s4] || [], n4[s4].push(a4)) : n4[s4] = a4; } return e3.header && (r4 > p2.length ? A("FieldMismatch", "TooManyFields", "Too many fields: expected " + p2.length + " fields but parsed " + r4, d2 + i5) : r4 < p2.length && A("FieldMismatch", "TooFewFields", "Too few fields: expected " + p2.length + " fields but parsed " + r4, d2 + i5)), n4; } var i4 = 1; return !_2.data.length || Array.isArray(_2.data[0]) ? (_2.data = _2.data.map(t3), i4 = _2.data.length) : _2.data = t3(_2.data, 0), e3.header && _2.meta && (_2.meta.fields = p2), d2 += i4, _2; } function T(t3, i4, r4, n4, s4) { var a4, o3, u3, f3; s4 = s4 || [",", " ", "|", ";", h.RECORD_SEP, h.UNIT_SEP]; for (var d3 = 0; d3 < s4.length; d3++) { var l3 = s4[d3], c3 = 0, p3 = 0, _3 = 0; u3 = void 0; for (var g3 = new k({ comments: n4, delimiter: l3, newline: i4, preview: 10 }).parse(t3), y3 = 0; y3 < g3.data.length; y3++) if (r4 && m2(g3.data[y3])) _3++; else { var v2 = g3.data[y3].length; p3 += v2, void 0 !== u3 ? v2 > 0 && (c3 += Math.abs(v2 - u3), u3 = v2) : u3 = v2; } g3.data.length > 0 && (p3 /= g3.data.length - _3), (void 0 === o3 || c3 <= o3) && (void 0 === f3 || p3 > f3) && p3 > 1.99 && (o3 = c3, a4 = l3, f3 = p3); } return e3.delimiter = a4, { successful: !!a4, bestDelimiter: a4 }; } function A(e4, t3, i4, r4) { var n4 = { type: e4, code: t3, message: i4 }; void 0 !== r4 && (n4.row = r4), _2.errors.push(n4); } this.parse = function(n4, s4, a4) { var o3 = e3.quoteChar || '"'; if (e3.newline || (e3.newline = this.guessLineEndings(n4, o3)), r3 = false, e3.delimiter) x(e3.delimiter) && (e3.delimiter = e3.delimiter(n4), _2.meta.delimiter = e3.delimiter); else { var u3 = T(n4, e3.newline, e3.skipEmptyLines, e3.comments, e3.delimitersToGuess); u3.successful ? e3.delimiter = u3.bestDelimiter : (r3 = true, e3.delimiter = h.DefaultDelimiter), _2.meta.delimiter = e3.delimiter; } var f3 = S(e3); return e3.preview && e3.header && f3.preview++, t2 = n4, i3 = new k(f3), _2 = i3.parse(t2, s4, a4), b2(), l2 ? { meta: { paused: true } } : _2 || { meta: { paused: false } }; }, this.paused = function() { return l2; }, this.pause = function() { l2 = true, i3.abort(), t2 = x(e3.chunk) ? "" : t2.substring(i3.getCharIndex()); }, this.resume = function() { u2.streamer._halted ? (l2 = false, u2.streamer.parseChunk(t2, true)) : setTimeout(u2.resume, 3); }, this.aborted = function() { return c2; }, this.abort = function() { c2 = true, i3.abort(), _2.meta.aborted = true, x(e3.complete) && e3.complete(_2), t2 = ""; }, this.guessLineEndings = function(e4, t3) { e4 = e4.substring(0, 1048576); var i4 = new RegExp(v(t3) + "([^]*?)" + v(t3), "gm"), r4 = (e4 = e4.replace(i4, "")).split("\r"), n4 = e4.split("\n"), s4 = n4.length > 1 && n4[0].length < r4[0].length; if (1 === r4.length || s4) return "\n"; for (var a4 = 0, o3 = 0; o3 < r4.length; o3++) "\n" === r4[o3][0] && a4++; return a4 >= r4.length / 2 ? "\r\n" : "\r"; }; } function v(e3) { return e3.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } function k(e3) { var t2, i3 = (e3 = e3 || {}).delimiter, r3 = e3.newline, n3 = e3.comments, s3 = e3.step, a3 = e3.preview, o2 = e3.fastMode, u2 = null, f2 = false, d2 = t2 = void 0 === e3.quoteChar || null === e3.quoteChar ? '"' : e3.quoteChar; if (void 0 !== e3.escapeChar && (d2 = e3.escapeChar), ("string" != typeof i3 || h.BAD_DELIMITERS.indexOf(i3) > -1) && (i3 = ","), n3 === i3) throw new Error("Comment character same as delimiter"); true === n3 ? n3 = "#" : ("string" != typeof n3 || h.BAD_DELIMITERS.indexOf(n3) > -1) && (n3 = false), "\n" !== r3 && "\r" !== r3 && "\r\n" !== r3 && (r3 = "\n"); var l2 = 0, c2 = false; this.parse = function(h2, p2, _2) { if ("string" != typeof h2) throw new Error("Input must be a string"); var g2 = h2.length, m2 = i3.length, y2 = r3.length, k2 = n3.length, b2 = x(s3); l2 = 0; var E2 = [], w2 = [], C2 = [], R2 = 0; if (!h2) return U(); if (o2 || false !== o2 && -1 === h2.indexOf(t2)) { for (var S2 = h2.split(r3), O2 = 0; O2 < S2.length; O2++) { if (C2 = S2[O2], l2 += C2.length, O2 !== S2.length - 1) l2 += r3.length; else if (_2) return U(); if (!n3 || C2.substring(0, k2) !== n3) { if (b2) { if (E2 = [], j(C2.split(i3)), q(), c2) return U(); } else j(C2.split(i3)); if (a3 && O2 >= a3) return E2 = E2.slice(0, a3), U(true); } } return U(); } for (var T = h2.indexOf(i3, l2), A = h2.indexOf(r3, l2), D = new RegExp(v(d2) + v(t2), "g"), I = h2.indexOf(t2, l2); ; ) if (h2[l2] !== t2) if (n3 && 0 === C2.length && h2.substring(l2, l2 + k2) === n3) { if (-1 === A) return U(); l2 = A + y2, A = h2.indexOf(r3, l2), T = h2.indexOf(i3, l2); } else if (-1 !== T && (T < A || -1 === A)) C2.push(h2.substring(l2, T)), l2 = T + m2, T = h2.indexOf(i3, l2); else { if (-1 === A) break; if (C2.push(h2.substring(l2, A)), M(A + y2), b2 && (q(), c2)) return U(); if (a3 && E2.length >= a3) return U(true); } else for (I = l2, l2++; ; ) { if (-1 === (I = h2.indexOf(t2, I + 1))) return _2 || w2.push({ type: "Quotes", code: "MissingQuotes", message: "Quoted field unterminated", row: E2.length, index: l2 }), z(); if (I === g2 - 1) return z(h2.substring(l2, I).replace(D, t2)); if (t2 !== d2 || h2[I + 1] !== d2) { if (t2 === d2 || 0 === I || h2[I - 1] !== d2) { -1 !== T && T < I + 1 && (T = h2.indexOf(i3, I + 1)), -1 !== A && A < I + 1 && (A = h2.indexOf(r3, I + 1)); var L = P(-1 === A ? T : Math.min(T, A)); if (h2.substr(I + 1 + L, m2) === i3) { C2.push(h2.substring(l2, I).replace(D, t2)), l2 = I + 1 + L + m2, h2[I + 1 + L + m2] !== t2 && (I = h2.indexOf(t2, l2)), T = h2.indexOf(i3, l2), A = h2.indexOf(r3, l2); break; } var F = P(A); if (h2.substring(I + 1 + F, I + 1 + F + y2) === r3) { if (C2.push(h2.substring(l2, I).replace(D, t2)), M(I + 1 + F + y2), T = h2.indexOf(i3, l2), I = h2.indexOf(t2, l2), b2 && (q(), c2)) return U(); if (a3 && E2.length >= a3) return U(true); break; } w2.push({ type: "Quotes", code: "InvalidQuotes", message: "Trailing quote on quoted field is malformed", row: E2.length, index: l2 }), I++; } } else I++; } return z(); function j(e4) { E2.push(e4), R2 = l2; } function P(e4) { var t3 = 0; if (-1 !== e4) { var i4 = h2.substring(I + 1, e4); i4 && "" === i4.trim() && (t3 = i4.length); } return t3; } function z(e4) { return _2 || (void 0 === e4 && (e4 = h2.substring(l2)), C2.push(e4), l2 = g2, j(C2), b2 && q()), U(); } function M(e4) { l2 = e4, j(C2), C2 = [], A = h2.indexOf(r3, l2); } function U(t3) { if (e3.header && !p2 && E2.length && !f2) { const t4 = E2[0], i4 = /* @__PURE__ */ Object.create(null), r4 = new Set(t4); let n4 = false; for (let s4 = 0; s4 < t4.length; s4++) { let a4 = t4[s4]; if (x(e3.transformHeader) && (a4 = e3.transformHeader(a4, s4)), i4[a4]) { let e4, o3 = i4[a4]; do { e4 = `${a4}_${o3}`, o3++; } while (r4.has(e4)); r4.add(e4), t4[s4] = e4, i4[a4]++, n4 = true, null === u2 && (u2 = {}), u2[e4] = a4; } else i4[a4] = 1, t4[s4] = a4; r4.add(a4); } n4 && console.warn("Duplicate headers found and renamed."), f2 = true; } return { data: E2, errors: w2, meta: { delimiter: i3, linebreak: r3, aborted: c2, truncated: !!t3, cursor: R2 + (p2 || 0), renamedHeaders: u2 } }; } function q() { s3(U()), E2 = [], w2 = []; } }, this.abort = function() { c2 = true; }, this.getCharIndex = function() { return l2; }; } function b() { if (!h.WORKERS_SUPPORTED) return false; var e3 = r2(), t2 = new i2.Worker(e3); return t2.onmessage = E, t2.id = o++, a2[t2.id] = t2, t2; } function E(e3) { var t2 = e3.data, i3 = a2[t2.workerId], r3 = false; if (t2.error) i3.userError(t2.error, t2.file); else if (t2.results && t2.results.data) { var n3 = { abort: function() { r3 = true, w(t2.workerId, { data: [], errors: [], meta: { aborted: true } }); }, pause: C, resume: C }; if (x(i3.userStep)) { for (var s3 = 0; s3 < t2.results.data.length && (i3.userStep({ data: t2.results.data[s3], errors: t2.results.errors, meta: t2.results.meta }, n3), !r3); s3++) ; delete t2.results; } else x(i3.userChunk) && (i3.userChunk(t2.results, n3, t2.file), delete t2.results); } t2.finished && !r3 && w(t2.workerId, t2.results); } function w(e3, t2) { var i3 = a2[e3]; x(i3.userComplete) && i3.userComplete(t2), i3.terminate(), delete a2[e3]; } function C() { throw new Error("Not implemented."); } function R(e3) { var t2 = e3.data; if (void 0 === h.WORKER_ID && t2 && (h.WORKER_ID = t2.workerId), "string" == typeof t2.input) i2.postMessage({ workerId: h.WORKER_ID, results: h.parse(t2.input, t2.config), finished: true }); else if (i2.File && t2.input instanceof File || t2.input instanceof Object) { var r3 = h.parse(t2.input, t2.config); r3 && i2.postMessage({ workerId: h.WORKER_ID, results: r3, finished: true }); } } function S(e3) { if ("object" != typeof e3 || null === e3) return e3; var t2 = Array.isArray(e3) ? [] : {}; for (var i3 in e3) t2[i3] = S(e3[i3]); return t2; } function O(e3, t2) { return function() { e3.apply(t2, arguments); }; } function x(e3) { return "function" == typeof e3; } return s2 && (i2.onmessage = R), c.prototype = Object.create(l.prototype), c.prototype.constructor = c, p.prototype = Object.create(l.prototype), p.prototype.constructor = p, _.prototype = Object.create(_.prototype), _.prototype.constructor = _, g.prototype = Object.create(l.prototype), g.prototype.constructor = g, "undefined" == typeof PAPA_BROWSER_CONTEXT && (m.prototype = Object.create(l.prototype), m.prototype.constructor = m), h; })()), n.exports); const a = i({ __proto__: null, default: e(s) }, [s]); export { a as p };