@tb-dev/utils 1.5.2 → 1.7.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/array.cjs +0 -11
- package/dist/array.d.ts +2 -2
- package/dist/array.js +0 -11
- package/dist/index.cjs +24 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +25 -1
- package/dist/panic.cjs +18 -0
- package/dist/panic.d.ts +4 -0
- package/dist/panic.js +18 -0
- package/dist/promise.d.ts +2 -0
- package/dist/string.d.ts +3 -0
- package/package.json +22 -6
package/dist/array.cjs
CHANGED
|
@@ -8,16 +8,6 @@ function upsert(array, item, predicate) {
|
|
|
8
8
|
array[index] = item;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
function splitWhitespace(value) {
|
|
12
|
-
if (!value)
|
|
13
|
-
return [];
|
|
14
|
-
if (Array.isArray(value)) {
|
|
15
|
-
const array = value.map((i) => splitWhitespace(i));
|
|
16
|
-
return array.flat(Number.POSITIVE_INFINITY);
|
|
17
|
-
}
|
|
18
|
-
value = value.trim().split(/\s/);
|
|
19
|
-
return trimArray(value);
|
|
20
|
-
}
|
|
21
11
|
function toArray(item) {
|
|
22
12
|
const array = item ?? [];
|
|
23
13
|
return Array.isArray(array) ? array : [array];
|
|
@@ -25,7 +15,6 @@ function toArray(item) {
|
|
|
25
15
|
function trimArray(array) {
|
|
26
16
|
return array.map((i) => i.trim()).filter(Boolean);
|
|
27
17
|
}
|
|
28
|
-
exports.splitWhitespace = splitWhitespace;
|
|
29
18
|
exports.toArray = toArray;
|
|
30
19
|
exports.trimArray = trimArray;
|
|
31
20
|
exports.upsert = upsert;
|
package/dist/array.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MaybeArray, Nullish } from '@tb-dev/utility-types';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
3
|
+
/** Pushes an item to the array if it doesn't exist, otherwise updates it. */
|
|
4
|
+
export declare function upsert<T>(array: T[], item: T, predicate: (value: T) => boolean): void;
|
|
5
5
|
export declare function toArray<T>(item?: Nullish<MaybeArray<T>>): T[];
|
|
6
6
|
export declare function trimArray(array: string[]): string[];
|
package/dist/array.js
CHANGED
|
@@ -6,16 +6,6 @@ function upsert(array, item, predicate) {
|
|
|
6
6
|
array[index] = item;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
function splitWhitespace(value) {
|
|
10
|
-
if (!value)
|
|
11
|
-
return [];
|
|
12
|
-
if (Array.isArray(value)) {
|
|
13
|
-
const array = value.map((i) => splitWhitespace(i));
|
|
14
|
-
return array.flat(Number.POSITIVE_INFINITY);
|
|
15
|
-
}
|
|
16
|
-
value = value.trim().split(/\s/);
|
|
17
|
-
return trimArray(value);
|
|
18
|
-
}
|
|
19
9
|
function toArray(item) {
|
|
20
10
|
const array = item ?? [];
|
|
21
11
|
return Array.isArray(array) ? array : [array];
|
|
@@ -24,7 +14,6 @@ function trimArray(array) {
|
|
|
24
14
|
return array.map((i) => i.trim()).filter(Boolean);
|
|
25
15
|
}
|
|
26
16
|
export {
|
|
27
|
-
splitWhitespace,
|
|
28
17
|
toArray,
|
|
29
18
|
trimArray,
|
|
30
19
|
upsert
|
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const regex = require("./regex.cjs");
|
|
4
4
|
const array = require("./array.cjs");
|
|
5
|
+
const panic = require("./panic.cjs");
|
|
6
|
+
function splitWhitespace(value) {
|
|
7
|
+
if (!value)
|
|
8
|
+
return [];
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
const array2 = value.map((i) => splitWhitespace(i));
|
|
11
|
+
return array2.flat(Number.POSITIVE_INFINITY);
|
|
12
|
+
}
|
|
13
|
+
value = value.trim().split(/\s/);
|
|
14
|
+
return array.trimArray(value);
|
|
15
|
+
}
|
|
16
|
+
function flush() {
|
|
17
|
+
return new Promise((resolve) => void setTimeout(resolve, 0));
|
|
18
|
+
}
|
|
19
|
+
function sleep(ms) {
|
|
20
|
+
return new Promise((resolve) => void setTimeout(resolve, ms));
|
|
21
|
+
}
|
|
5
22
|
function isEmpty(value) {
|
|
6
23
|
if (isNullish(value)) {
|
|
7
24
|
return true;
|
|
@@ -26,11 +43,17 @@ function toPixel(value) {
|
|
|
26
43
|
return value;
|
|
27
44
|
}
|
|
28
45
|
exports.regex = regex.regex;
|
|
29
|
-
exports.splitWhitespace = array.splitWhitespace;
|
|
30
46
|
exports.toArray = array.toArray;
|
|
31
47
|
exports.trimArray = array.trimArray;
|
|
32
48
|
exports.upsert = array.upsert;
|
|
49
|
+
exports.panic = panic.panic;
|
|
50
|
+
exports.todo = panic.todo;
|
|
51
|
+
exports.unimplemented = panic.unimplemented;
|
|
52
|
+
exports.unreachable = panic.unreachable;
|
|
53
|
+
exports.flush = flush;
|
|
33
54
|
exports.isEmpty = isEmpty;
|
|
34
55
|
exports.isNullish = isNullish;
|
|
35
56
|
exports.noop = noop;
|
|
57
|
+
exports.sleep = sleep;
|
|
58
|
+
exports.splitWhitespace = splitWhitespace;
|
|
36
59
|
exports.toPixel = toPixel;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from './array';
|
|
2
|
+
export * from './panic';
|
|
2
3
|
export * from './regex';
|
|
4
|
+
export * from './string';
|
|
5
|
+
export * from './promise';
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
7
|
+
* Checks if a value is empty.
|
|
5
8
|
*
|
|
6
9
|
* Arrays and strings are considered empty if they have a length of 0.
|
|
7
10
|
* Map and Sets are considered empty if they have a size of 0.
|
|
@@ -12,8 +15,5 @@ export * from './regex';
|
|
|
12
15
|
export declare function isEmpty(value?: unknown): boolean;
|
|
13
16
|
export declare function isNullish(value: unknown): value is null | undefined;
|
|
14
17
|
export declare const noop: () => void;
|
|
15
|
-
/**
|
|
16
|
-
* Add the pixel unit to a value.
|
|
17
|
-
* If the value is a string, it is returned unchanged.
|
|
18
|
-
*/
|
|
18
|
+
/** Adds the pixel unit to a value. */
|
|
19
19
|
export declare function toPixel(value: string | number): string;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { regex } from "./regex.js";
|
|
2
|
-
import {
|
|
2
|
+
import { trimArray } from "./array.js";
|
|
3
|
+
import { toArray, upsert } from "./array.js";
|
|
4
|
+
import { panic, todo, unimplemented, unreachable } from "./panic.js";
|
|
5
|
+
function splitWhitespace(value) {
|
|
6
|
+
if (!value)
|
|
7
|
+
return [];
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
const array = value.map((i) => splitWhitespace(i));
|
|
10
|
+
return array.flat(Number.POSITIVE_INFINITY);
|
|
11
|
+
}
|
|
12
|
+
value = value.trim().split(/\s/);
|
|
13
|
+
return trimArray(value);
|
|
14
|
+
}
|
|
15
|
+
function flush() {
|
|
16
|
+
return new Promise((resolve) => void setTimeout(resolve, 0));
|
|
17
|
+
}
|
|
18
|
+
function sleep(ms) {
|
|
19
|
+
return new Promise((resolve) => void setTimeout(resolve, ms));
|
|
20
|
+
}
|
|
3
21
|
function isEmpty(value) {
|
|
4
22
|
if (isNullish(value)) {
|
|
5
23
|
return true;
|
|
@@ -24,13 +42,19 @@ function toPixel(value) {
|
|
|
24
42
|
return value;
|
|
25
43
|
}
|
|
26
44
|
export {
|
|
45
|
+
flush,
|
|
27
46
|
isEmpty,
|
|
28
47
|
isNullish,
|
|
29
48
|
noop,
|
|
49
|
+
panic,
|
|
30
50
|
regex,
|
|
51
|
+
sleep,
|
|
31
52
|
splitWhitespace,
|
|
32
53
|
toArray,
|
|
33
54
|
toPixel,
|
|
55
|
+
todo,
|
|
34
56
|
trimArray,
|
|
57
|
+
unimplemented,
|
|
58
|
+
unreachable,
|
|
35
59
|
upsert
|
|
36
60
|
};
|
package/dist/panic.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function panic(message) {
|
|
4
|
+
throw new Error(message);
|
|
5
|
+
}
|
|
6
|
+
function todo(message = "not yet implemented") {
|
|
7
|
+
panic(message);
|
|
8
|
+
}
|
|
9
|
+
function unimplemented(message = "not implemented") {
|
|
10
|
+
panic(message);
|
|
11
|
+
}
|
|
12
|
+
function unreachable(message = "unreachable") {
|
|
13
|
+
panic(message);
|
|
14
|
+
}
|
|
15
|
+
exports.panic = panic;
|
|
16
|
+
exports.todo = todo;
|
|
17
|
+
exports.unimplemented = unimplemented;
|
|
18
|
+
exports.unreachable = unreachable;
|
package/dist/panic.d.ts
ADDED
package/dist/panic.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function panic(message) {
|
|
2
|
+
throw new Error(message);
|
|
3
|
+
}
|
|
4
|
+
function todo(message = "not yet implemented") {
|
|
5
|
+
panic(message);
|
|
6
|
+
}
|
|
7
|
+
function unimplemented(message = "not implemented") {
|
|
8
|
+
panic(message);
|
|
9
|
+
}
|
|
10
|
+
function unreachable(message = "unreachable") {
|
|
11
|
+
panic(message);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
panic,
|
|
15
|
+
todo,
|
|
16
|
+
unimplemented,
|
|
17
|
+
unreachable
|
|
18
|
+
};
|
package/dist/string.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tb-dev/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "TypeScript utils",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -30,18 +30,18 @@
|
|
|
30
30
|
"@tb-dev/utility-types": "^1.2.7"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@tb-dev/eslint-config": "^3.
|
|
34
|
-
"@types/node": "^20.12.
|
|
33
|
+
"@tb-dev/eslint-config": "^3.5.1",
|
|
34
|
+
"@types/node": "^20.12.11",
|
|
35
35
|
"eslint": "^8.57.0",
|
|
36
36
|
"husky": "^9.0.11",
|
|
37
37
|
"lint-staged": "^15.2.2",
|
|
38
38
|
"prettier": "^3.2.5",
|
|
39
39
|
"tslib": "^2.6.2",
|
|
40
40
|
"typedoc": "^0.25.13",
|
|
41
|
-
"typedoc-plugin-mdn-links": "^3.1.
|
|
41
|
+
"typedoc-plugin-mdn-links": "^3.1.24",
|
|
42
42
|
"typescript": "^5.4.5",
|
|
43
|
-
"vite": "^5.2.
|
|
44
|
-
"vite-plugin-dts": "^3.9.
|
|
43
|
+
"vite": "^5.2.11",
|
|
44
|
+
"vite-plugin-dts": "^3.9.1"
|
|
45
45
|
},
|
|
46
46
|
"files": [
|
|
47
47
|
"dist"
|
|
@@ -60,10 +60,25 @@
|
|
|
60
60
|
"import": "./dist/array.js",
|
|
61
61
|
"require": "./dist/array.cjs"
|
|
62
62
|
},
|
|
63
|
+
"./panic": {
|
|
64
|
+
"types": "./dist/panic.d.ts",
|
|
65
|
+
"import": "./dist/panic.js",
|
|
66
|
+
"require": "./dist/panic.cjs"
|
|
67
|
+
},
|
|
68
|
+
"./promise": {
|
|
69
|
+
"types": "./dist/promise.d.ts",
|
|
70
|
+
"import": "./dist/promise.js",
|
|
71
|
+
"require": "./dist/promise.cjs"
|
|
72
|
+
},
|
|
63
73
|
"./regex": {
|
|
64
74
|
"types": "./dist/regex.d.ts",
|
|
65
75
|
"import": "./dist/regex.js",
|
|
66
76
|
"require": "./dist/regex.cjs"
|
|
77
|
+
},
|
|
78
|
+
"./string": {
|
|
79
|
+
"types": "./dist/string.d.ts",
|
|
80
|
+
"import": "./dist/string.js",
|
|
81
|
+
"require": "./dist/string.cjs"
|
|
67
82
|
}
|
|
68
83
|
},
|
|
69
84
|
"scripts": {
|
|
@@ -72,6 +87,7 @@
|
|
|
72
87
|
"format": "prettier . --write",
|
|
73
88
|
"format-check": "prettier . --check",
|
|
74
89
|
"lint": "eslint . --config eslint.config.js --cache",
|
|
90
|
+
"lint-fix": "eslint . --config eslint.config.js --cache --fix",
|
|
75
91
|
"release": "pnpm run build && pnpm publish",
|
|
76
92
|
"type-check": "tsc --noEmit",
|
|
77
93
|
"update": "miho update major -t"
|