@tb-dev/utils 3.2.1 → 3.3.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/index.d.ts +1 -1
- package/dist/array/trim-array.d.ts +8 -1
- package/dist/index.cjs +7 -6
- package/dist/index.js +7 -6
- package/dist/string/index.d.ts +1 -1
- package/dist/string/split-whitespace.d.ts +3 -1
- package/dist/types.d.ts +1 -0
- package/package.json +12 -12
package/dist/array/index.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
export interface TrimArrayOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Whether to allow empty strings.
|
|
4
|
+
* @default false
|
|
5
|
+
*/
|
|
6
|
+
allowEmpty?: boolean;
|
|
7
|
+
}
|
|
1
8
|
/** Trims each string in the array, removing any empty strings. */
|
|
2
|
-
export declare function trimArray(array: string[]): string[];
|
|
9
|
+
export declare function trimArray(array: string[], options?: TrimArrayOptions): string[];
|
package/dist/index.cjs
CHANGED
|
@@ -23,14 +23,15 @@ function toArray(item) {
|
|
|
23
23
|
const array = item ?? [];
|
|
24
24
|
return Array.isArray(array) ? array : [array];
|
|
25
25
|
}
|
|
26
|
-
function trimArray(array) {
|
|
27
|
-
|
|
26
|
+
function trimArray(array, options = {}) {
|
|
27
|
+
const _array = array.map((it) => it.trim());
|
|
28
|
+
return options.allowEmpty ? _array : _array.filter(Boolean);
|
|
28
29
|
}
|
|
29
30
|
function panic(...args) {
|
|
30
31
|
throw new Error(args.join(" "));
|
|
31
32
|
}
|
|
32
33
|
function todo(...args) {
|
|
33
|
-
panic(format("
|
|
34
|
+
panic(format("not yet implemented", args));
|
|
34
35
|
}
|
|
35
36
|
function unimplemented(...args) {
|
|
36
37
|
panic(format("not implemented", args));
|
|
@@ -45,14 +46,14 @@ function format(base, args) {
|
|
|
45
46
|
}
|
|
46
47
|
return message;
|
|
47
48
|
}
|
|
48
|
-
function splitWhitespace(value) {
|
|
49
|
+
function splitWhitespace(value, options = {}) {
|
|
49
50
|
if (!value) return [];
|
|
50
51
|
if (Array.isArray(value)) {
|
|
51
|
-
const array = value.map((it) => splitWhitespace(it));
|
|
52
|
+
const array = value.map((it) => splitWhitespace(it, options));
|
|
52
53
|
return array.flat(Number.POSITIVE_INFINITY);
|
|
53
54
|
}
|
|
54
55
|
value = value.trim().split(/\s/);
|
|
55
|
-
return trimArray(value);
|
|
56
|
+
return trimArray(value, options);
|
|
56
57
|
}
|
|
57
58
|
function sleep(ms) {
|
|
58
59
|
return new Promise((resolve) => void setTimeout(resolve, ms));
|
package/dist/index.js
CHANGED
|
@@ -21,14 +21,15 @@ function toArray(item) {
|
|
|
21
21
|
const array = item ?? [];
|
|
22
22
|
return Array.isArray(array) ? array : [array];
|
|
23
23
|
}
|
|
24
|
-
function trimArray(array) {
|
|
25
|
-
|
|
24
|
+
function trimArray(array, options = {}) {
|
|
25
|
+
const _array = array.map((it) => it.trim());
|
|
26
|
+
return options.allowEmpty ? _array : _array.filter(Boolean);
|
|
26
27
|
}
|
|
27
28
|
function panic(...args) {
|
|
28
29
|
throw new Error(args.join(" "));
|
|
29
30
|
}
|
|
30
31
|
function todo(...args) {
|
|
31
|
-
panic(format("
|
|
32
|
+
panic(format("not yet implemented", args));
|
|
32
33
|
}
|
|
33
34
|
function unimplemented(...args) {
|
|
34
35
|
panic(format("not implemented", args));
|
|
@@ -43,14 +44,14 @@ function format(base, args) {
|
|
|
43
44
|
}
|
|
44
45
|
return message;
|
|
45
46
|
}
|
|
46
|
-
function splitWhitespace(value) {
|
|
47
|
+
function splitWhitespace(value, options = {}) {
|
|
47
48
|
if (!value) return [];
|
|
48
49
|
if (Array.isArray(value)) {
|
|
49
|
-
const array = value.map((it) => splitWhitespace(it));
|
|
50
|
+
const array = value.map((it) => splitWhitespace(it, options));
|
|
50
51
|
return array.flat(Number.POSITIVE_INFINITY);
|
|
51
52
|
}
|
|
52
53
|
value = value.trim().split(/\s/);
|
|
53
|
-
return trimArray(value);
|
|
54
|
+
return trimArray(value, options);
|
|
54
55
|
}
|
|
55
56
|
function sleep(ms) {
|
|
56
57
|
return new Promise((resolve) => void setTimeout(resolve, ms));
|
package/dist/string/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { splitWhitespace } from './split-whitespace';
|
|
1
|
+
export { splitWhitespace, type SplitWhitespaceOptions } from './split-whitespace';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Nullish } from '../types';
|
|
2
|
+
import { TrimArrayOptions } from '../array/trim-array';
|
|
3
|
+
export type SplitWhitespaceOptions = TrimArrayOptions;
|
|
2
4
|
/**
|
|
3
5
|
* Splits a string or an array of strings (recursively) by whitespace.
|
|
4
6
|
*
|
|
@@ -9,4 +11,4 @@ import { Nullish } from '../types';
|
|
|
9
11
|
* splitWhitespace(['a ', ['b', ['c d']]]); // ['a', 'b', 'c', 'd']
|
|
10
12
|
* ```
|
|
11
13
|
*/
|
|
12
|
-
export declare function splitWhitespace(value: Nullish<string | string[]
|
|
14
|
+
export declare function splitWhitespace(value: Nullish<string | string[]>, options?: SplitWhitespaceOptions): string[];
|
package/dist/types.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export type PickByValue<T, V> = {
|
|
|
27
27
|
export type PickPartial<T, K extends keyof T> = Pick<Partial<T>, K>;
|
|
28
28
|
/** Constructs a type by picking the set of properties `K` from a required version of `T`. */
|
|
29
29
|
export type PickRequired<T, K extends keyof T> = Pick<Required<T>, K>;
|
|
30
|
+
/** Removes the readonly modifier from all properties of T. */
|
|
30
31
|
export type Writeable<T> = {
|
|
31
32
|
-readonly [P in keyof T]: T[P];
|
|
32
33
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tb-dev/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "TypeScript utils",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,20 +26,20 @@
|
|
|
26
26
|
"*.{?(c|m)@(j|t)s,css,vue,md,json}": "prettier --write"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@tb-dev/eslint-config": "^5.
|
|
30
|
-
"@types/node": "^22.5.
|
|
31
|
-
"@vitest/ui": "^2.
|
|
32
|
-
"eslint": "^9.
|
|
33
|
-
"husky": "^9.1.
|
|
29
|
+
"@tb-dev/eslint-config": "^5.3.2",
|
|
30
|
+
"@types/node": "^22.5.4",
|
|
31
|
+
"@vitest/ui": "^2.1.1",
|
|
32
|
+
"eslint": "^9.10.0",
|
|
33
|
+
"husky": "^9.1.6",
|
|
34
34
|
"lint-staged": "^15.2.10",
|
|
35
35
|
"prettier": "^3.3.3",
|
|
36
36
|
"tslib": "^2.7.0",
|
|
37
|
-
"typedoc": "^0.26.
|
|
38
|
-
"typedoc-plugin-mdn-links": "^3.2.
|
|
39
|
-
"typescript": "^5.
|
|
40
|
-
"vite": "^5.4.
|
|
41
|
-
"vite-plugin-dts": "^4.1
|
|
42
|
-
"vitest": "^2.
|
|
37
|
+
"typedoc": "^0.26.7",
|
|
38
|
+
"typedoc-plugin-mdn-links": "^3.2.12",
|
|
39
|
+
"typescript": "^5.6.2",
|
|
40
|
+
"vite": "^5.4.5",
|
|
41
|
+
"vite-plugin-dts": "^4.2.1",
|
|
42
|
+
"vitest": "^2.1.1"
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
45
|
"dist"
|