@ztimson/utils 0.22.4 → 0.22.5
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 -0
- package/dist/index.cjs +18 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +18 -2
- package/dist/index.mjs.map +1 -1
- package/dist/string.d.ts +16 -0
- package/package.json +1 -1
package/dist/csv.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -412,6 +412,17 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
412
412
|
return this;
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
|
+
function fromCsv(csv, hasHeaders = true) {
|
|
416
|
+
const row = csv.split("\n");
|
|
417
|
+
let headers = hasHeaders ? row.splice(0, 1)[0] : null;
|
|
418
|
+
if (headers) headers = headers.match(/(?:[^,"']+|"[^"]*"|'[^']*')+/g);
|
|
419
|
+
return row.map((r) => {
|
|
420
|
+
const props = r.match(/(?:[^,"']+|"[^"]*"|'[^']*')+/g);
|
|
421
|
+
const h = headers || Array(props.length).fill(null).map((r2, i) => {
|
|
422
|
+
});
|
|
423
|
+
return h.reduce((acc, h2, i) => ({ ...acc, [h2]: props[i] }), {});
|
|
424
|
+
});
|
|
425
|
+
}
|
|
415
426
|
function toCsv(target, flatten = true) {
|
|
416
427
|
const headers = new ASet(target.reduce((acc, row) => [...acc, ...Object.keys(flatten ? flattenObj(row) : row)], []));
|
|
417
428
|
return [
|
|
@@ -947,10 +958,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
947
958
|
split = split.pop().split("/");
|
|
948
959
|
return whole + Number(split[0]) / Number(split[1]);
|
|
949
960
|
}
|
|
950
|
-
const LETTER_LIST = "
|
|
961
|
+
const LETTER_LIST = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
951
962
|
const NUMBER_LIST = "0123456789";
|
|
952
963
|
const SYMBOL_LIST = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/";
|
|
953
|
-
const CHAR_LIST = LETTER_LIST + NUMBER_LIST + SYMBOL_LIST;
|
|
964
|
+
const CHAR_LIST = LETTER_LIST + LETTER_LIST.toLowerCase() + NUMBER_LIST + SYMBOL_LIST;
|
|
954
965
|
function formatBytes(bytes, decimals = 2) {
|
|
955
966
|
if (bytes === 0) return "0 Bytes";
|
|
956
967
|
const k = 1024;
|
|
@@ -1487,6 +1498,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1487
1498
|
exports2.ASet = ASet;
|
|
1488
1499
|
exports2.BadGatewayError = BadGatewayError;
|
|
1489
1500
|
exports2.BadRequestError = BadRequestError;
|
|
1501
|
+
exports2.CHAR_LIST = CHAR_LIST;
|
|
1490
1502
|
exports2.Cache = Cache;
|
|
1491
1503
|
exports2.CliBackground = CliBackground;
|
|
1492
1504
|
exports2.CliEffects = CliEffects;
|
|
@@ -1498,9 +1510,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1498
1510
|
exports2.InternalServerError = InternalServerError;
|
|
1499
1511
|
exports2.JSONAttemptParse = JSONAttemptParse;
|
|
1500
1512
|
exports2.JSONSanitize = JSONSanitize;
|
|
1513
|
+
exports2.LETTER_LIST = LETTER_LIST;
|
|
1501
1514
|
exports2.LOG_LEVEL = LOG_LEVEL;
|
|
1502
1515
|
exports2.Logger = Logger;
|
|
1503
1516
|
exports2.MethodNotAllowedError = MethodNotAllowedError;
|
|
1517
|
+
exports2.NUMBER_LIST = NUMBER_LIST;
|
|
1504
1518
|
exports2.NotAcceptableError = NotAcceptableError;
|
|
1505
1519
|
exports2.NotFoundError = NotFoundError;
|
|
1506
1520
|
exports2.NotImplementedError = NotImplementedError;
|
|
@@ -1511,6 +1525,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1511
1525
|
exports2.PathEventEmitter = PathEventEmitter;
|
|
1512
1526
|
exports2.PaymentRequiredError = PaymentRequiredError;
|
|
1513
1527
|
exports2.PromiseProgress = PromiseProgress;
|
|
1528
|
+
exports2.SYMBOL_LIST = SYMBOL_LIST;
|
|
1514
1529
|
exports2.ServiceUnavailableError = ServiceUnavailableError;
|
|
1515
1530
|
exports2.TypedEmitter = TypedEmitter;
|
|
1516
1531
|
exports2.UnauthorizedError = UnauthorizedError;
|
|
@@ -1538,6 +1553,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1538
1553
|
exports2.formatDate = formatDate;
|
|
1539
1554
|
exports2.formatPhoneNumber = formatPhoneNumber;
|
|
1540
1555
|
exports2.fracToDec = fracToDec;
|
|
1556
|
+
exports2.fromCsv = fromCsv;
|
|
1541
1557
|
exports2.gravatar = gravatar;
|
|
1542
1558
|
exports2.includes = includes;
|
|
1543
1559
|
exports2.insertAt = insertAt;
|