@ztimson/utils 0.22.1 → 0.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/csv.d.ts +1 -1
- package/dist/index.cjs +8 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +8 -15
- package/dist/index.mjs.map +1 -1
- package/dist/objects.d.ts +2 -2
- package/dist/path-events.d.ts +1 -1
- package/package.json +1 -1
package/dist/csv.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -57,8 +57,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
57
57
|
function flattenObj(obj, parent, result = {}) {
|
|
58
58
|
if (typeof obj === "object" && !Array.isArray(obj)) {
|
|
59
59
|
for (const key of Object.keys(obj)) {
|
|
60
|
-
const propName = parent ? parent
|
|
61
|
-
if (typeof obj[key] === "object") {
|
|
60
|
+
const propName = parent ? `${parent}.${key}` : key;
|
|
61
|
+
if (typeof obj[key] === "object" && obj[key] != null && !Array.isArray(obj[key])) {
|
|
62
|
+
console.log(propName);
|
|
62
63
|
flattenObj(obj[key], propName, result);
|
|
63
64
|
} else {
|
|
64
65
|
result[propName] = obj[key];
|
|
@@ -411,21 +412,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
411
412
|
return this;
|
|
412
413
|
}
|
|
413
414
|
}
|
|
414
|
-
function
|
|
415
|
-
const headers = target.reduce((acc, row) =>
|
|
416
|
-
Object.keys(flatten ? flattenObj(row) : row).forEach((key) => {
|
|
417
|
-
if (!acc.includes(key)) acc.push(key);
|
|
418
|
-
});
|
|
419
|
-
return acc;
|
|
420
|
-
}, []);
|
|
415
|
+
function toCsv(target, flatten = true) {
|
|
416
|
+
const headers = new ASet(target.reduce((acc, row) => [...acc, ...Object.keys(flatten ? flattenObj(row) : row)], []));
|
|
421
417
|
return [
|
|
422
418
|
headers.join(","),
|
|
423
419
|
...target.map((row) => headers.map((h) => {
|
|
424
420
|
const value = dotNotation(row, h);
|
|
425
|
-
|
|
426
|
-
if (type == "string" && value.includes(",")) return `"${value}"`;
|
|
427
|
-
if (type == "object") return `"${JSON.stringify(value)}"`;
|
|
428
|
-
return value;
|
|
421
|
+
return typeof value == "object" && value != null ? '"' + JSONSanitize(value).replaceAll('"', '""') + '"' : value;
|
|
429
422
|
}).join(","))
|
|
430
423
|
].join("\n");
|
|
431
424
|
}
|
|
@@ -1126,7 +1119,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1126
1119
|
__publicField(this, "methods");
|
|
1127
1120
|
var _a;
|
|
1128
1121
|
if (typeof Event == "object") return Object.assign(this, Event);
|
|
1129
|
-
let [p, scope, method] = Event.split(":");
|
|
1122
|
+
let [p, scope, method] = Event.replaceAll(/\/{2,}/g, "/").split(":");
|
|
1130
1123
|
if (!method) method = scope || "*";
|
|
1131
1124
|
if (p == "*" || !p && method == "*") {
|
|
1132
1125
|
p = "";
|
|
@@ -1518,7 +1511,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1518
1511
|
exports2.arrayDiff = arrayDiff;
|
|
1519
1512
|
exports2.caseInsensitiveSort = caseInsensitiveSort;
|
|
1520
1513
|
exports2.clean = clean;
|
|
1521
|
-
exports2.csv = csv;
|
|
1522
1514
|
exports2.dec2Frac = dec2Frac;
|
|
1523
1515
|
exports2.deepCopy = deepCopy;
|
|
1524
1516
|
exports2.deepMerge = deepMerge;
|
|
@@ -1558,6 +1550,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1558
1550
|
exports2.strSplice = strSplice;
|
|
1559
1551
|
exports2.timeUntil = timeUntil;
|
|
1560
1552
|
exports2.timestampFilename = timestampFilename;
|
|
1553
|
+
exports2.toCsv = toCsv;
|
|
1561
1554
|
exports2.typeKeys = typeKeys;
|
|
1562
1555
|
exports2.uploadWithProgress = uploadWithProgress;
|
|
1563
1556
|
exports2.validateEmail = validateEmail;
|