@tb-dev/utils 5.1.4 → 6.0.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 +1 -1
- package/dist/array/index.d.ts +3 -3
- package/dist/index.d.ts +6 -16
- package/dist/index.js +35 -41
- package/dist/nil/index.d.ts +1 -1
- package/dist/option/index.d.ts +1 -0
- package/dist/option/unwrap.d.ts +4 -0
- package/dist/promise/flush-promises.d.ts +1 -1
- package/dist/promise/index.d.ts +3 -3
- package/dist/string/index.d.ts +1 -1
- package/package.json +4 -3
- package/dist/regex.d.ts +0 -3
- /package/dist/{panic.d.ts → panic/index.d.ts} +0 -0
- /package/dist/{types.d.ts → types/index.d.ts} +0 -0
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025 Andrew Ferreira
|
|
3
|
+
Copyright (c) 2025 Andrew Ferreira <andrew.shien2@gmail.com>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/array/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export * from './to-array';
|
|
2
|
+
export * from './trim-array';
|
|
3
|
+
export * from './upsert';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
export * from './nil';
|
|
2
1
|
export * from './array';
|
|
2
|
+
export * from './function';
|
|
3
|
+
export * from './nil';
|
|
4
|
+
export * from './option';
|
|
3
5
|
export * from './panic';
|
|
4
|
-
export * from './regex';
|
|
5
|
-
export * from './types';
|
|
6
|
-
export * from './string';
|
|
7
6
|
export * from './promise';
|
|
8
|
-
export * from './
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* Arrays and strings are considered empty if they have a length of 0.
|
|
13
|
-
* Map and Sets are considered empty if they have a size of 0.
|
|
14
|
-
*
|
|
15
|
-
* This function does not check for empty objects.
|
|
16
|
-
* Any other value is considered empty only if it is nullish.
|
|
17
|
-
*/
|
|
18
|
-
export declare function isEmpty(value?: unknown): boolean;
|
|
19
|
-
/** Adds the pixel unit to a value. */
|
|
7
|
+
export * from './string';
|
|
8
|
+
export type * from './types';
|
|
9
|
+
/** Adds the pixel unit to a value if it is a number. */
|
|
20
10
|
export declare function toPixel(value: string | number): string;
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
function
|
|
9
|
-
|
|
4
|
+
function toArray(item) {
|
|
5
|
+
const array = item ?? [];
|
|
6
|
+
return Array.isArray(array) ? array : [array];
|
|
7
|
+
}
|
|
8
|
+
function trimArray(array, options = {}) {
|
|
9
|
+
const _array = array.map((it) => it.trim());
|
|
10
|
+
return options.allowEmpty ? _array : _array.filter(Boolean);
|
|
10
11
|
}
|
|
11
|
-
const isNullish = isNil;
|
|
12
12
|
function upsert(array, item, predicate) {
|
|
13
13
|
const index = array.findIndex(predicate ?? ((value) => value === item));
|
|
14
14
|
if (index === -1) {
|
|
@@ -17,14 +17,12 @@ function upsert(array, item, predicate) {
|
|
|
17
17
|
array[index] = item;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function trimArray(array, options = {}) {
|
|
25
|
-
const _array = array.map((it) => it.trim());
|
|
26
|
-
return options.allowEmpty ? _array : _array.filter(Boolean);
|
|
20
|
+
const noop = () => {
|
|
21
|
+
};
|
|
22
|
+
function isNil(value) {
|
|
23
|
+
return value === void 0 || value === null;
|
|
27
24
|
}
|
|
25
|
+
const isNullish = isNil;
|
|
28
26
|
function panic(...args) {
|
|
29
27
|
throw new Error(args.join(" "));
|
|
30
28
|
}
|
|
@@ -44,17 +42,14 @@ function format(base, args) {
|
|
|
44
42
|
}
|
|
45
43
|
return message;
|
|
46
44
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
if (Array.isArray(value)) {
|
|
50
|
-
const array = value.map((it) => splitWhitespace(it, options));
|
|
51
|
-
return array.flat(Number.POSITIVE_INFINITY);
|
|
52
|
-
}
|
|
53
|
-
value = value.trim().split(/\s/);
|
|
54
|
-
return trimArray(value, options);
|
|
45
|
+
function unwrap(value, message = "`unwrap` called with a nil value") {
|
|
46
|
+
return isNil(value) ? panic(message) : value;
|
|
55
47
|
}
|
|
56
|
-
function
|
|
57
|
-
return
|
|
48
|
+
function unwrapOr(value, other) {
|
|
49
|
+
return isNil(value) ? other : value;
|
|
50
|
+
}
|
|
51
|
+
function unwrapOrElse(value, fn) {
|
|
52
|
+
return isNil(value) ? fn() : value;
|
|
58
53
|
}
|
|
59
54
|
function flushPromises() {
|
|
60
55
|
return new Promise((resolve) => void setTimeout(resolve, 0));
|
|
@@ -83,35 +78,31 @@ class PromiseSet {
|
|
|
83
78
|
return set;
|
|
84
79
|
}
|
|
85
80
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return value
|
|
81
|
+
function sleep(ms) {
|
|
82
|
+
return new Promise((resolve) => void setTimeout(resolve, ms));
|
|
83
|
+
}
|
|
84
|
+
function splitWhitespace(value, options = {}) {
|
|
85
|
+
if (value) {
|
|
86
|
+
if (Array.isArray(value)) {
|
|
87
|
+
const array = value.map((it) => splitWhitespace(it, options));
|
|
88
|
+
return array.flat(Number.POSITIVE_INFINITY);
|
|
89
|
+
}
|
|
90
|
+
value = value.trim().split(/\s/);
|
|
91
|
+
return trimArray(value, options);
|
|
97
92
|
}
|
|
98
|
-
return
|
|
93
|
+
return [];
|
|
99
94
|
}
|
|
100
95
|
function toPixel(value) {
|
|
101
|
-
if (typeof value === "number"
|
|
102
|
-
return `${value}px`;
|
|
103
|
-
}
|
|
96
|
+
if (typeof value === "number") return `${value}px`;
|
|
104
97
|
return value;
|
|
105
98
|
}
|
|
106
99
|
export {
|
|
107
100
|
PromiseSet,
|
|
108
101
|
flushPromises,
|
|
109
|
-
isEmpty,
|
|
110
102
|
isNil,
|
|
111
103
|
isNullish,
|
|
112
104
|
noop,
|
|
113
105
|
panic,
|
|
114
|
-
regex,
|
|
115
106
|
sleep,
|
|
116
107
|
splitWhitespace,
|
|
117
108
|
toArray,
|
|
@@ -120,5 +111,8 @@ export {
|
|
|
120
111
|
trimArray,
|
|
121
112
|
unimplemented,
|
|
122
113
|
unreachable,
|
|
114
|
+
unwrap,
|
|
115
|
+
unwrapOr,
|
|
116
|
+
unwrapOrElse,
|
|
123
117
|
upsert
|
|
124
118
|
};
|
package/dist/nil/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './is-nil';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './unwrap';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/** Flushes
|
|
1
|
+
/** Flushes pending promises. */
|
|
2
2
|
export declare function flushPromises(): Promise<void>;
|
package/dist/promise/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export * from './flush-promises';
|
|
2
|
+
export * from './promise-set';
|
|
3
|
+
export * from './sleep';
|
package/dist/string/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './split-whitespace';
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tb-dev/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "TypeScript utils",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"private": false,
|
|
8
|
+
"funding": "https://github.com/sponsors/ferreira-tb",
|
|
8
9
|
"homepage": "https://tb.dev.br/utils/",
|
|
9
10
|
"author": {
|
|
10
11
|
"name": "Andrew Ferreira",
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
],
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@tb-dev/eslint-config": "^6.7.1",
|
|
27
|
-
"@types/node": "^22.13.
|
|
28
|
+
"@types/node": "^22.13.14",
|
|
28
29
|
"@vitest/ui": "^3.0.9",
|
|
29
30
|
"eslint": "^9.23.0",
|
|
30
31
|
"prettier": "^3.5.3",
|
|
@@ -32,7 +33,7 @@
|
|
|
32
33
|
"typedoc": "^0.28.1",
|
|
33
34
|
"typedoc-plugin-mdn-links": "^5.0.1",
|
|
34
35
|
"typescript": "^5.8.2",
|
|
35
|
-
"vite": "^6.2.
|
|
36
|
+
"vite": "^6.2.3",
|
|
36
37
|
"vite-plugin-dts": "^4.5.3",
|
|
37
38
|
"vitest": "^3.0.9"
|
|
38
39
|
},
|
package/dist/regex.d.ts
DELETED
|
File without changes
|
|
File without changes
|