@tb-dev/utils 1.4.2 → 1.4.4

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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { MaybeArray, Nullish } from '@tb-dev/utility-types';
1
+ import { MaybeArray, Nullish } from '@tb-dev/utility-types';
2
+
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[];
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
- const array = require("./array.cjs");
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.splitWhitespace = array.splitWhitespace;
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
- export { splitWhitespace, toArray, trimArray, upsert } from './array';
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
- import { splitWhitespace, toArray, trimArray, upsert } from "./array.js";
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
- splitWhitespace,
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.2",
3
+ "version": "1.4.4",
4
4
  "description": "TypeScript utils",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -28,21 +28,21 @@
28
28
  "*.{?(c|m)@(j|t)s,vue}": "pnpm run lint"
29
29
  },
30
30
  "dependencies": {
31
- "@tb-dev/utility-types": "^1.2.4"
31
+ "@tb-dev/utility-types": "^1.2.5"
32
32
  },
33
33
  "devDependencies": {
34
- "@tb-dev/eslint-config": "^3.3.0",
35
- "@types/node": "^20.11.30",
34
+ "@tb-dev/eslint-config": "^3.3.2",
35
+ "@types/node": "^20.12.3",
36
36
  "eslint": "^8.57.0",
37
37
  "husky": "^9.0.11",
38
38
  "lint-staged": "^15.2.2",
39
39
  "prettier": "^3.2.5",
40
40
  "tslib": "^2.6.2",
41
41
  "typedoc": "^0.25.12",
42
- "typedoc-plugin-mdn-links": "^3.1.18",
42
+ "typedoc-plugin-mdn-links": "^3.1.19",
43
43
  "typescript": "^5.4.3",
44
- "vite": "^5.2.6",
45
- "vite-plugin-dts": "^3.7.3"
44
+ "vite": "^5.2.8",
45
+ "vite-plugin-dts": "^3.8.1"
46
46
  },
47
47
  "files": [
48
48
  "dist"