@takeshape/util 11.49.0 → 11.50.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.
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDeepEmpty = void 0;
4
+ /**
5
+ * Checks if a value and all nested values are empty.
6
+ */
7
+ function isDeepEmpty(value) {
8
+ if (typeof value === 'string') {
9
+ return value.trim().length === 0;
10
+ }
11
+ if (Array.isArray(value)) {
12
+ return value.length === 0 || value.every(isDeepEmpty);
13
+ }
14
+ if (value instanceof Map || value instanceof Set) {
15
+ return value.size === 0 || Array.from(value.values()).every(isDeepEmpty);
16
+ }
17
+ if (value === null) {
18
+ return true;
19
+ }
20
+ if (typeof value === 'object') {
21
+ return Object.keys(value).length === 0 || Object.values(value).every(isDeepEmpty);
22
+ }
23
+ return value === undefined;
24
+ }
25
+ exports.isDeepEmpty = isDeepEmpty;
@@ -48,3 +48,4 @@ __exportStar(require("./urls.js"), exports);
48
48
  __exportStar(require("./validation.js"), exports);
49
49
  __exportStar(require("./value.js"), exports);
50
50
  __exportStar(require("./visit.js"), exports);
51
+ __exportStar(require("./empty.js"), exports);
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Checks if a value and all nested values are empty.
3
+ */
4
+ export function isDeepEmpty(value) {
5
+ if (typeof value === 'string') {
6
+ return value.trim().length === 0;
7
+ }
8
+ if (Array.isArray(value)) {
9
+ return value.length === 0 || value.every(isDeepEmpty);
10
+ }
11
+ if (value instanceof Map || value instanceof Set) {
12
+ return value.size === 0 || Array.from(value.values()).every(isDeepEmpty);
13
+ }
14
+ if (value === null) {
15
+ return true;
16
+ }
17
+ if (typeof value === 'object') {
18
+ return Object.keys(value).length === 0 || Object.values(value).every(isDeepEmpty);
19
+ }
20
+ return value === undefined;
21
+ }
@@ -32,3 +32,4 @@ export * from './urls.js';
32
32
  export * from './validation.js';
33
33
  export * from './value.js';
34
34
  export * from './visit.js';
35
+ export * from './empty.js';