@tb-dev/utils 3.3.2 → 4.0.1
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/function/index.d.ts +1 -0
- package/dist/function/noop.d.ts +1 -0
- package/dist/index.cjs +11 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -7
- package/dist/nil/is-nil.d.ts +2 -1
- package/dist/promise/promise-set.d.ts +2 -1
- package/dist/types.d.ts +3 -1
- package/package.json +11 -16
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './noop';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const noop: () => void;
|
package/dist/index.cjs
CHANGED
|
@@ -12,7 +12,7 @@ function isNil(value) {
|
|
|
12
12
|
}
|
|
13
13
|
const isNullish = isNil;
|
|
14
14
|
function upsert(array, item, predicate) {
|
|
15
|
-
const index = array.findIndex(predicate ?? ((
|
|
15
|
+
const index = array.findIndex(predicate ?? ((value) => value === item));
|
|
16
16
|
if (index === -1) {
|
|
17
17
|
array.push(item);
|
|
18
18
|
} else {
|
|
@@ -58,11 +58,14 @@ function splitWhitespace(value, options = {}) {
|
|
|
58
58
|
function sleep(ms) {
|
|
59
59
|
return new Promise((resolve) => void setTimeout(resolve, ms));
|
|
60
60
|
}
|
|
61
|
+
function flushPromises() {
|
|
62
|
+
return new Promise((resolve) => void setTimeout(resolve, 0));
|
|
63
|
+
}
|
|
61
64
|
class PromiseSet {
|
|
62
65
|
constructor() {
|
|
63
66
|
__publicField(this, "promises", /* @__PURE__ */ new Set());
|
|
64
67
|
}
|
|
65
|
-
|
|
68
|
+
chain(promise) {
|
|
66
69
|
this.promises.add(promise);
|
|
67
70
|
return this;
|
|
68
71
|
}
|
|
@@ -70,6 +73,10 @@ class PromiseSet {
|
|
|
70
73
|
await Promise.all(this.promises);
|
|
71
74
|
this.promises.clear();
|
|
72
75
|
}
|
|
76
|
+
async joinFlushed() {
|
|
77
|
+
await this.join();
|
|
78
|
+
await flushPromises();
|
|
79
|
+
}
|
|
73
80
|
static from(promises) {
|
|
74
81
|
const set = new PromiseSet();
|
|
75
82
|
for (const promise of promises) {
|
|
@@ -78,9 +85,8 @@ class PromiseSet {
|
|
|
78
85
|
return set;
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
88
|
+
const noop = () => {
|
|
89
|
+
};
|
|
84
90
|
function isEmpty(value) {
|
|
85
91
|
if (isNullish(value)) {
|
|
86
92
|
return true;
|
|
@@ -93,8 +99,6 @@ function isEmpty(value) {
|
|
|
93
99
|
}
|
|
94
100
|
return false;
|
|
95
101
|
}
|
|
96
|
-
const noop = () => {
|
|
97
|
-
};
|
|
98
102
|
function toPixel(value) {
|
|
99
103
|
if (typeof value === "number" || typeof value === "string" && regex.float.test(value)) {
|
|
100
104
|
return `${value}px`;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './regex';
|
|
|
5
5
|
export * from './types';
|
|
6
6
|
export * from './string';
|
|
7
7
|
export * from './promise';
|
|
8
|
+
export * from './function';
|
|
8
9
|
/**
|
|
9
10
|
* Checks if a value is empty.
|
|
10
11
|
*
|
|
@@ -15,6 +16,5 @@ export * from './promise';
|
|
|
15
16
|
* Any other value is considered empty only if it is nullish.
|
|
16
17
|
*/
|
|
17
18
|
export declare function isEmpty(value?: unknown): boolean;
|
|
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
|
@@ -10,7 +10,7 @@ function isNil(value) {
|
|
|
10
10
|
}
|
|
11
11
|
const isNullish = isNil;
|
|
12
12
|
function upsert(array, item, predicate) {
|
|
13
|
-
const index = array.findIndex(predicate ?? ((
|
|
13
|
+
const index = array.findIndex(predicate ?? ((value) => value === item));
|
|
14
14
|
if (index === -1) {
|
|
15
15
|
array.push(item);
|
|
16
16
|
} else {
|
|
@@ -56,11 +56,14 @@ function splitWhitespace(value, options = {}) {
|
|
|
56
56
|
function sleep(ms) {
|
|
57
57
|
return new Promise((resolve) => void setTimeout(resolve, ms));
|
|
58
58
|
}
|
|
59
|
+
function flushPromises() {
|
|
60
|
+
return new Promise((resolve) => void setTimeout(resolve, 0));
|
|
61
|
+
}
|
|
59
62
|
class PromiseSet {
|
|
60
63
|
constructor() {
|
|
61
64
|
__publicField(this, "promises", /* @__PURE__ */ new Set());
|
|
62
65
|
}
|
|
63
|
-
|
|
66
|
+
chain(promise) {
|
|
64
67
|
this.promises.add(promise);
|
|
65
68
|
return this;
|
|
66
69
|
}
|
|
@@ -68,6 +71,10 @@ class PromiseSet {
|
|
|
68
71
|
await Promise.all(this.promises);
|
|
69
72
|
this.promises.clear();
|
|
70
73
|
}
|
|
74
|
+
async joinFlushed() {
|
|
75
|
+
await this.join();
|
|
76
|
+
await flushPromises();
|
|
77
|
+
}
|
|
71
78
|
static from(promises) {
|
|
72
79
|
const set = new PromiseSet();
|
|
73
80
|
for (const promise of promises) {
|
|
@@ -76,9 +83,8 @@ class PromiseSet {
|
|
|
76
83
|
return set;
|
|
77
84
|
}
|
|
78
85
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
86
|
+
const noop = () => {
|
|
87
|
+
};
|
|
82
88
|
function isEmpty(value) {
|
|
83
89
|
if (isNullish(value)) {
|
|
84
90
|
return true;
|
|
@@ -91,8 +97,6 @@ function isEmpty(value) {
|
|
|
91
97
|
}
|
|
92
98
|
return false;
|
|
93
99
|
}
|
|
94
|
-
const noop = () => {
|
|
95
|
-
};
|
|
96
100
|
function toPixel(value) {
|
|
97
101
|
if (typeof value === "number" || typeof value === "string" && regex.float.test(value)) {
|
|
98
102
|
return `${value}px`;
|
package/dist/nil/is-nil.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -9,8 +9,10 @@ export type MaybeArrayOrSet<T> = MaybeArray<T> | MaybeSet<T>;
|
|
|
9
9
|
export type MaybePromise<T> = T | PromiseLike<T>;
|
|
10
10
|
/** Something may be a Set. */
|
|
11
11
|
export type MaybeSet<T> = T | Set<T>;
|
|
12
|
+
/** Null or undefined. */
|
|
13
|
+
export type Nil = null | undefined;
|
|
12
14
|
/** Something may be nullish. */
|
|
13
|
-
export type Nullish<T> = T |
|
|
15
|
+
export type Nullish<T> = T | Nil;
|
|
14
16
|
/** Constructs a type where all properties of `T` may be null. */
|
|
15
17
|
export type PartialNull<T> = {
|
|
16
18
|
[P in keyof T]: T[P] | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tb-dev/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "TypeScript utils",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,24 +22,19 @@
|
|
|
22
22
|
"utils",
|
|
23
23
|
"typescript"
|
|
24
24
|
],
|
|
25
|
-
"lint-staged": {
|
|
26
|
-
"*.{?(c|m)@(j|t)s,css,vue,md,json}": "prettier --write"
|
|
27
|
-
},
|
|
28
25
|
"devDependencies": {
|
|
29
|
-
"@tb-dev/eslint-config": "^5.
|
|
30
|
-
"@types/node": "^22.7.
|
|
31
|
-
"@vitest/ui": "^2.1.
|
|
32
|
-
"eslint": "^9.
|
|
33
|
-
"husky": "^9.1.6",
|
|
34
|
-
"lint-staged": "^15.2.10",
|
|
26
|
+
"@tb-dev/eslint-config": "^5.4.2",
|
|
27
|
+
"@types/node": "^22.7.5",
|
|
28
|
+
"@vitest/ui": "^2.1.2",
|
|
29
|
+
"eslint": "^9.12.0",
|
|
35
30
|
"prettier": "^3.3.3",
|
|
36
31
|
"tslib": "^2.7.0",
|
|
37
|
-
"typedoc": "^0.26.
|
|
38
|
-
"typedoc-plugin-mdn-links": "^3.3.
|
|
39
|
-
"typescript": "^5.6.
|
|
32
|
+
"typedoc": "^0.26.9",
|
|
33
|
+
"typedoc-plugin-mdn-links": "^3.3.3",
|
|
34
|
+
"typescript": "^5.6.3",
|
|
40
35
|
"vite": "^5.4.8",
|
|
41
|
-
"vite-plugin-dts": "^4.2.
|
|
42
|
-
"vitest": "^2.1.
|
|
36
|
+
"vite-plugin-dts": "^4.2.4",
|
|
37
|
+
"vitest": "^2.1.2"
|
|
43
38
|
},
|
|
44
39
|
"files": [
|
|
45
40
|
"dist"
|
|
@@ -61,7 +56,7 @@
|
|
|
61
56
|
"format-check": "prettier . --check",
|
|
62
57
|
"lint": "eslint . --config eslint.config.js --cache",
|
|
63
58
|
"lint-fix": "eslint . --config eslint.config.js --fix",
|
|
64
|
-
"release": "pnpm run build && pnpm publish",
|
|
59
|
+
"release": "pnpm run test && pnpm run build && pnpm publish",
|
|
65
60
|
"test": "vitest",
|
|
66
61
|
"test:ui": "vitest --ui --watch",
|
|
67
62
|
"type-check": "tsc --noEmit",
|