@tb-dev/utils 3.0.2 → 3.1.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 +12 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -3
- package/dist/nil/index.d.ts +1 -0
- package/dist/nil/is-nil.d.ts +2 -0
- package/dist/promise/promise-set.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -7,6 +7,10 @@ const float = /^\d+(?:\.(\d+))?$/;
|
|
|
7
7
|
const regex = {
|
|
8
8
|
float
|
|
9
9
|
};
|
|
10
|
+
function isNil(value) {
|
|
11
|
+
return value === void 0 || value === null;
|
|
12
|
+
}
|
|
13
|
+
const isNullish = isNil;
|
|
10
14
|
function upsert(array, item, predicate) {
|
|
11
15
|
const index = array.findIndex(predicate ?? ((it) => it === item));
|
|
12
16
|
if (index === -1) {
|
|
@@ -65,6 +69,13 @@ class PromiseSet {
|
|
|
65
69
|
await Promise.all(this.promises);
|
|
66
70
|
this.promises.clear();
|
|
67
71
|
}
|
|
72
|
+
static from(promises) {
|
|
73
|
+
const set = new PromiseSet();
|
|
74
|
+
for (const promise of promises) {
|
|
75
|
+
set.promises.add(promise);
|
|
76
|
+
}
|
|
77
|
+
return set;
|
|
78
|
+
}
|
|
68
79
|
}
|
|
69
80
|
function flushPromises() {
|
|
70
81
|
return new Promise((resolve) => void setTimeout(resolve, 0));
|
|
@@ -81,9 +92,6 @@ function isEmpty(value) {
|
|
|
81
92
|
}
|
|
82
93
|
return false;
|
|
83
94
|
}
|
|
84
|
-
function isNullish(value) {
|
|
85
|
-
return value === void 0 || value === null;
|
|
86
|
-
}
|
|
87
95
|
const noop = () => {
|
|
88
96
|
};
|
|
89
97
|
function toPixel(value) {
|
|
@@ -95,6 +103,7 @@ function toPixel(value) {
|
|
|
95
103
|
exports.PromiseSet = PromiseSet;
|
|
96
104
|
exports.flushPromises = flushPromises;
|
|
97
105
|
exports.isEmpty = isEmpty;
|
|
106
|
+
exports.isNil = isNil;
|
|
98
107
|
exports.isNullish = isNullish;
|
|
99
108
|
exports.noop = noop;
|
|
100
109
|
exports.panic = panic;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './nil';
|
|
1
2
|
export * from './array';
|
|
2
3
|
export * from './panic';
|
|
3
4
|
export * from './regex';
|
|
@@ -14,7 +15,6 @@ export * from './promise';
|
|
|
14
15
|
* Any other value is considered empty only if it is nullish.
|
|
15
16
|
*/
|
|
16
17
|
export declare function isEmpty(value?: unknown): boolean;
|
|
17
|
-
export declare function isNullish(value: unknown): value is null | undefined;
|
|
18
18
|
export declare const noop: () => void;
|
|
19
19
|
/** Adds the pixel unit to a value. */
|
|
20
20
|
export declare function toPixel(value: string | number): string;
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,10 @@ const float = /^\d+(?:\.(\d+))?$/;
|
|
|
5
5
|
const regex = {
|
|
6
6
|
float
|
|
7
7
|
};
|
|
8
|
+
function isNil(value) {
|
|
9
|
+
return value === void 0 || value === null;
|
|
10
|
+
}
|
|
11
|
+
const isNullish = isNil;
|
|
8
12
|
function upsert(array, item, predicate) {
|
|
9
13
|
const index = array.findIndex(predicate ?? ((it) => it === item));
|
|
10
14
|
if (index === -1) {
|
|
@@ -63,6 +67,13 @@ class PromiseSet {
|
|
|
63
67
|
await Promise.all(this.promises);
|
|
64
68
|
this.promises.clear();
|
|
65
69
|
}
|
|
70
|
+
static from(promises) {
|
|
71
|
+
const set = new PromiseSet();
|
|
72
|
+
for (const promise of promises) {
|
|
73
|
+
set.promises.add(promise);
|
|
74
|
+
}
|
|
75
|
+
return set;
|
|
76
|
+
}
|
|
66
77
|
}
|
|
67
78
|
function flushPromises() {
|
|
68
79
|
return new Promise((resolve) => void setTimeout(resolve, 0));
|
|
@@ -79,9 +90,6 @@ function isEmpty(value) {
|
|
|
79
90
|
}
|
|
80
91
|
return false;
|
|
81
92
|
}
|
|
82
|
-
function isNullish(value) {
|
|
83
|
-
return value === void 0 || value === null;
|
|
84
|
-
}
|
|
85
93
|
const noop = () => {
|
|
86
94
|
};
|
|
87
95
|
function toPixel(value) {
|
|
@@ -94,6 +102,7 @@ export {
|
|
|
94
102
|
PromiseSet,
|
|
95
103
|
flushPromises,
|
|
96
104
|
isEmpty,
|
|
105
|
+
isNil,
|
|
97
106
|
isNullish,
|
|
98
107
|
noop,
|
|
99
108
|
panic,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { isNil, isNullish } from './is-nil';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tb-dev/utils",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "TypeScript utils",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@tb-dev/eslint-config": "^5.2.0",
|
|
30
|
-
"@types/node": "^22.
|
|
30
|
+
"@types/node": "^22.3.0",
|
|
31
31
|
"@vitest/ui": "^2.0.5",
|
|
32
32
|
"eslint": "^9.9.0",
|
|
33
33
|
"husky": "^9.1.4",
|
|
34
|
-
"lint-staged": "^15.2.
|
|
34
|
+
"lint-staged": "^15.2.9",
|
|
35
35
|
"prettier": "^3.3.3",
|
|
36
36
|
"tslib": "^2.6.3",
|
|
37
37
|
"typedoc": "^0.26.5",
|