@sheetxl/io
Version:
IO - Import/Export Libraries for SheetXL.
426 lines (425 loc) • 26.1 kB
JavaScript
/**
* @license @sheetxl/io - IO - Import/Export Libraries for SheetXL. - v0.4.0
*
* (C) 2025-present SheetXL Inc. & Michael T. Ford
* License: The license can be found at https://www.sheetxl.com/license.
*/
function _t(Y, H) {
for (var k = 0; k < H.length; k++) {
const P = H[k];
if (typeof P != "string" && !Array.isArray(P)) {
for (const N in P) if (N !== "default" && !(N in Y)) {
const Q = Object.getOwnPropertyDescriptor(P, N);
Q && Object.defineProperty(Y, N, Q.get ? Q : { enumerable: !0, get: () => P[N] });
}
}
}
return Object.freeze(Object.defineProperty(Y, Symbol.toStringTag, { value: "Module" }));
}
var ct, pt = { exports: {} };
const yt = _t({ __proto__: null }, [(ct || (ct = 1, pt.exports = function Y() {
var H, k = typeof self < "u" ? self : typeof window < "u" ? window : k !== void 0 ? k : {}, P = !k.document && !!k.postMessage, N = k.IS_PAPA_WORKER || !1, Q = {}, gt = 0, o = {};
function B(t) {
this._handle = null, this._finished = !1, this._completed = !1, this._halted = !1, this._input = null, this._baseIndex = 0, this._partialLine = "", this._rowCount = 0, this._start = 0, this._nextChunk = null, this.isFirstChunk = !0, this._completeResults = { data: [], errors: [], meta: {} }, function(e) {
var i = at(e);
i.chunkSize = parseInt(i.chunkSize), e.step || e.chunk || (i.chunkSize = null), this._handle = new ht(i), (this._handle.streamer = this)._config = i;
}.call(this, t), this.parseChunk = function(e, i) {
var n = parseInt(this._config.skipFirstNLines) || 0;
if (this.isFirstChunk && 0 < n) {
let c = this._config.newline;
c || (r = this._config.quoteChar || '"', c = this._handle.guessLineEndings(e, r)), e = [...e.split(c).slice(n)].join(c);
}
this.isFirstChunk && _(this._config.beforeFirstChunk) && (r = this._config.beforeFirstChunk(e)) !== void 0 && (e = r), this.isFirstChunk = !1, this._halted = !1, n = this._partialLine + e;
var r = (this._partialLine = "", this._handle.parse(n, this._baseIndex, !this._finished));
if (!this._handle.paused() && !this._handle.aborted()) {
if (e = r.meta.cursor, this._finished || (this._partialLine = n.substring(e - this._baseIndex), this._baseIndex = e), r && r.data && (this._rowCount += r.data.length), n = this._finished || this._config.preview && this._rowCount >= this._config.preview, N) k.postMessage({ results: r, workerId: o.WORKER_ID, finished: n });
else if (_(this._config.chunk) && !i) {
if (this._config.chunk(r, this._handle), this._handle.paused() || this._handle.aborted()) return void (this._halted = !0);
this._completeResults = r = void 0;
}
return this._config.step || this._config.chunk || (this._completeResults.data = this._completeResults.data.concat(r.data), this._completeResults.errors = this._completeResults.errors.concat(r.errors), this._completeResults.meta = r.meta), this._completed || !n || !_(this._config.complete) || r && r.meta.aborted || (this._config.complete(this._completeResults, this._input), this._completed = !0), n || r && r.meta.paused || this._nextChunk(), r;
}
this._halted = !0;
}, this._sendError = function(e) {
_(this._config.error) ? this._config.error(e) : N && this._config.error && k.postMessage({ workerId: o.WORKER_ID, error: e, finished: !1 });
};
}
function it(t) {
var e;
(t = t || {}).chunkSize || (t.chunkSize = o.RemoteChunkSize), B.call(this, t), this._nextChunk = P ? function() {
this._readChunk(), this._chunkLoaded();
} : function() {
this._readChunk();
}, this.stream = function(i) {
this._input = i, this._nextChunk();
}, this._readChunk = function() {
if (this._finished) this._chunkLoaded();
else {
if (e = new XMLHttpRequest(), this._config.withCredentials && (e.withCredentials = this._config.withCredentials), P || (e.onload = J(this._chunkLoaded, this), e.onerror = J(this._chunkError, this)), e.open(this._config.downloadRequestBody ? "POST" : "GET", this._input, !P), this._config.downloadRequestHeaders) {
var i, n = this._config.downloadRequestHeaders;
for (i in n) e.setRequestHeader(i, n[i]);
}
var r;
this._config.chunkSize && (r = this._start + this._config.chunkSize - 1, e.setRequestHeader("Range", "bytes=" + this._start + "-" + r));
try {
e.send(this._config.downloadRequestBody);
} catch (c) {
this._chunkError(c.message);
}
P && e.status === 0 && this._chunkError();
}
}, this._chunkLoaded = function() {
e.readyState === 4 && (e.status < 200 || 400 <= e.status ? this._chunkError() : (this._start += this._config.chunkSize || e.responseText.length, this._finished = !this._config.chunkSize || this._start >= ((i) => (i = i.getResponseHeader("Content-Range")) !== null ? parseInt(i.substring(i.lastIndexOf("/") + 1)) : -1)(e), this.parseChunk(e.responseText)));
}, this._chunkError = function(i) {
i = e.statusText || i, this._sendError(new Error(i));
};
}
function rt(t) {
(t = t || {}).chunkSize || (t.chunkSize = o.LocalChunkSize), B.call(this, t);
var e, i, n = typeof FileReader < "u";
this.stream = function(r) {
this._input = r, i = r.slice || r.webkitSlice || r.mozSlice, n ? ((e = new FileReader()).onload = J(this._chunkLoaded, this), e.onerror = J(this._chunkError, this)) : e = new FileReaderSync(), this._nextChunk();
}, this._nextChunk = function() {
this._finished || this._config.preview && !(this._rowCount < this._config.preview) || this._readChunk();
}, this._readChunk = function() {
var r = this._input, c = (this._config.chunkSize && (c = Math.min(this._start + this._config.chunkSize, this._input.size), r = i.call(r, this._start, c)), e.readAsText(r, this._config.encoding));
n || this._chunkLoaded({ target: { result: c } });
}, this._chunkLoaded = function(r) {
this._start += this._config.chunkSize, this._finished = !this._config.chunkSize || this._start >= this._input.size, this.parseChunk(r.target.result);
}, this._chunkError = function() {
this._sendError(e.error);
};
}
function X(t) {
var e;
B.call(this, t = t || {}), this.stream = function(i) {
return e = i, this._nextChunk();
}, this._nextChunk = function() {
var i, n;
if (!this._finished) return i = this._config.chunkSize, e = i ? (n = e.substring(0, i), e.substring(i)) : (n = e, ""), this._finished = !e, this.parseChunk(n);
};
}
function nt(t) {
B.call(this, t = t || {});
var e = [], i = !0, n = !1;
this.pause = function() {
B.prototype.pause.apply(this, arguments), this._input.pause();
}, this.resume = function() {
B.prototype.resume.apply(this, arguments), this._input.resume();
}, this.stream = function(r) {
this._input = r, this._input.on("data", this._streamData), this._input.on("end", this._streamEnd), this._input.on("error", this._streamError);
}, this._checkIsFinished = function() {
n && e.length === 1 && (this._finished = !0);
}, this._nextChunk = function() {
this._checkIsFinished(), e.length ? this.parseChunk(e.shift()) : i = !0;
}, this._streamData = J(function(r) {
try {
e.push(typeof r == "string" ? r : r.toString(this._config.encoding)), i && (i = !1, this._checkIsFinished(), this.parseChunk(e.shift()));
} catch (c) {
this._streamError(c);
}
}, this), this._streamError = J(function(r) {
this._streamCleanUp(), this._sendError(r);
}, this), this._streamEnd = J(function() {
this._streamCleanUp(), n = !0, this._streamData("");
}, this), this._streamCleanUp = J(function() {
this._input.removeListener("data", this._streamData), this._input.removeListener("end", this._streamEnd), this._input.removeListener("error", this._streamError);
}, this);
}
function ht(t) {
var e, i, n, r, c = Math.pow(2, 53), C = -c, j = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/, z = /^((\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)))$/, p = this, w = 0, a = 0, L = !1, u = !1, g = [], s = { data: [], errors: [], meta: {} };
function O(h) {
return t.skipEmptyLines === "greedy" ? h.join("").trim() === "" : h.length === 1 && h[0].length === 0;
}
function R() {
if (s && n && (M("Delimiter", "UndetectableDelimiter", "Unable to auto-detect delimiting character; defaulted to '" + o.DefaultDelimiter + "'"), n = !1), t.skipEmptyLines && (s.data = s.data.filter(function(l) {
return !O(l);
})), T()) {
let l = function(S, A) {
_(t.transformHeader) && (S = t.transformHeader(S, A)), g.push(S);
};
if (s) if (Array.isArray(s.data[0])) {
for (var h = 0; T() && h < s.data.length; h++) s.data[h].forEach(l);
s.data.splice(0, 1);
} else s.data.forEach(l);
}
function d(l, S) {
for (var A = t.header ? {} : [], b = 0; b < l.length; b++) {
var y = b, m = l[b];
m = ((U, f) => ((v) => (t.dynamicTypingFunction && t.dynamicTyping[v] === void 0 && (t.dynamicTyping[v] = t.dynamicTypingFunction(v)), (t.dynamicTyping[v] || t.dynamicTyping) === !0))(U) ? f === "true" || f === "TRUE" || f !== "false" && f !== "FALSE" && (((v) => {
if (j.test(v) && (v = parseFloat(v), C < v && v < c)) return 1;
})(f) ? parseFloat(f) : z.test(f) ? new Date(f) : f === "" ? null : f) : f)(y = t.header ? b >= g.length ? "__parsed_extra" : g[b] : y, m = t.transform ? t.transform(m, y) : m), y === "__parsed_extra" ? (A[y] = A[y] || [], A[y].push(m)) : A[y] = m;
}
return t.header && (b > g.length ? M("FieldMismatch", "TooManyFields", "Too many fields: expected " + g.length + " fields but parsed " + b, a + S) : b < g.length && M("FieldMismatch", "TooFewFields", "Too few fields: expected " + g.length + " fields but parsed " + b, a + S)), A;
}
var E;
s && (t.header || t.dynamicTyping || t.transform) && (E = 1, !s.data.length || Array.isArray(s.data[0]) ? (s.data = s.data.map(d), E = s.data.length) : s.data = d(s.data, 0), t.header && s.meta && (s.meta.fields = g), a += E);
}
function T() {
return t.header && g.length === 0;
}
function M(h, d, E, l) {
h = { type: h, code: d, message: E }, l !== void 0 && (h.row = l), s.errors.push(h);
}
_(t.step) && (r = t.step, t.step = function(h) {
s = h, T() ? R() : (R(), s.data.length !== 0 && (w += h.data.length, t.preview && w > t.preview ? i.abort() : (s.data = s.data[0], r(s, p))));
}), this.parse = function(h, d, E) {
var l = t.quoteChar || '"';
return t.newline || (t.newline = this.guessLineEndings(h, l)), n = !1, t.delimiter ? _(t.delimiter) && (t.delimiter = t.delimiter(h), s.meta.delimiter = t.delimiter) : ((l = ((S, A, b, y, m) => {
var U, f, v, $;
m = m || [",", " ", "|", ";", o.RECORD_SEP, o.UNIT_SEP];
for (var Z = 0; Z < m.length; Z++) {
for (var K, tt = m[Z], F = 0, D = 0, x = 0, I = (v = void 0, new st({ comments: y, delimiter: tt, newline: A, preview: 10 }).parse(S)), W = 0; W < I.data.length; W++) b && O(I.data[W]) ? x++ : (D += K = I.data[W].length, v === void 0 ? v = K : 0 < K && (F += Math.abs(K - v), v = K));
0 < I.data.length && (D /= I.data.length - x), (f === void 0 || F <= f) && ($ === void 0 || $ < D) && 1.99 < D && (f = F, U = tt, $ = D);
}
return { successful: !!(t.delimiter = U), bestDelimiter: U };
})(h, t.newline, t.skipEmptyLines, t.comments, t.delimitersToGuess)).successful ? t.delimiter = l.bestDelimiter : (n = !0, t.delimiter = o.DefaultDelimiter), s.meta.delimiter = t.delimiter), l = at(t), t.preview && t.header && l.preview++, e = h, i = new st(l), s = i.parse(e, d, E), R(), L ? { meta: { paused: !0 } } : s || { meta: { paused: !1 } };
}, this.paused = function() {
return L;
}, this.pause = function() {
L = !0, i.abort(), e = _(t.chunk) ? "" : e.substring(i.getCharIndex());
}, this.resume = function() {
p.streamer._halted ? (L = !1, p.streamer.parseChunk(e, !0)) : setTimeout(p.resume, 3);
}, this.aborted = function() {
return u;
}, this.abort = function() {
u = !0, i.abort(), s.meta.aborted = !0, _(t.complete) && t.complete(s), e = "";
}, this.guessLineEndings = function(h, d) {
h = h.substring(0, 1048576), d = new RegExp(V(d) + "([^]*?)" + V(d), "gm");
var E = (h = h.replace(d, "")).split("\r");
if (h = 1 < (d = h.split(`
`)).length && d[0].length < E[0].length, E.length === 1 || h) return `
`;
for (var l = 0, S = 0; S < E.length; S++) E[S][0] === `
` && l++;
return l >= E.length / 2 ? `\r
` : "\r";
};
}
function V(t) {
return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function st(t) {
var e = (t = t || {}).delimiter, i = t.newline, n = t.comments, r = t.step, c = t.preview, C = t.fastMode, j = null, z = !1, p = t.quoteChar == null ? '"' : t.quoteChar, w = p;
if (t.escapeChar !== void 0 && (w = t.escapeChar), (typeof e != "string" || -1 < o.BAD_DELIMITERS.indexOf(e)) && (e = ","), n === e) throw new Error("Comment character same as delimiter");
n === !0 ? n = "#" : (typeof n != "string" || -1 < o.BAD_DELIMITERS.indexOf(n)) && (n = !1), i !== `
` && i !== "\r" && i !== `\r
` && (i = `
`);
var a = 0, L = !1;
this.parse = function(u, g, s) {
if (typeof u != "string") throw new Error("Input must be a string");
var O = u.length, R = e.length, T = i.length, M = n.length, h = _(r), d = [], E = [], l = [], S = a = 0;
if (!u) return F();
if (C || C !== !1 && u.indexOf(p) === -1) {
for (var A = u.split(i), b = 0; b < A.length; b++) {
if (l = A[b], a += l.length, b !== A.length - 1) a += i.length;
else if (s) return F();
if (!n || l.substring(0, M) !== n) {
if (h) {
if (d = [], $(l.split(e)), D(), L) return F();
} else $(l.split(e));
if (c && c <= b) return d = d.slice(0, c), F(!0);
}
}
return F();
}
for (var y = u.indexOf(e, a), m = u.indexOf(i, a), U = new RegExp(V(w) + V(p), "g"), f = u.indexOf(p, a); ; ) if (u[a] === p) for (f = a, a++; ; ) {
if ((f = u.indexOf(p, f + 1)) === -1) return s || E.push({ type: "Quotes", code: "MissingQuotes", message: "Quoted field unterminated", row: d.length, index: a }), K();
if (f === O - 1) return K(u.substring(a, f).replace(U, p));
if (p === w && u[f + 1] === w) f++;
else if (p === w || f === 0 || u[f - 1] !== w) {
y !== -1 && y < f + 1 && (y = u.indexOf(e, f + 1));
var v = Z((m = m !== -1 && m < f + 1 ? u.indexOf(i, f + 1) : m) === -1 ? y : Math.min(y, m));
if (u.substr(f + 1 + v, R) === e) {
l.push(u.substring(a, f).replace(U, p)), u[a = f + 1 + v + R] !== p && (f = u.indexOf(p, a)), y = u.indexOf(e, a), m = u.indexOf(i, a);
break;
}
if (v = Z(m), u.substring(f + 1 + v, f + 1 + v + T) === i) {
if (l.push(u.substring(a, f).replace(U, p)), tt(f + 1 + v + T), y = u.indexOf(e, a), f = u.indexOf(p, a), h && (D(), L)) return F();
if (c && d.length >= c) return F(!0);
break;
}
E.push({ type: "Quotes", code: "InvalidQuotes", message: "Trailing quote on quoted field is malformed", row: d.length, index: a }), f++;
}
}
else if (n && l.length === 0 && u.substring(a, a + M) === n) {
if (m === -1) return F();
a = m + T, m = u.indexOf(i, a), y = u.indexOf(e, a);
} else if (y !== -1 && (y < m || m === -1)) l.push(u.substring(a, y)), a = y + R, y = u.indexOf(e, a);
else {
if (m === -1) break;
if (l.push(u.substring(a, m)), tt(m + T), h && (D(), L)) return F();
if (c && d.length >= c) return F(!0);
}
return K();
function $(x) {
d.push(x), S = a;
}
function Z(x) {
var I = 0;
return x !== -1 && (x = u.substring(f + 1, x)) && x.trim() === "" ? x.length : I;
}
function K(x) {
return s || (x === void 0 && (x = u.substring(a)), l.push(x), a = O, $(l), h && D()), F();
}
function tt(x) {
a = x, $(l), l = [], m = u.indexOf(i, a);
}
function F(x) {
if (t.header && !g && d.length && !z) {
var I = d[0], W = /* @__PURE__ */ Object.create(null), ot = new Set(I);
let lt = !1;
for (let G = 0; G < I.length; G++) {
let q = I[G];
if (W[q = _(t.transformHeader) ? t.transformHeader(q, G) : q]) {
let et, dt = W[q];
for (; et = q + "_" + dt, dt++, ot.has(et); ) ;
ot.add(et), I[G] = et, W[q]++, lt = !0, (j = j === null ? {} : j)[et] = q;
} else W[q] = 1, I[G] = q;
ot.add(q);
}
lt && console.warn("Duplicate headers found and renamed."), z = !0;
}
return { data: d, errors: E, meta: { delimiter: e, linebreak: i, aborted: L, truncated: !!x, cursor: S + (g || 0), renamedHeaders: j } };
}
function D() {
r(F()), d = [], E = [];
}
}, this.abort = function() {
L = !0;
}, this.getCharIndex = function() {
return a;
};
}
function mt(t) {
var e = t.data, i = Q[e.workerId], n = !1;
if (e.error) i.userError(e.error, e.file);
else if (e.results && e.results.data) {
var r = { abort: function() {
n = !0, ut(e.workerId, { data: [], errors: [], meta: { aborted: !0 } });
}, pause: ft, resume: ft };
if (_(i.userStep)) {
for (var c = 0; c < e.results.data.length && (i.userStep({ data: e.results.data[c], errors: e.results.errors, meta: e.results.meta }, r), !n); c++) ;
delete e.results;
} else _(i.userChunk) && (i.userChunk(e.results, r, e.file), delete e.results);
}
e.finished && !n && ut(e.workerId, e.results);
}
function ut(t, e) {
var i = Q[t];
_(i.userComplete) && i.userComplete(e), i.terminate(), delete Q[t];
}
function ft() {
throw new Error("Not implemented.");
}
function at(t) {
if (typeof t != "object" || t === null) return t;
var e, i = Array.isArray(t) ? [] : {};
for (e in t) i[e] = at(t[e]);
return i;
}
function J(t, e) {
return function() {
t.apply(e, arguments);
};
}
function _(t) {
return typeof t == "function";
}
return o.parse = function(t, e) {
var i = (e = e || {}).dynamicTyping || !1;
if (_(i) && (e.dynamicTypingFunction = i, i = {}), e.dynamicTyping = i, e.transform = !!_(e.transform) && e.transform, !e.worker || !o.WORKERS_SUPPORTED) return i = null, o.NODE_STREAM_INPUT, typeof t == "string" ? (t = ((n) => n.charCodeAt(0) !== 65279 ? n : n.slice(1))(t), i = new (e.download ? it : X)(e)) : t.readable === !0 && _(t.read) && _(t.on) ? i = new nt(e) : (k.File && t instanceof File || t instanceof Object) && (i = new rt(e)), i.stream(t);
(i = (() => {
var n;
return !!o.WORKERS_SUPPORTED && (n = (() => {
var r = k.URL || k.webkitURL || null, c = Y.toString();
return o.BLOB_URL || (o.BLOB_URL = r.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; ", "(", c, ")();"], { type: "text/javascript" })));
})(), (n = new k.Worker(n)).onmessage = mt, n.id = gt++, Q[n.id] = n);
})()).userStep = e.step, i.userChunk = e.chunk, i.userComplete = e.complete, i.userError = e.error, e.step = _(e.step), e.chunk = _(e.chunk), e.complete = _(e.complete), e.error = _(e.error), delete e.worker, i.postMessage({ input: t, config: e, workerId: i.id });
}, o.unparse = function(t, e) {
var i = !1, n = !0, r = ",", c = `\r
`, C = '"', j = C + C, z = !1, p = null, w = !1, a = ((() => {
if (typeof e == "object") {
if (typeof e.delimiter != "string" || o.BAD_DELIMITERS.filter(function(g) {
return e.delimiter.indexOf(g) !== -1;
}).length || (r = e.delimiter), typeof e.quotes != "boolean" && typeof e.quotes != "function" && !Array.isArray(e.quotes) || (i = e.quotes), typeof e.skipEmptyLines != "boolean" && typeof e.skipEmptyLines != "string" || (z = e.skipEmptyLines), typeof e.newline == "string" && (c = e.newline), typeof e.quoteChar == "string" && (C = e.quoteChar), typeof e.header == "boolean" && (n = e.header), Array.isArray(e.columns)) {
if (e.columns.length === 0) throw new Error("Option columns is empty");
p = e.columns;
}
e.escapeChar !== void 0 && (j = e.escapeChar + C), e.escapeFormulae instanceof RegExp ? w = e.escapeFormulae : typeof e.escapeFormulae == "boolean" && e.escapeFormulae && (w = /^[=+\-@\t\r].*$/);
}
})(), new RegExp(V(C), "g"));
if (typeof t == "string" && (t = JSON.parse(t)), Array.isArray(t)) {
if (!t.length || Array.isArray(t[0])) return L(null, t, z);
if (typeof t[0] == "object") return L(p || Object.keys(t[0]), t, z);
} else if (typeof t == "object") return typeof t.data == "string" && (t.data = JSON.parse(t.data)), Array.isArray(t.data) && (t.fields || (t.fields = t.meta && t.meta.fields || p), t.fields || (t.fields = Array.isArray(t.data[0]) ? t.fields : typeof t.data[0] == "object" ? Object.keys(t.data[0]) : []), Array.isArray(t.data[0]) || typeof t.data[0] == "object" || (t.data = [t.data])), L(t.fields || [], t.data || [], z);
throw new Error("Unable to serialize unrecognized input");
function L(g, s, O) {
var R = "", T = (typeof g == "string" && (g = JSON.parse(g)), typeof s == "string" && (s = JSON.parse(s)), Array.isArray(g) && 0 < g.length), M = !Array.isArray(s[0]);
if (T && n) {
for (var h = 0; h < g.length; h++) 0 < h && (R += r), R += u(g[h], h);
0 < s.length && (R += c);
}
for (var d = 0; d < s.length; d++) {
var E = (T ? g : s[d]).length, l = !1, S = T ? Object.keys(s[d]).length === 0 : s[d].length === 0;
if (O && !T && (l = O === "greedy" ? s[d].join("").trim() === "" : s[d].length === 1 && s[d][0].length === 0), O === "greedy" && T) {
for (var A = [], b = 0; b < E; b++) {
var y = M ? g[b] : b;
A.push(s[d][y]);
}
l = A.join("").trim() === "";
}
if (!l) {
for (var m = 0; m < E; m++) {
0 < m && !S && (R += r);
var U = T && M ? g[m] : m;
R += u(s[d][U], m);
}
d < s.length - 1 && (!O || 0 < E && !S) && (R += c);
}
}
return R;
}
function u(g, s) {
var O, R;
return g == null ? "" : g.constructor === Date ? JSON.stringify(g).slice(1, 25) : (R = !1, w && typeof g == "string" && w.test(g) && (g = "'" + g, R = !0), O = g.toString().replace(a, j), (R = R || i === !0 || typeof i == "function" && i(g, s) || Array.isArray(i) && i[s] || ((T, M) => {
for (var h = 0; h < M.length; h++) if (-1 < T.indexOf(M[h])) return !0;
return !1;
})(O, o.BAD_DELIMITERS) || -1 < O.indexOf(r) || O.charAt(0) === " " || O.charAt(O.length - 1) === " ") ? C + O + C : O);
}
}, o.RECORD_SEP = "", o.UNIT_SEP = "", o.BYTE_ORDER_MARK = "\uFEFF", o.BAD_DELIMITERS = ["\r", `
`, '"', o.BYTE_ORDER_MARK], o.WORKERS_SUPPORTED = !P && !!k.Worker, o.NODE_STREAM_INPUT = 1, o.LocalChunkSize = 10485760, o.RemoteChunkSize = 5242880, o.DefaultDelimiter = ",", o.Parser = st, o.ParserHandle = ht, o.NetworkStreamer = it, o.FileStreamer = rt, o.StringStreamer = X, o.ReadableStreamStreamer = nt, k.jQuery && ((H = k.jQuery).fn.parse = function(t) {
var e = t.config || {}, i = [];
return this.each(function(c) {
if (H(this).prop("tagName").toUpperCase() !== "INPUT" || H(this).attr("type").toLowerCase() !== "file" || !k.FileReader || !this.files || this.files.length === 0) return !0;
for (var C = 0; C < this.files.length; C++) i.push({ file: this.files[C], inputElem: this, instanceConfig: H.extend({}, e) });
}), n(), this;
function n() {
if (i.length === 0) _(t.complete) && t.complete();
else {
var c, C, j, z, p = i[0];
if (_(t.before)) {
var w = t.before(p.file, p.inputElem);
if (typeof w == "object") {
if (w.action === "abort") return c = "AbortError", C = p.file, j = p.inputElem, z = w.reason, void (_(t.error) && t.error({ name: c }, C, j, z));
if (w.action === "skip") return void r();
typeof w.config == "object" && (p.instanceConfig = H.extend(p.instanceConfig, w.config));
} else if (w === "skip") return void r();
}
var a = p.instanceConfig.complete;
p.instanceConfig.complete = function(L) {
_(a) && a(L, p.file, p.inputElem), r();
}, o.parse(p.file, p.instanceConfig);
}
}
function r() {
i.splice(0, 1), n();
}
}), N && (k.onmessage = function(t) {
t = t.data, o.WORKER_ID === void 0 && t && (o.WORKER_ID = t.workerId), typeof t.input == "string" ? k.postMessage({ workerId: o.WORKER_ID, results: o.parse(t.input, t.config), finished: !0 }) : (k.File && t.input instanceof File || t.input instanceof Object) && (t = o.parse(t.input, t.config)) && k.postMessage({ workerId: o.WORKER_ID, results: t, finished: !0 });
}), (it.prototype = Object.create(B.prototype)).constructor = it, (rt.prototype = Object.create(B.prototype)).constructor = rt, (X.prototype = Object.create(X.prototype)).constructor = X, (nt.prototype = Object.create(B.prototype)).constructor = nt, o;
}()), pt.exports)]);
export {
yt as p
};