@ztimson/utils 0.21.5 → 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/LICENSE +0 -0
- package/README.md +91 -91
- package/dist/array.d.ts +0 -0
- package/dist/aset.d.ts +0 -0
- package/dist/cache.d.ts +0 -0
- package/dist/csv.d.ts +0 -0
- package/dist/emitter.d.ts +0 -0
- package/dist/errors.d.ts +1 -1
- package/dist/files.d.ts +0 -0
- package/dist/http.d.ts +0 -0
- package/dist/index.cjs +153 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -0
- package/dist/index.mjs +153 -8
- package/dist/index.mjs.map +1 -1
- package/dist/jwt.d.ts +0 -0
- package/dist/logger.d.ts +0 -0
- package/dist/math.d.ts +0 -0
- package/dist/misc.d.ts +0 -0
- package/dist/objects.d.ts +0 -0
- package/dist/path-events.d.ts +0 -0
- package/dist/promise-progress.d.ts +0 -0
- package/dist/string.d.ts +10 -0
- package/dist/time.d.ts +10 -2
- package/dist/types.d.ts +0 -0
- package/package.json +1 -1
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
<!-- Header -->
|
|
2
|
-
<div id="top" align="center">
|
|
3
|
-
<br />
|
|
4
|
-
|
|
5
|
-
<!-- Logo -->
|
|
6
|
-
<img src="https://git.zakscode.com/repo-avatars/77dbab78e5fb3302dc9e751c4d6315a64df8d3a714d5cd5719b0dc39e6619119" alt="Logo" width="200" height="200">
|
|
7
|
-
|
|
8
|
-
<!-- Title -->
|
|
9
|
-
### @ztimson/utils
|
|
10
|
-
|
|
11
|
-
<!-- Description -->
|
|
12
|
-
Javascript/Typescript Utilities
|
|
13
|
-
|
|
14
|
-
<!-- Repo badges -->
|
|
15
|
-
[](https://git.zakscode.com/ztimson/utils/tags)
|
|
16
|
-
[](https://git.zakscode.com/ztimson/utils/pulls)
|
|
17
|
-
[](https://git.zakscode.com/ztimson/utils/issues)
|
|
18
|
-
|
|
19
|
-
<!-- Links -->
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
<div>
|
|
23
|
-
<a href="https://utils.docs.zakscode.com" target="_blank">Documentation</a>
|
|
24
|
-
• <a href="https://git.zakscode.com/ztimson/utils/releases" target="_blank">Release Notes</a>
|
|
25
|
-
• <a href="https://git.zakscode.com/ztimson/utils/issues/new?template=.github%2fissue_template%2fbug.md" target="_blank">Report a Bug</a>
|
|
26
|
-
• <a href="https://git.zakscode.com/ztimson/utils/issues/new?template=.github%2fissue_template%2fenhancement.md" target="_blank">Request a Feature</a>
|
|
27
|
-
</div>
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
</div>
|
|
31
|
-
|
|
32
|
-
## Table of Contents
|
|
33
|
-
- [@ztimson/utils](#top)
|
|
34
|
-
- [About](#about)
|
|
35
|
-
- [Built With](#built-with)
|
|
36
|
-
- [Setup](#setup)
|
|
37
|
-
- [Production](#production)
|
|
38
|
-
- [Development](#development)
|
|
39
|
-
- [Documentation](https://utils.docs.zakscode.com/)
|
|
40
|
-
- [License](#license)
|
|
41
|
-
|
|
42
|
-
## About
|
|
43
|
-
|
|
44
|
-
A collection of utilities to make life a little easier
|
|
45
|
-
|
|
46
|
-
### Built With
|
|
47
|
-
[](https://typescriptlang.org/)
|
|
48
|
-
|
|
49
|
-
## Setup
|
|
50
|
-
|
|
51
|
-
<details>
|
|
52
|
-
<summary>
|
|
53
|
-
<h3 id="production" style="display: inline">
|
|
54
|
-
Production
|
|
55
|
-
</h3>
|
|
56
|
-
</summary>
|
|
57
|
-
|
|
58
|
-
#### Prerequisites
|
|
59
|
-
- [Node.js](https://nodejs.org/en/download)
|
|
60
|
-
|
|
61
|
-
#### Instructions
|
|
62
|
-
1. Install persist: `npm i @ztimosn/utils`
|
|
63
|
-
|
|
64
|
-
</details>
|
|
65
|
-
|
|
66
|
-
<details>
|
|
67
|
-
<summary>
|
|
68
|
-
<h3 id="development" style="display: inline">
|
|
69
|
-
Development
|
|
70
|
-
</h3>
|
|
71
|
-
</summary>
|
|
72
|
-
|
|
73
|
-
#### Prerequisites
|
|
74
|
-
- [Node.js](https://nodejs.org/en/download)
|
|
75
|
-
|
|
76
|
-
#### Instructions
|
|
77
|
-
1. Install the dependencies: `npm i`
|
|
78
|
-
2. Build library: `npm build`
|
|
79
|
-
3. Run unit tests: `npm test`
|
|
80
|
-
|
|
81
|
-
</details>
|
|
82
|
-
|
|
83
|
-
## Documentation
|
|
84
|
-
|
|
85
|
-
[Available Here](https://utils.docs.zakscode.com/)
|
|
86
|
-
|
|
87
|
-
## License
|
|
88
|
-
|
|
89
|
-
Copyright © 2023 Zakary Timson | Available under MIT Licensing
|
|
90
|
-
|
|
91
|
-
See the [license](_media/LICENSE) for more information.
|
|
1
|
+
<!-- Header -->
|
|
2
|
+
<div id="top" align="center">
|
|
3
|
+
<br />
|
|
4
|
+
|
|
5
|
+
<!-- Logo -->
|
|
6
|
+
<img src="https://git.zakscode.com/repo-avatars/77dbab78e5fb3302dc9e751c4d6315a64df8d3a714d5cd5719b0dc39e6619119" alt="Logo" width="200" height="200">
|
|
7
|
+
|
|
8
|
+
<!-- Title -->
|
|
9
|
+
### @ztimson/utils
|
|
10
|
+
|
|
11
|
+
<!-- Description -->
|
|
12
|
+
Javascript/Typescript Utilities
|
|
13
|
+
|
|
14
|
+
<!-- Repo badges -->
|
|
15
|
+
[](https://git.zakscode.com/ztimson/utils/tags)
|
|
16
|
+
[](https://git.zakscode.com/ztimson/utils/pulls)
|
|
17
|
+
[](https://git.zakscode.com/ztimson/utils/issues)
|
|
18
|
+
|
|
19
|
+
<!-- Links -->
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
<div>
|
|
23
|
+
<a href="https://utils.docs.zakscode.com" target="_blank">Documentation</a>
|
|
24
|
+
• <a href="https://git.zakscode.com/ztimson/utils/releases" target="_blank">Release Notes</a>
|
|
25
|
+
• <a href="https://git.zakscode.com/ztimson/utils/issues/new?template=.github%2fissue_template%2fbug.md" target="_blank">Report a Bug</a>
|
|
26
|
+
• <a href="https://git.zakscode.com/ztimson/utils/issues/new?template=.github%2fissue_template%2fenhancement.md" target="_blank">Request a Feature</a>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
## Table of Contents
|
|
33
|
+
- [@ztimson/utils](#top)
|
|
34
|
+
- [About](#about)
|
|
35
|
+
- [Built With](#built-with)
|
|
36
|
+
- [Setup](#setup)
|
|
37
|
+
- [Production](#production)
|
|
38
|
+
- [Development](#development)
|
|
39
|
+
- [Documentation](https://utils.docs.zakscode.com/)
|
|
40
|
+
- [License](#license)
|
|
41
|
+
|
|
42
|
+
## About
|
|
43
|
+
|
|
44
|
+
A collection of utilities to make life a little easier
|
|
45
|
+
|
|
46
|
+
### Built With
|
|
47
|
+
[](https://typescriptlang.org/)
|
|
48
|
+
|
|
49
|
+
## Setup
|
|
50
|
+
|
|
51
|
+
<details>
|
|
52
|
+
<summary>
|
|
53
|
+
<h3 id="production" style="display: inline">
|
|
54
|
+
Production
|
|
55
|
+
</h3>
|
|
56
|
+
</summary>
|
|
57
|
+
|
|
58
|
+
#### Prerequisites
|
|
59
|
+
- [Node.js](https://nodejs.org/en/download)
|
|
60
|
+
|
|
61
|
+
#### Instructions
|
|
62
|
+
1. Install persist: `npm i @ztimosn/utils`
|
|
63
|
+
|
|
64
|
+
</details>
|
|
65
|
+
|
|
66
|
+
<details>
|
|
67
|
+
<summary>
|
|
68
|
+
<h3 id="development" style="display: inline">
|
|
69
|
+
Development
|
|
70
|
+
</h3>
|
|
71
|
+
</summary>
|
|
72
|
+
|
|
73
|
+
#### Prerequisites
|
|
74
|
+
- [Node.js](https://nodejs.org/en/download)
|
|
75
|
+
|
|
76
|
+
#### Instructions
|
|
77
|
+
1. Install the dependencies: `npm i`
|
|
78
|
+
2. Build library: `npm build`
|
|
79
|
+
3. Run unit tests: `npm test`
|
|
80
|
+
|
|
81
|
+
</details>
|
|
82
|
+
|
|
83
|
+
## Documentation
|
|
84
|
+
|
|
85
|
+
[Available Here](https://utils.docs.zakscode.com/)
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
Copyright © 2023 Zakary Timson | Available under MIT Licensing
|
|
90
|
+
|
|
91
|
+
See the [license](_media/LICENSE) for more information.
|
package/dist/array.d.ts
CHANGED
|
File without changes
|
package/dist/aset.d.ts
CHANGED
|
File without changes
|
package/dist/cache.d.ts
CHANGED
|
File without changes
|
package/dist/csv.d.ts
CHANGED
|
File without changes
|
package/dist/emitter.d.ts
CHANGED
|
File without changes
|
package/dist/errors.d.ts
CHANGED
|
@@ -74,4 +74,4 @@ export declare class GatewayTimeoutError extends CustomError {
|
|
|
74
74
|
* @param {string} message Override default error message
|
|
75
75
|
* @return {CustomError} The proper error type
|
|
76
76
|
*/
|
|
77
|
-
export declare function errorFromCode(code: number, message?: string): CustomError
|
|
77
|
+
export declare function errorFromCode(code: number, message?: string): CustomError;
|
package/dist/files.d.ts
CHANGED
|
File without changes
|
package/dist/http.d.ts
CHANGED
|
File without changes
|
package/dist/index.cjs
CHANGED
|
@@ -711,7 +711,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
711
711
|
}
|
|
712
712
|
__publicField(GatewayTimeoutError, "code", 504);
|
|
713
713
|
function errorFromCode(code, message) {
|
|
714
|
-
if (code >= 200 && code < 300) return null;
|
|
715
714
|
switch (code) {
|
|
716
715
|
case 400:
|
|
717
716
|
return new BadRequestError(message);
|
|
@@ -997,6 +996,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
997
996
|
return c;
|
|
998
997
|
}).join("");
|
|
999
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
|
+
}
|
|
1000
1004
|
function matchAll(value, regex) {
|
|
1001
1005
|
if (typeof regex === "string") {
|
|
1002
1006
|
regex = new RegExp(regex, "g");
|
|
@@ -1320,14 +1324,153 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1320
1324
|
emitter.on("*", (event, ...args) => this.emit(event, ...args));
|
|
1321
1325
|
}
|
|
1322
1326
|
}
|
|
1323
|
-
function
|
|
1327
|
+
function adjustedInterval(cb, ms) {
|
|
1328
|
+
let cancel = false, timeout = null;
|
|
1329
|
+
const p = async () => {
|
|
1330
|
+
if (cancel) return;
|
|
1331
|
+
const start = (/* @__PURE__ */ new Date()).getTime();
|
|
1332
|
+
await cb();
|
|
1333
|
+
const end = (/* @__PURE__ */ new Date()).getTime();
|
|
1334
|
+
timeout = setTimeout(() => p(), ms - (end - start) || 1);
|
|
1335
|
+
};
|
|
1336
|
+
p();
|
|
1337
|
+
return () => {
|
|
1338
|
+
cancel = true;
|
|
1339
|
+
if (timeout) clearTimeout(timeout);
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
function formatDate(date, format = "YYYY-MM-DD H:mm ") {
|
|
1324
1343
|
if (typeof date == "number" || typeof date == "string") date = new Date(date);
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
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()));
|
|
1331
1474
|
}
|
|
1332
1475
|
function sleep(ms) {
|
|
1333
1476
|
return new Promise((res) => setTimeout(res, ms));
|
|
@@ -1372,6 +1515,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1372
1515
|
exports2.TypedEmitter = TypedEmitter;
|
|
1373
1516
|
exports2.UnauthorizedError = UnauthorizedError;
|
|
1374
1517
|
exports2.addUnique = addUnique;
|
|
1518
|
+
exports2.adjustedInterval = adjustedInterval;
|
|
1375
1519
|
exports2.arrayDiff = arrayDiff;
|
|
1376
1520
|
exports2.caseInsensitiveSort = caseInsensitiveSort;
|
|
1377
1521
|
exports2.clean = clean;
|
|
@@ -1412,6 +1556,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1412
1556
|
exports2.sleep = sleep;
|
|
1413
1557
|
exports2.sleepWhile = sleepWhile;
|
|
1414
1558
|
exports2.sortByProp = sortByProp;
|
|
1559
|
+
exports2.strSplice = strSplice;
|
|
1415
1560
|
exports2.timeUntil = timeUntil;
|
|
1416
1561
|
exports2.timestampFilename = timestampFilename;
|
|
1417
1562
|
exports2.tyoeKeys = tyoeKeys;
|