@tb-dev/utils 1.4.1 → 1.4.3
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 -1
- package/dist/array.d.ts +3 -2
- package/dist/array.js +0 -1
- package/dist/index.cjs +13 -5
- package/dist/index.d.ts +10 -1
- package/dist/index.js +14 -6
- package/package.json +4 -4
package/dist/array.cjs
CHANGED
package/dist/array.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { MaybeArray, Nullish } from '@tb-dev/utility-types';
|
|
2
|
+
|
|
3
|
+
export declare function upsert<T>(array: T[], item: T, predicate: (item: T) => boolean): void;
|
|
3
4
|
export declare function splitWhitespace(value: Nullish<string | string[]>): string[];
|
|
4
5
|
export declare function toArray<T>(item?: Nullish<MaybeArray<T>>): T[];
|
|
5
6
|
export declare function trimArray(array: string[]): string[];
|
package/dist/array.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const regex = require("./regex.cjs");
|
|
4
|
-
|
|
4
|
+
function isEmpty(value) {
|
|
5
|
+
if (isNullish(value)) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
if (Array.isArray(value) || typeof value === "string") {
|
|
9
|
+
return value.length === 0;
|
|
10
|
+
}
|
|
11
|
+
if (value instanceof Map || value instanceof Set) {
|
|
12
|
+
return value.size === 0;
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
5
16
|
function isNullish(value) {
|
|
6
17
|
return value === null || value === void 0;
|
|
7
18
|
}
|
|
@@ -11,9 +22,6 @@ function toPixel(value) {
|
|
|
11
22
|
}
|
|
12
23
|
return value;
|
|
13
24
|
}
|
|
14
|
-
exports.
|
|
15
|
-
exports.toArray = array.toArray;
|
|
16
|
-
exports.trimArray = array.trimArray;
|
|
17
|
-
exports.upsert = array.upsert;
|
|
25
|
+
exports.isEmpty = isEmpty;
|
|
18
26
|
exports.isNullish = isNullish;
|
|
19
27
|
exports.toPixel = toPixel;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Check if a value is empty.
|
|
3
|
+
*
|
|
4
|
+
* Arrays and strings are considered empty if they have a length of 0.
|
|
5
|
+
* Map and Sets are considered empty if they have a size of 0.
|
|
6
|
+
*
|
|
7
|
+
* This function does not check for empty objects.
|
|
8
|
+
* Any other value is considered empty only if it is nullish.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isEmpty(value?: unknown): boolean;
|
|
2
11
|
export declare function isNullish(value: unknown): value is null | undefined;
|
|
3
12
|
/**
|
|
4
13
|
* Add the pixel unit to a value.
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { float } from "./regex.js";
|
|
2
|
-
|
|
2
|
+
function isEmpty(value) {
|
|
3
|
+
if (isNullish(value)) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
if (Array.isArray(value) || typeof value === "string") {
|
|
7
|
+
return value.length === 0;
|
|
8
|
+
}
|
|
9
|
+
if (value instanceof Map || value instanceof Set) {
|
|
10
|
+
return value.size === 0;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
3
14
|
function isNullish(value) {
|
|
4
15
|
return value === null || value === void 0;
|
|
5
16
|
}
|
|
@@ -10,10 +21,7 @@ function toPixel(value) {
|
|
|
10
21
|
return value;
|
|
11
22
|
}
|
|
12
23
|
export {
|
|
24
|
+
isEmpty,
|
|
13
25
|
isNullish,
|
|
14
|
-
|
|
15
|
-
toArray,
|
|
16
|
-
toPixel,
|
|
17
|
-
trimArray,
|
|
18
|
-
upsert
|
|
26
|
+
toPixel
|
|
19
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tb-dev/utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "TypeScript utils",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@tb-dev/utility-types": "^1.2.4"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tb-dev/eslint-config": "^3.3.
|
|
34
|
+
"@tb-dev/eslint-config": "^3.3.1",
|
|
35
35
|
"@types/node": "^20.11.30",
|
|
36
36
|
"eslint": "^8.57.0",
|
|
37
37
|
"husky": "^9.0.11",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"typedoc": "^0.25.12",
|
|
42
42
|
"typedoc-plugin-mdn-links": "^3.1.18",
|
|
43
43
|
"typescript": "^5.4.3",
|
|
44
|
-
"vite": "^5.2.
|
|
45
|
-
"vite-plugin-dts": "^3.
|
|
44
|
+
"vite": "^5.2.7",
|
|
45
|
+
"vite-plugin-dts": "^3.8.1"
|
|
46
46
|
},
|
|
47
47
|
"files": [
|
|
48
48
|
"dist"
|