@ztimson/utils 0.21.6 → 0.22.0
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/index.cjs +137 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +137 -7
- package/dist/index.mjs.map +1 -1
- package/dist/string.d.ts +10 -0
- package/dist/time.d.ts +3 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -996,6 +996,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
996
996
|
return c;
|
|
997
997
|
}).join("");
|
|
998
998
|
}
|
|
999
|
+
function strSplice(str, start, deleteCount, insert = "") {
|
|
1000
|
+
const before = str.slice(0, start);
|
|
1001
|
+
const after = str.slice(start + deleteCount);
|
|
1002
|
+
return before + insert + after;
|
|
1003
|
+
}
|
|
999
1004
|
function matchAll(value, regex) {
|
|
1000
1005
|
if (typeof regex === "string") {
|
|
1001
1006
|
regex = new RegExp(regex, "g");
|
|
@@ -1334,14 +1339,138 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1334
1339
|
if (timeout) clearTimeout(timeout);
|
|
1335
1340
|
};
|
|
1336
1341
|
}
|
|
1337
|
-
function formatDate(date) {
|
|
1342
|
+
function formatDate(date, format = "YYYY-MM-DD H:mm ") {
|
|
1338
1343
|
if (typeof date == "number" || typeof date == "string") date = new Date(date);
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1344
|
+
function day(num) {
|
|
1345
|
+
switch (num) {
|
|
1346
|
+
case 0:
|
|
1347
|
+
return "Sunday";
|
|
1348
|
+
case 1:
|
|
1349
|
+
return "Monday";
|
|
1350
|
+
case 2:
|
|
1351
|
+
return "Tuesday";
|
|
1352
|
+
case 3:
|
|
1353
|
+
return "Wednesday";
|
|
1354
|
+
case 4:
|
|
1355
|
+
return "Thursday";
|
|
1356
|
+
case 5:
|
|
1357
|
+
return "Friday";
|
|
1358
|
+
case 6:
|
|
1359
|
+
return "Saturday";
|
|
1360
|
+
default:
|
|
1361
|
+
return "Unknown";
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
function doy(date2) {
|
|
1365
|
+
const start = /* @__PURE__ */ new Date(`${date2.getFullYear()}-01-01 0:00:00`);
|
|
1366
|
+
return Math.ceil((date2.getTime() - start.getTime()) / (1e3 * 60 * 60 * 24));
|
|
1367
|
+
}
|
|
1368
|
+
function month(num) {
|
|
1369
|
+
switch (num) {
|
|
1370
|
+
case 0:
|
|
1371
|
+
return "January";
|
|
1372
|
+
case 1:
|
|
1373
|
+
return "February";
|
|
1374
|
+
case 2:
|
|
1375
|
+
return "March";
|
|
1376
|
+
case 3:
|
|
1377
|
+
return "April";
|
|
1378
|
+
case 4:
|
|
1379
|
+
return "May";
|
|
1380
|
+
case 5:
|
|
1381
|
+
return "June";
|
|
1382
|
+
case 6:
|
|
1383
|
+
return "July";
|
|
1384
|
+
case 7:
|
|
1385
|
+
return "August";
|
|
1386
|
+
case 8:
|
|
1387
|
+
return "September";
|
|
1388
|
+
case 9:
|
|
1389
|
+
return "October";
|
|
1390
|
+
case 10:
|
|
1391
|
+
return "November";
|
|
1392
|
+
case 11:
|
|
1393
|
+
return "December";
|
|
1394
|
+
default:
|
|
1395
|
+
return "Unknown";
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
function suffix(num) {
|
|
1399
|
+
let n = num.toString();
|
|
1400
|
+
switch (n.at(-1)) {
|
|
1401
|
+
case "1":
|
|
1402
|
+
return num + "st";
|
|
1403
|
+
case "2":
|
|
1404
|
+
return num + "nd";
|
|
1405
|
+
case "3":
|
|
1406
|
+
return num + "rd";
|
|
1407
|
+
default:
|
|
1408
|
+
return num + "th";
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
function tzOffset(offset) {
|
|
1412
|
+
const hours = ~~(offset / 60);
|
|
1413
|
+
const minutes = offset % 60;
|
|
1414
|
+
return (offset > 0 ? "-" : "") + `${hours}:${minutes.toString().padStart(2, "0")}`;
|
|
1415
|
+
}
|
|
1416
|
+
function timezone(offset) {
|
|
1417
|
+
const hours = offset / 60;
|
|
1418
|
+
switch (hours) {
|
|
1419
|
+
case -12:
|
|
1420
|
+
return "IDLW";
|
|
1421
|
+
case -11:
|
|
1422
|
+
return "SST";
|
|
1423
|
+
case -10:
|
|
1424
|
+
return "HST";
|
|
1425
|
+
case -9:
|
|
1426
|
+
return "AKST";
|
|
1427
|
+
case -8:
|
|
1428
|
+
return "PST";
|
|
1429
|
+
case -7:
|
|
1430
|
+
return "MST";
|
|
1431
|
+
case -6:
|
|
1432
|
+
return "CST";
|
|
1433
|
+
case -5:
|
|
1434
|
+
return "EST";
|
|
1435
|
+
case -4:
|
|
1436
|
+
return "AST";
|
|
1437
|
+
case -3:
|
|
1438
|
+
return "ART";
|
|
1439
|
+
case -2:
|
|
1440
|
+
return "FNT";
|
|
1441
|
+
case -1:
|
|
1442
|
+
return "AZOT";
|
|
1443
|
+
case 0:
|
|
1444
|
+
return "UTC";
|
|
1445
|
+
case 1:
|
|
1446
|
+
return "CET";
|
|
1447
|
+
case 2:
|
|
1448
|
+
return "EET";
|
|
1449
|
+
case 3:
|
|
1450
|
+
return "MSK";
|
|
1451
|
+
case 4:
|
|
1452
|
+
return "SAMT";
|
|
1453
|
+
case 5:
|
|
1454
|
+
return "YEKT";
|
|
1455
|
+
case 6:
|
|
1456
|
+
return "OMST";
|
|
1457
|
+
case 7:
|
|
1458
|
+
return "KRAT";
|
|
1459
|
+
case 8:
|
|
1460
|
+
return "CST";
|
|
1461
|
+
case 9:
|
|
1462
|
+
return "JST";
|
|
1463
|
+
case 10:
|
|
1464
|
+
return "AEST";
|
|
1465
|
+
case 11:
|
|
1466
|
+
return "SBT";
|
|
1467
|
+
case 12:
|
|
1468
|
+
return "NZST";
|
|
1469
|
+
default:
|
|
1470
|
+
return "";
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
return format.replaceAll("YYYY", date.getFullYear().toString()).replaceAll("YY", date.getFullYear().toString().slice(2)).replaceAll("MMMM", month(date.getMonth())).replaceAll("MMM", month(date.getMonth()).slice(0, 2)).replaceAll("MM", (date.getMonth() + 1).toString().padStart(2, "0")).replaceAll("M", (date.getMonth() + 1).toString()).replaceAll("DDD", doy(date).toString()).replaceAll("DD", date.getDate().toString().padStart(2, "0")).replaceAll("Do", suffix(date.getDate())).replaceAll("D", date.getDate().toString()).replaceAll("dddd", day(date.getDay())).replaceAll("ddd", day(date.getDay()).slice(0, 2)).replaceAll("dd", date.getDate().toString().padStart(2, "0")).replaceAll("d", date.getDay().toString()).replaceAll("HH", date.getHours().toString().padStart(2, "0")).replaceAll("H", date.getHours().toString()).replaceAll("hh", (date.getHours() > 12 ? date.getHours() - 12 : date.getHours()).toString().padStart(2, "0")).replaceAll("h", (date.getHours() > 12 ? date.getHours() - 12 : date.getHours()).toString()).replaceAll("mm", date.getMinutes().toString().padStart(2, "0")).replaceAll("m", date.getMinutes().toString()).replaceAll("ss", date.getSeconds().toString().padStart(2, "0")).replaceAll("s", date.getSeconds().toString()).replaceAll("SSS", date.getMilliseconds().toString()).replaceAll("SS", date.getMilliseconds().toString().slice(0, 1)).replaceAll("S", date.getMilliseconds().toString()[0]).replaceAll("A", date.getHours() >= 12 ? "PM" : "AM").replaceAll("a", date.getHours() >= 12 ? "pm" : "am").replaceAll("ZZ", tzOffset(date.getTimezoneOffset()).replace(":", "")).replaceAll("Z", tzOffset(date.getTimezoneOffset())).replaceAll("z", timezone(date.getTimezoneOffset()));
|
|
1345
1474
|
}
|
|
1346
1475
|
function sleep(ms) {
|
|
1347
1476
|
return new Promise((res) => setTimeout(res, ms));
|
|
@@ -1427,6 +1556,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1427
1556
|
exports2.sleep = sleep;
|
|
1428
1557
|
exports2.sleepWhile = sleepWhile;
|
|
1429
1558
|
exports2.sortByProp = sortByProp;
|
|
1559
|
+
exports2.strSplice = strSplice;
|
|
1430
1560
|
exports2.timeUntil = timeUntil;
|
|
1431
1561
|
exports2.timestampFilename = timestampFilename;
|
|
1432
1562
|
exports2.tyoeKeys = tyoeKeys;
|