@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/index.mjs
CHANGED
|
@@ -408,6 +408,17 @@ class Cache {
|
|
|
408
408
|
return this;
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
|
+
function fromCsv(csv, hasHeaders = true) {
|
|
412
|
+
const row = csv.split("\n");
|
|
413
|
+
let headers = hasHeaders ? row.splice(0, 1)[0] : null;
|
|
414
|
+
if (headers) headers = headers.match(/(?:[^,"']+|"[^"]*"|'[^']*')+/g);
|
|
415
|
+
return row.map((r) => {
|
|
416
|
+
const props = r.match(/(?:[^,"']+|"[^"]*"|'[^']*')+/g);
|
|
417
|
+
const h = headers || Array(props.length).fill(null).map((r2, i) => {
|
|
418
|
+
});
|
|
419
|
+
return h.reduce((acc, h2, i) => ({ ...acc, [h2]: props[i] }), {});
|
|
420
|
+
});
|
|
421
|
+
}
|
|
411
422
|
function toCsv(target, flatten = true) {
|
|
412
423
|
const headers = new ASet(target.reduce((acc, row) => [...acc, ...Object.keys(flatten ? flattenObj(row) : row)], []));
|
|
413
424
|
return [
|
|
@@ -943,10 +954,10 @@ function fracToDec(frac) {
|
|
|
943
954
|
split = split.pop().split("/");
|
|
944
955
|
return whole + Number(split[0]) / Number(split[1]);
|
|
945
956
|
}
|
|
946
|
-
const LETTER_LIST = "
|
|
957
|
+
const LETTER_LIST = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
947
958
|
const NUMBER_LIST = "0123456789";
|
|
948
959
|
const SYMBOL_LIST = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/";
|
|
949
|
-
const CHAR_LIST = LETTER_LIST + NUMBER_LIST + SYMBOL_LIST;
|
|
960
|
+
const CHAR_LIST = LETTER_LIST + LETTER_LIST.toLowerCase() + NUMBER_LIST + SYMBOL_LIST;
|
|
950
961
|
function formatBytes(bytes, decimals = 2) {
|
|
951
962
|
if (bytes === 0) return "0 Bytes";
|
|
952
963
|
const k = 1024;
|
|
@@ -1484,6 +1495,7 @@ export {
|
|
|
1484
1495
|
ASet,
|
|
1485
1496
|
BadGatewayError,
|
|
1486
1497
|
BadRequestError,
|
|
1498
|
+
CHAR_LIST,
|
|
1487
1499
|
Cache,
|
|
1488
1500
|
CliBackground,
|
|
1489
1501
|
CliEffects,
|
|
@@ -1495,9 +1507,11 @@ export {
|
|
|
1495
1507
|
InternalServerError,
|
|
1496
1508
|
JSONAttemptParse,
|
|
1497
1509
|
JSONSanitize,
|
|
1510
|
+
LETTER_LIST,
|
|
1498
1511
|
LOG_LEVEL,
|
|
1499
1512
|
Logger,
|
|
1500
1513
|
MethodNotAllowedError,
|
|
1514
|
+
NUMBER_LIST,
|
|
1501
1515
|
NotAcceptableError,
|
|
1502
1516
|
NotFoundError,
|
|
1503
1517
|
NotImplementedError,
|
|
@@ -1508,6 +1522,7 @@ export {
|
|
|
1508
1522
|
PathEventEmitter,
|
|
1509
1523
|
PaymentRequiredError,
|
|
1510
1524
|
PromiseProgress,
|
|
1525
|
+
SYMBOL_LIST,
|
|
1511
1526
|
ServiceUnavailableError,
|
|
1512
1527
|
TypedEmitter,
|
|
1513
1528
|
UnauthorizedError,
|
|
@@ -1535,6 +1550,7 @@ export {
|
|
|
1535
1550
|
formatDate,
|
|
1536
1551
|
formatPhoneNumber,
|
|
1537
1552
|
fracToDec,
|
|
1553
|
+
fromCsv,
|
|
1538
1554
|
gravatar,
|
|
1539
1555
|
includes,
|
|
1540
1556
|
insertAt,
|