Socket
Socket
Sign inDemoInstall

@emqx/shared-ui-utils

Package Overview
Dependencies
27
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.11 to 0.0.12

dist/useBatchSettings.d.ts

7

dist/download.d.ts
/**
* Initiates a download of a file from a given URL with the specified filename.
*
* @param url - The URL of the file to be downloaded.
* @param filename - The name of the file to be downloaded.
*/
export declare const downloadFile: (url: string, filename: string) => void;
/**
* Creates a download link for a given Blob data with the specified filename.

@@ -3,0 +10,0 @@ * The link is automatically clicked to initiate the download, and then removed from the document body.

@@ -8,1 +8,29 @@ /**

export declare const formatSizeUnit: (val: number) => string;
/**
* Converts a given value from one unit to its equivalent in the smallest unit of the same type.
*
* For example, it converts a value in kilobytes (KB) to bytes (B), or a value in hours (h) to milliseconds (ms).
* The smallest unit for time is millisecond (ms), and for size is byte (B).
*
* @param {number} value - The numeric value to be converted.
* @param {string} unit - The unit of the value, which is a key of the SizeOrTimeUnit enum.
* @returns {number} The input value converted to the smallest unit.
* @throws {Error} If the provided unit is not a key in the SizeOrTimeUnit enum.
*
* @example
* // returns 1024, converts 1 kilobyte to bytes
* formatValueToMinUnit(1, 'KB');
*/
declare enum SizeOrTimeUnit {
ms = 1,
s = 1000,
m = 60000,
h = 3600000,
d = 86400000,
B = 1,
KB = 1024,
MB = 1048576,
GB = 1073741824
}
export declare const formatValueToMinUnit: (value: number, unit: keyof typeof SizeOrTimeUnit) => number;
export {};

1

dist/index.d.ts

@@ -5,1 +5,2 @@ export * from './objectUtils';

export * from './download';
export * from './useBatchSettings';

@@ -1,64 +0,626 @@

const i = (e, r = [], n = {}) => {
if (typeof e == "object" && !Array.isArray(e) && e !== null)
for (const t of Object.keys(e))
i(e[t], r.concat(t), n);
const ke = (i, E = [], m = {}) => {
if (typeof i == "object" && !Array.isArray(i) && i !== null)
for (const c of Object.keys(i))
ke(i[c], E.concat(c), m);
else
n[r.join(".")] = e;
return n;
}, l = (e) => {
if (Object(e) !== e && !Array.isArray(e))
return e;
const r = /\.?([^.[\]]+)|\[(\d+)\]/g, n = {};
m[E.join(".")] = i;
return m;
}, Ce = (i) => {
if (Object(i) !== i && !Array.isArray(i))
return i;
const E = /\.?([^.[\]]+)|\[(\d+)\]/g, m = {};
try {
for (const t in e) {
let o = n, c = "", s;
for (; s = r.exec(t); )
o = o[c] || (o[c] = s[2] ? [] : {}), c = s[2] || s[1];
o[c] = e[t];
for (const c in i) {
let z = m, G = "", J;
for (; J = E.exec(c); )
z = z[G] || (z[G] = J[2] ? [] : {}), G = J[2] || J[1];
z[G] = i[c];
}
} catch (t) {
console.error(t);
} catch (c) {
console.error(c);
}
return n[""] || n;
}, a = (e) => Object.keys(e).length === 0, y = (e) => {
return m[""] || m;
}, Re = (i) => Object.keys(i).length === 0, xe = (i) => {
try {
return JSON.parse(e);
return JSON.parse(i);
} catch {
console.error("An error occurred while parsing the JSON string");
}
}, u = (e, r) => {
}, Oe = (i, E) => {
try {
return typeof e == "string" ? e : JSON.stringify(e, null, r);
} catch (n) {
return console.error(n), "stringify error";
return typeof i == "string" ? i : JSON.stringify(i, null, E);
} catch (m) {
return console.error(m), "stringify error";
}
}, f = (e) => {
if (typeof e != "string")
}, Ae = (i) => {
if (typeof i != "string")
return !1;
try {
const r = JSON.parse(e);
return typeof r == "object" && r !== null;
const E = JSON.parse(i);
return typeof E == "object" && E !== null;
} catch {
return !1;
}
}, d = (e) => {
if (typeof e != "number" || isNaN(e) || e < 0)
}, Ie = (i) => {
if (typeof i != "number" || isNaN(i) || i < 0)
throw new Error("Invalid input: input should be a non-negative number");
if (e === 0)
if (i === 0)
return "0 Bytes";
const r = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], n = Math.floor(Math.log(e) / Math.log(1024));
return `${(e / 1024 ** n).toFixed(1)} ${r[n]}`;
}, p = (e, r) => {
const n = window.URL.createObjectURL(new Blob([e])), t = document.createElement("a");
t.style.display = "none", t.href = n, t.download = r, document.body.appendChild(t), t.click(), document.body.removeChild(t);
const E = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], m = Math.floor(Math.log(i) / Math.log(1024));
return `${(i / 1024 ** m).toFixed(1)} ${E[m]}`;
};
var ce = /* @__PURE__ */ ((i) => (i[i.ms = 1] = "ms", i[i.s = 1e3] = "s", i[i.m = 6e4] = "m", i[i.h = 36e5] = "h", i[i.d = 864e5] = "d", i[i.B = 1] = "B", i[i.KB = 1024] = "KB", i[i.MB = 1048576] = "MB", i[i.GB = 1073741824] = "GB", i))(ce || {});
const De = (i, E) => {
if (!(E in ce))
throw new Error(`Invalid unit: ${E}`);
return i * ce[E];
}, be = (i, E) => {
const m = document.createElement("a");
m.style.display = "none", m.href = i, m.download = E, document.body.appendChild(m), m.click(), document.body.removeChild(m);
}, Le = (i, E) => {
const m = window.URL.createObjectURL(new Blob([i]));
be(m, E), window.URL.revokeObjectURL(m);
};
var we = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, Ee = { exports: {} };
/* @license
Papa Parse
v5.4.1
https://github.com/mholt/PapaParse
License: MIT
*/
(function(i, E) {
(function(m, c) {
i.exports = c();
})(we, function m() {
var c = typeof self < "u" ? self : typeof window < "u" ? window : c !== void 0 ? c : {}, z = !c.document && !!c.postMessage, G = c.IS_PAPA_WORKER || !1, J = {}, me = 0, l = { parse: function(t, e) {
var r = (e = e || {}).dynamicTyping || !1;
if (_(r) && (e.dynamicTypingFunction = r, r = {}), e.dynamicTyping = r, e.transform = !!_(e.transform) && e.transform, e.worker && l.WORKERS_SUPPORTED) {
var n = function() {
if (!l.WORKERS_SUPPORTED)
return !1;
var f = (B = c.URL || c.webkitURL || null, C = m.toString(), l.BLOB_URL || (l.BLOB_URL = B.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" })))), d = new c.Worker(f), B, C;
return d.onmessage = ve, d.id = me++, J[d.id] = d;
}();
return n.userStep = e.step, n.userChunk = e.chunk, n.userComplete = e.complete, n.userError = e.error, e.step = _(e.step), e.chunk = _(e.chunk), e.complete = _(e.complete), e.error = _(e.error), delete e.worker, void n.postMessage({ input: t, config: e, workerId: n.id });
}
var a = null;
return l.NODE_STREAM_INPUT, typeof t == "string" ? (t = function(f) {
return f.charCodeAt(0) === 65279 ? f.slice(1) : f;
}(t), a = e.download ? new ae(e) : new ie(e)) : t.readable === !0 && _(t.read) && _(t.on) ? a = new ue(e) : (c.File && t instanceof File || t instanceof Object) && (a = new oe(e)), a.stream(t);
}, unparse: function(t, e) {
var r = !1, n = !0, a = ",", f = `\r
`, d = '"', B = d + d, C = !1, o = null, x = !1;
(function() {
if (typeof e == "object") {
if (typeof e.delimiter != "string" || l.BAD_DELIMITERS.filter(function(s) {
return e.delimiter.indexOf(s) !== -1;
}).length || (a = e.delimiter), (typeof e.quotes == "boolean" || typeof e.quotes == "function" || Array.isArray(e.quotes)) && (r = e.quotes), typeof e.skipEmptyLines != "boolean" && typeof e.skipEmptyLines != "string" || (C = e.skipEmptyLines), typeof e.newline == "string" && (f = e.newline), typeof e.quoteChar == "string" && (d = 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");
o = e.columns;
}
e.escapeChar !== void 0 && (B = e.escapeChar + d), (typeof e.escapeFormulae == "boolean" || e.escapeFormulae instanceof RegExp) && (x = e.escapeFormulae instanceof RegExp ? e.escapeFormulae : /^[=+\-@\t\r].*$/);
}
})();
var h = new RegExp(se(d), "g");
if (typeof t == "string" && (t = JSON.parse(t)), Array.isArray(t)) {
if (!t.length || Array.isArray(t[0]))
return j(null, t, C);
if (typeof t[0] == "object")
return j(o || Object.keys(t[0]), t, C);
} 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 || o), 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])), j(t.fields || [], t.data || [], C);
throw new Error("Unable to serialize unrecognized input");
function j(s, k, M) {
var R = "";
typeof s == "string" && (s = JSON.parse(s)), typeof k == "string" && (k = JSON.parse(k));
var F = Array.isArray(s) && 0 < s.length, D = !Array.isArray(k[0]);
if (F && n) {
for (var L = 0; L < s.length; L++)
0 < L && (R += a), R += S(s[L], L);
0 < k.length && (R += f);
}
for (var u = 0; u < k.length; u++) {
var p = F ? s.length : k[u].length, b = !1, I = F ? Object.keys(k[u]).length === 0 : k[u].length === 0;
if (M && !F && (b = M === "greedy" ? k[u].join("").trim() === "" : k[u].length === 1 && k[u][0].length === 0), M === "greedy" && F) {
for (var y = [], T = 0; T < p; T++) {
var O = D ? s[T] : T;
y.push(k[u][O]);
}
b = y.join("").trim() === "";
}
if (!b) {
for (var v = 0; v < p; v++) {
0 < v && !I && (R += a);
var W = F && D ? s[v] : v;
R += S(k[u][W], v);
}
u < k.length - 1 && (!M || 0 < p && !I) && (R += f);
}
}
return R;
}
function S(s, k) {
if (s == null)
return "";
if (s.constructor === Date)
return JSON.stringify(s).slice(1, 25);
var M = !1;
x && typeof s == "string" && x.test(s) && (s = "'" + s, M = !0);
var R = s.toString().replace(h, B);
return (M = M || r === !0 || typeof r == "function" && r(s, k) || Array.isArray(r) && r[k] || function(F, D) {
for (var L = 0; L < D.length; L++)
if (-1 < F.indexOf(D[L]))
return !0;
return !1;
}(R, l.BAD_DELIMITERS) || -1 < R.indexOf(a) || R.charAt(0) === " " || R.charAt(R.length - 1) === " ") ? d + R + d : R;
}
} };
if (l.RECORD_SEP = String.fromCharCode(30), l.UNIT_SEP = String.fromCharCode(31), l.BYTE_ORDER_MARK = "\uFEFF", l.BAD_DELIMITERS = ["\r", `
`, '"', l.BYTE_ORDER_MARK], l.WORKERS_SUPPORTED = !z && !!c.Worker, l.NODE_STREAM_INPUT = 1, l.LocalChunkSize = 10485760, l.RemoteChunkSize = 5242880, l.DefaultDelimiter = ",", l.Parser = fe, l.ParserHandle = pe, l.NetworkStreamer = ae, l.FileStreamer = oe, l.StringStreamer = ie, l.ReadableStreamStreamer = ue, c.jQuery) {
var ne = c.jQuery;
ne.fn.parse = function(t) {
var e = t.config || {}, r = [];
return this.each(function(f) {
if (!(ne(this).prop("tagName").toUpperCase() === "INPUT" && ne(this).attr("type").toLowerCase() === "file" && c.FileReader) || !this.files || this.files.length === 0)
return !0;
for (var d = 0; d < this.files.length; d++)
r.push({ file: this.files[d], inputElem: this, instanceConfig: ne.extend({}, e) });
}), n(), this;
function n() {
if (r.length !== 0) {
var f, d, B, C, o = r[0];
if (_(t.before)) {
var x = t.before(o.file, o.inputElem);
if (typeof x == "object") {
if (x.action === "abort")
return f = "AbortError", d = o.file, B = o.inputElem, C = x.reason, void (_(t.error) && t.error({ name: f }, d, B, C));
if (x.action === "skip")
return void a();
typeof x.config == "object" && (o.instanceConfig = ne.extend(o.instanceConfig, x.config));
} else if (x === "skip")
return void a();
}
var h = o.instanceConfig.complete;
o.instanceConfig.complete = function(j) {
_(h) && h(j, o.file, o.inputElem), a();
}, l.parse(o.file, o.instanceConfig);
} else
_(t.complete) && t.complete();
}
function a() {
r.splice(0, 1), n();
}
};
}
function U(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 r = le(e);
r.chunkSize = parseInt(r.chunkSize), e.step || e.chunk || (r.chunkSize = null), this._handle = new pe(r), (this._handle.streamer = this)._config = r;
}).call(this, t), this.parseChunk = function(e, r) {
if (this.isFirstChunk && _(this._config.beforeFirstChunk)) {
var n = this._config.beforeFirstChunk(e);
n !== void 0 && (e = n);
}
this.isFirstChunk = !1, this._halted = !1;
var a = this._partialLine + e;
this._partialLine = "";
var f = this._handle.parse(a, this._baseIndex, !this._finished);
if (!this._handle.paused() && !this._handle.aborted()) {
var d = f.meta.cursor;
this._finished || (this._partialLine = a.substring(d - this._baseIndex), this._baseIndex = d), f && f.data && (this._rowCount += f.data.length);
var B = this._finished || this._config.preview && this._rowCount >= this._config.preview;
if (G)
c.postMessage({ results: f, workerId: l.WORKER_ID, finished: B });
else if (_(this._config.chunk) && !r) {
if (this._config.chunk(f, this._handle), this._handle.paused() || this._handle.aborted())
return void (this._halted = !0);
f = void 0, this._completeResults = void 0;
}
return this._config.step || this._config.chunk || (this._completeResults.data = this._completeResults.data.concat(f.data), this._completeResults.errors = this._completeResults.errors.concat(f.errors), this._completeResults.meta = f.meta), this._completed || !B || !_(this._config.complete) || f && f.meta.aborted || (this._config.complete(this._completeResults, this._input), this._completed = !0), B || f && f.meta.paused || this._nextChunk(), f;
}
this._halted = !0;
}, this._sendError = function(e) {
_(this._config.error) ? this._config.error(e) : G && this._config.error && c.postMessage({ workerId: l.WORKER_ID, error: e, finished: !1 });
};
}
function ae(t) {
var e;
(t = t || {}).chunkSize || (t.chunkSize = l.RemoteChunkSize), U.call(this, t), this._nextChunk = z ? function() {
this._readChunk(), this._chunkLoaded();
} : function() {
this._readChunk();
}, this.stream = function(r) {
this._input = r, this._nextChunk();
}, this._readChunk = function() {
if (this._finished)
this._chunkLoaded();
else {
if (e = new XMLHttpRequest(), this._config.withCredentials && (e.withCredentials = this._config.withCredentials), z || (e.onload = Z(this._chunkLoaded, this), e.onerror = Z(this._chunkError, this)), e.open(this._config.downloadRequestBody ? "POST" : "GET", this._input, !z), this._config.downloadRequestHeaders) {
var r = this._config.downloadRequestHeaders;
for (var n in r)
e.setRequestHeader(n, r[n]);
}
if (this._config.chunkSize) {
var a = this._start + this._config.chunkSize - 1;
e.setRequestHeader("Range", "bytes=" + this._start + "-" + a);
}
try {
e.send(this._config.downloadRequestBody);
} catch (f) {
this._chunkError(f.message);
}
z && e.status === 0 && this._chunkError();
}
}, this._chunkLoaded = function() {
e.readyState === 4 && (e.status < 200 || 400 <= e.status ? this._chunkError() : (this._start += this._config.chunkSize ? this._config.chunkSize : e.responseText.length, this._finished = !this._config.chunkSize || this._start >= function(r) {
var n = r.getResponseHeader("Content-Range");
return n === null ? -1 : parseInt(n.substring(n.lastIndexOf("/") + 1));
}(e), this.parseChunk(e.responseText)));
}, this._chunkError = function(r) {
var n = e.statusText || r;
this._sendError(new Error(n));
};
}
function oe(t) {
var e, r;
(t = t || {}).chunkSize || (t.chunkSize = l.LocalChunkSize), U.call(this, t);
var n = typeof FileReader < "u";
this.stream = function(a) {
this._input = a, r = a.slice || a.webkitSlice || a.mozSlice, n ? ((e = new FileReader()).onload = Z(this._chunkLoaded, this), e.onerror = Z(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 a = this._input;
if (this._config.chunkSize) {
var f = Math.min(this._start + this._config.chunkSize, this._input.size);
a = r.call(a, this._start, f);
}
var d = e.readAsText(a, this._config.encoding);
n || this._chunkLoaded({ target: { result: d } });
}, this._chunkLoaded = function(a) {
this._start += this._config.chunkSize, this._finished = !this._config.chunkSize || this._start >= this._input.size, this.parseChunk(a.target.result);
}, this._chunkError = function() {
this._sendError(e.error);
};
}
function ie(t) {
var e;
U.call(this, t = t || {}), this.stream = function(r) {
return e = r, this._nextChunk();
}, this._nextChunk = function() {
if (!this._finished) {
var r, n = this._config.chunkSize;
return n ? (r = e.substring(0, n), e = e.substring(n)) : (r = e, e = ""), this._finished = !e, this.parseChunk(r);
}
};
}
function ue(t) {
U.call(this, t = t || {});
var e = [], r = !0, n = !1;
this.pause = function() {
U.prototype.pause.apply(this, arguments), this._input.pause();
}, this.resume = function() {
U.prototype.resume.apply(this, arguments), this._input.resume();
}, this.stream = function(a) {
this._input = a, 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()) : r = !0;
}, this._streamData = Z(function(a) {
try {
e.push(typeof a == "string" ? a : a.toString(this._config.encoding)), r && (r = !1, this._checkIsFinished(), this.parseChunk(e.shift()));
} catch (f) {
this._streamError(f);
}
}, this), this._streamError = Z(function(a) {
this._streamCleanUp(), this._sendError(a);
}, this), this._streamEnd = Z(function() {
this._streamCleanUp(), n = !0, this._streamData("");
}, this), this._streamCleanUp = Z(function() {
this._input.removeListener("data", this._streamData), this._input.removeListener("end", this._streamEnd), this._input.removeListener("error", this._streamError);
}, this);
}
function pe(t) {
var e, r, n, a = Math.pow(2, 53), f = -a, d = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/, B = /^((\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)))$/, C = this, o = 0, x = 0, h = !1, j = !1, S = [], s = { data: [], errors: [], meta: {} };
if (_(t.step)) {
var k = t.step;
t.step = function(u) {
if (s = u, F())
R();
else {
if (R(), s.data.length === 0)
return;
o += u.data.length, t.preview && o > t.preview ? r.abort() : (s.data = s.data[0], k(s, C));
}
};
}
function M(u) {
return t.skipEmptyLines === "greedy" ? u.join("").trim() === "" : u.length === 1 && u[0].length === 0;
}
function R() {
return s && n && (L("Delimiter", "UndetectableDelimiter", "Unable to auto-detect delimiting character; defaulted to '" + l.DefaultDelimiter + "'"), n = !1), t.skipEmptyLines && (s.data = s.data.filter(function(u) {
return !M(u);
})), F() && function() {
if (!s)
return;
function u(b, I) {
_(t.transformHeader) && (b = t.transformHeader(b, I)), S.push(b);
}
if (Array.isArray(s.data[0])) {
for (var p = 0; F() && p < s.data.length; p++)
s.data[p].forEach(u);
s.data.splice(0, 1);
} else
s.data.forEach(u);
}(), function() {
if (!s || !t.header && !t.dynamicTyping && !t.transform)
return s;
function u(b, I) {
var y, T = t.header ? {} : [];
for (y = 0; y < b.length; y++) {
var O = y, v = b[y];
t.header && (O = y >= S.length ? "__parsed_extra" : S[y]), t.transform && (v = t.transform(v, O)), v = D(O, v), O === "__parsed_extra" ? (T[O] = T[O] || [], T[O].push(v)) : T[O] = v;
}
return t.header && (y > S.length ? L("FieldMismatch", "TooManyFields", "Too many fields: expected " + S.length + " fields but parsed " + y, x + I) : y < S.length && L("FieldMismatch", "TooFewFields", "Too few fields: expected " + S.length + " fields but parsed " + y, x + I)), T;
}
var p = 1;
return !s.data.length || Array.isArray(s.data[0]) ? (s.data = s.data.map(u), p = s.data.length) : s.data = u(s.data, 0), t.header && s.meta && (s.meta.fields = S), x += p, s;
}();
}
function F() {
return t.header && S.length === 0;
}
function D(u, p) {
return b = u, t.dynamicTypingFunction && t.dynamicTyping[b] === void 0 && (t.dynamicTyping[b] = t.dynamicTypingFunction(b)), (t.dynamicTyping[b] || t.dynamicTyping) === !0 ? p === "true" || p === "TRUE" || p !== "false" && p !== "FALSE" && (function(I) {
if (d.test(I)) {
var y = parseFloat(I);
if (f < y && y < a)
return !0;
}
return !1;
}(p) ? parseFloat(p) : B.test(p) ? new Date(p) : p === "" ? null : p) : p;
var b;
}
function L(u, p, b, I) {
var y = { type: u, code: p, message: b };
I !== void 0 && (y.row = I), s.errors.push(y);
}
this.parse = function(u, p, b) {
var I = t.quoteChar || '"';
if (t.newline || (t.newline = function(O, v) {
O = O.substring(0, 1048576);
var W = new RegExp(se(v) + "([^]*?)" + se(v), "gm"), N = (O = O.replace(W, "")).split("\r"), H = O.split(`
`), Q = 1 < H.length && H[0].length < N[0].length;
if (N.length === 1 || Q)
return `
`;
for (var P = 0, w = 0; w < N.length; w++)
N[w][0] === `
` && P++;
return P >= N.length / 2 ? `\r
` : "\r";
}(u, I)), n = !1, t.delimiter)
_(t.delimiter) && (t.delimiter = t.delimiter(u), s.meta.delimiter = t.delimiter);
else {
var y = function(O, v, W, N, H) {
var Q, P, w, A;
H = H || [",", " ", "|", ";", l.RECORD_SEP, l.UNIT_SEP];
for (var ee = 0; ee < H.length; ee++) {
var g = H[ee], re = 0, $ = 0, te = 0;
w = void 0;
for (var Y = new fe({ comments: N, delimiter: g, newline: v, preview: 10 }).parse(O), V = 0; V < Y.data.length; V++)
if (W && M(Y.data[V]))
te++;
else {
var X = Y.data[V].length;
$ += X, w !== void 0 ? 0 < X && (re += Math.abs(X - w), w = X) : w = X;
}
0 < Y.data.length && ($ /= Y.data.length - te), (P === void 0 || re <= P) && (A === void 0 || A < $) && 1.99 < $ && (P = re, Q = g, A = $);
}
return { successful: !!(t.delimiter = Q), bestDelimiter: Q };
}(u, t.newline, t.skipEmptyLines, t.comments, t.delimitersToGuess);
y.successful ? t.delimiter = y.bestDelimiter : (n = !0, t.delimiter = l.DefaultDelimiter), s.meta.delimiter = t.delimiter;
}
var T = le(t);
return t.preview && t.header && T.preview++, e = u, r = new fe(T), s = r.parse(e, p, b), R(), h ? { meta: { paused: !0 } } : s || { meta: { paused: !1 } };
}, this.paused = function() {
return h;
}, this.pause = function() {
h = !0, r.abort(), e = _(t.chunk) ? "" : e.substring(r.getCharIndex());
}, this.resume = function() {
C.streamer._halted ? (h = !1, C.streamer.parseChunk(e, !0)) : setTimeout(C.resume, 3);
}, this.aborted = function() {
return j;
}, this.abort = function() {
j = !0, r.abort(), s.meta.aborted = !0, _(t.complete) && t.complete(s), e = "";
};
}
function se(t) {
return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function fe(t) {
var e, r = (t = t || {}).delimiter, n = t.newline, a = t.comments, f = t.step, d = t.preview, B = t.fastMode, C = e = t.quoteChar === void 0 || t.quoteChar === null ? '"' : t.quoteChar;
if (t.escapeChar !== void 0 && (C = t.escapeChar), (typeof r != "string" || -1 < l.BAD_DELIMITERS.indexOf(r)) && (r = ","), a === r)
throw new Error("Comment character same as delimiter");
a === !0 ? a = "#" : (typeof a != "string" || -1 < l.BAD_DELIMITERS.indexOf(a)) && (a = !1), n !== `
` && n !== "\r" && n !== `\r
` && (n = `
`);
var o = 0, x = !1;
this.parse = function(h, j, S) {
if (typeof h != "string")
throw new Error("Input must be a string");
var s = h.length, k = r.length, M = n.length, R = a.length, F = _(f), D = [], L = [], u = [], p = o = 0;
if (!h)
return q();
if (t.header && !j) {
var b = h.split(n)[0].split(r), I = [], y = {}, T = !1;
for (var O in b) {
var v = b[O];
_(t.transformHeader) && (v = t.transformHeader(v, O));
var W = v, N = y[v] || 0;
for (0 < N && (T = !0, W = v + "_" + N), y[v] = N + 1; I.includes(W); )
W = W + "_" + N;
I.push(W);
}
if (T) {
var H = h.split(n);
H[0] = I.join(r), h = H.join(n);
}
}
if (B || B !== !1 && h.indexOf(e) === -1) {
for (var Q = h.split(n), P = 0; P < Q.length; P++) {
if (u = Q[P], o += u.length, P !== Q.length - 1)
o += n.length;
else if (S)
return q();
if (!a || u.substring(0, R) !== a) {
if (F) {
if (D = [], te(u.split(r)), he(), x)
return q();
} else
te(u.split(r));
if (d && d <= P)
return D = D.slice(0, d), q(!0);
}
}
return q();
}
for (var w = h.indexOf(r, o), A = h.indexOf(n, o), ee = new RegExp(se(C) + se(e), "g"), g = h.indexOf(e, o); ; )
if (h[o] !== e)
if (a && u.length === 0 && h.substring(o, o + R) === a) {
if (A === -1)
return q();
o = A + M, A = h.indexOf(n, o), w = h.indexOf(r, o);
} else if (w !== -1 && (w < A || A === -1))
u.push(h.substring(o, w)), o = w + k, w = h.indexOf(r, o);
else {
if (A === -1)
break;
if (u.push(h.substring(o, A)), X(A + M), F && (he(), x))
return q();
if (d && D.length >= d)
return q(!0);
}
else
for (g = o, o++; ; ) {
if ((g = h.indexOf(e, g + 1)) === -1)
return S || L.push({ type: "Quotes", code: "MissingQuotes", message: "Quoted field unterminated", row: D.length, index: o }), V();
if (g === s - 1)
return V(h.substring(o, g).replace(ee, e));
if (e !== C || h[g + 1] !== C) {
if (e === C || g === 0 || h[g - 1] !== C) {
w !== -1 && w < g + 1 && (w = h.indexOf(r, g + 1)), A !== -1 && A < g + 1 && (A = h.indexOf(n, g + 1));
var re = Y(A === -1 ? w : Math.min(w, A));
if (h.substr(g + 1 + re, k) === r) {
u.push(h.substring(o, g).replace(ee, e)), h[o = g + 1 + re + k] !== e && (g = h.indexOf(e, o)), w = h.indexOf(r, o), A = h.indexOf(n, o);
break;
}
var $ = Y(A);
if (h.substring(g + 1 + $, g + 1 + $ + M) === n) {
if (u.push(h.substring(o, g).replace(ee, e)), X(g + 1 + $ + M), w = h.indexOf(r, o), g = h.indexOf(e, o), F && (he(), x))
return q();
if (d && D.length >= d)
return q(!0);
break;
}
L.push({ type: "Quotes", code: "InvalidQuotes", message: "Trailing quote on quoted field is malformed", row: D.length, index: o }), g++;
}
} else
g++;
}
return V();
function te(K) {
D.push(K), p = o;
}
function Y(K) {
var ye = 0;
if (K !== -1) {
var de = h.substring(g + 1, K);
de && de.trim() === "" && (ye = de.length);
}
return ye;
}
function V(K) {
return S || (K === void 0 && (K = h.substring(o)), u.push(K), o = s, te(u), F && he()), q();
}
function X(K) {
o = K, te(u), u = [], A = h.indexOf(n, o);
}
function q(K) {
return { data: D, errors: L, meta: { delimiter: r, linebreak: n, aborted: x, truncated: !!K, cursor: p + (j || 0) } };
}
function he() {
f(q()), D = [], L = [];
}
}, this.abort = function() {
x = !0;
}, this.getCharIndex = function() {
return o;
};
}
function ve(t) {
var e = t.data, r = J[e.workerId], n = !1;
if (e.error)
r.userError(e.error, e.file);
else if (e.results && e.results.data) {
var a = { abort: function() {
n = !0, ge(e.workerId, { data: [], errors: [], meta: { aborted: !0 } });
}, pause: _e, resume: _e };
if (_(r.userStep)) {
for (var f = 0; f < e.results.data.length && (r.userStep({ data: e.results.data[f], errors: e.results.errors, meta: e.results.meta }, a), !n); f++)
;
delete e.results;
} else
_(r.userChunk) && (r.userChunk(e.results, a, e.file), delete e.results);
}
e.finished && !n && ge(e.workerId, e.results);
}
function ge(t, e) {
var r = J[t];
_(r.userComplete) && r.userComplete(e), r.terminate(), delete J[t];
}
function _e() {
throw new Error("Not implemented.");
}
function le(t) {
if (typeof t != "object" || t === null)
return t;
var e = Array.isArray(t) ? [] : {};
for (var r in t)
e[r] = le(t[r]);
return e;
}
function Z(t, e) {
return function() {
t.apply(e, arguments);
};
}
function _(t) {
return typeof t == "function";
}
return G && (c.onmessage = function(t) {
var e = t.data;
if (l.WORKER_ID === void 0 && e && (l.WORKER_ID = e.workerId), typeof e.input == "string")
c.postMessage({ workerId: l.WORKER_ID, results: l.parse(e.input, e.config), finished: !0 });
else if (c.File && e.input instanceof File || e.input instanceof Object) {
var r = l.parse(e.input, e.config);
r && c.postMessage({ workerId: l.WORKER_ID, results: r, finished: !0 });
}
}), (ae.prototype = Object.create(U.prototype)).constructor = ae, (oe.prototype = Object.create(U.prototype)).constructor = oe, (ie.prototype = Object.create(ie.prototype)).constructor = ie, (ue.prototype = Object.create(U.prototype)).constructor = ue, l;
});
})(Ee);
export {
p as createDownloadBlobLink,
i as flattenObject,
d as formatSizeUnit,
a as isEmptyObj,
f as isJSONString,
y as parseJSONSafely,
u as stringifyObjSafely,
l as unflattenObject
Le as createDownloadBlobLink,
be as downloadFile,
ke as flattenObject,
Ie as formatSizeUnit,
De as formatValueToMinUnit,
Re as isEmptyObj,
Ae as isJSONString,
xe as parseJSONSafely,
Oe as stringifyObjSafely,
Ce as unflattenObject
};
{
"name": "@emqx/shared-ui-utils",
"version": "0.0.11",
"version": "0.0.12",
"homepage": "https://emqx.io",

@@ -27,2 +27,9 @@ "license": "Apache-2.0",

},
"dependencies": {
"papaparse": "^5.4.1",
"vue-i18n": "^9.10.2"
},
"devDependencies": {
"@types/papaparse": "^5.3.14"
},
"scripts": {

@@ -29,0 +36,0 @@ "dev": "vite",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc