@splendidlabz/utils 1.15.1 → 1.16.1
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.md +95 -0
- package/dist/cjs/dom/actions/index.cjs +15 -7
- package/dist/cjs/dom/actions/prefer-horizontal-scroll.cjs +15 -7
- package/dist/cjs/dom/index.cjs +15 -7
- package/dist/cjs/lib/index.cjs +14 -14
- package/dist/cjs/lib/objects/empty.cjs +19 -7
- package/dist/cjs/lib/objects/index.cjs +24 -24
- package/dist/cjs/lib/objects/normalize-object.cjs +15 -7
- package/dist/cjs/lib/objects/omit-empty.cjs +15 -7
- package/dist/cjs/lib/promises/index.cjs +15 -7
- package/dist/cjs/lib/promises/reject.cjs +15 -7
- package/dist/cjs/lib/sse.cjs +15 -7
- package/dist/esm/lib/objects/empty.js +11 -7
- package/dist/esm/lib/objects/omit-empty.js +5 -7
- package/dist/types/lib/objects/empty.d.cts +19 -2
- package/dist/types/lib/objects/omit-empty.d.cts +1 -3
- package/package.json +3 -2
package/LICENSE.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Copyright (c) 2024-present Splendid Labz Pte. Ltd.
|
|
2
|
+
|
|
3
|
+
Elastic License 2.0
|
|
4
|
+
|
|
5
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
14
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
15
|
+
available, and prepare derivative works of the software, in each case subject to
|
|
16
|
+
the limitations and conditions below.
|
|
17
|
+
|
|
18
|
+
## Limitations
|
|
19
|
+
|
|
20
|
+
You may not provide the software to third parties as a hosted or managed
|
|
21
|
+
service, where the service provides users with access to any substantial set of
|
|
22
|
+
the features or functionality of the software.
|
|
23
|
+
|
|
24
|
+
You may not move, change, disable, or circumvent the license key functionality
|
|
25
|
+
in the software, and you may not remove or obscure any functionality in the
|
|
26
|
+
software that is protected by the license key.
|
|
27
|
+
|
|
28
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
29
|
+
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
30
|
+
to applicable law.
|
|
31
|
+
|
|
32
|
+
## Patents
|
|
33
|
+
|
|
34
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
35
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
36
|
+
sale, import and have imported the software, in each case subject to the
|
|
37
|
+
limitations and conditions in this license. This license does not cover any
|
|
38
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
39
|
+
the software. If you or your company make any written claim that the software
|
|
40
|
+
infringes or contributes to infringement of any patent, your patent license for
|
|
41
|
+
the software granted under these terms ends immediately. If your company makes
|
|
42
|
+
such a claim, your patent license ends immediately for work on behalf of your
|
|
43
|
+
company.
|
|
44
|
+
|
|
45
|
+
## Notices
|
|
46
|
+
|
|
47
|
+
You must ensure that anyone who gets a copy of any part of the software from you
|
|
48
|
+
also gets a copy of these terms.
|
|
49
|
+
|
|
50
|
+
If you modify the software, you must include in any modified copies of the
|
|
51
|
+
software prominent notices stating that you have modified the software.
|
|
52
|
+
|
|
53
|
+
## No Other Rights
|
|
54
|
+
|
|
55
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
56
|
+
these terms.
|
|
57
|
+
|
|
58
|
+
## Termination
|
|
59
|
+
|
|
60
|
+
If you use the software in violation of these terms, such use is not licensed,
|
|
61
|
+
and your licenses will automatically terminate. If the licensor provides you
|
|
62
|
+
with a notice of your violation, and you cease all violation of this license no
|
|
63
|
+
later than 30 days after you receive that notice, your licenses will be
|
|
64
|
+
reinstated retroactively. However, if you violate these terms after such
|
|
65
|
+
reinstatement, any additional violation of these terms will cause your licenses
|
|
66
|
+
to terminate automatically and permanently.
|
|
67
|
+
|
|
68
|
+
## No Liability
|
|
69
|
+
|
|
70
|
+
_As far as the law allows, the software comes as is, without any warranty or
|
|
71
|
+
condition, and the licensor will not be liable to you for any damages arising
|
|
72
|
+
out of these terms or the use or nature of the software, under any kind of
|
|
73
|
+
legal claim._
|
|
74
|
+
|
|
75
|
+
## Definitions
|
|
76
|
+
|
|
77
|
+
The **licensor** is the entity offering these terms, and the **software** is the
|
|
78
|
+
software the licensor makes available under these terms, including any portion
|
|
79
|
+
of it.
|
|
80
|
+
|
|
81
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
82
|
+
|
|
83
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
84
|
+
organization that you work for, plus all organizations that have control over,
|
|
85
|
+
are under the control of, or are under common control with that
|
|
86
|
+
organization. **control** means ownership of substantially all the assets of an
|
|
87
|
+
entity, or the power to direct its management and policies by vote, contract, or
|
|
88
|
+
otherwise. Control can be direct or indirect.
|
|
89
|
+
|
|
90
|
+
**your licenses** are all the licenses granted to you for the software under
|
|
91
|
+
these terms.
|
|
92
|
+
|
|
93
|
+
**use** means anything you do with the software requiring one of your licenses.
|
|
94
|
+
|
|
95
|
+
**trademark** means trademarks, service marks, and similar rights.
|
|
@@ -171,18 +171,26 @@ function isPlainObject(x) {
|
|
|
171
171
|
return prototype === Object.prototype || prototype === null;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
// src/lib/objects/empty.js
|
|
175
|
+
function isEmpty(value) {
|
|
176
|
+
if (value === null || value === void 0) return true;
|
|
177
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
178
|
+
return value.length === 0;
|
|
179
|
+
}
|
|
180
|
+
if (isPlainObject(value)) return Object.keys(value).length === 0;
|
|
181
|
+
if (typeof value.size === "number") return value.size === 0;
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
|
|
174
185
|
// src/lib/objects/omit-empty.js
|
|
175
186
|
function omitEmpty(obj, options = {}) {
|
|
176
|
-
const { shallow = false
|
|
187
|
+
const { shallow = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
177
188
|
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
178
189
|
const result = Array.isArray(obj) ? [] : {};
|
|
179
190
|
for (const [key, value] of Object.entries(obj)) {
|
|
180
|
-
if (value
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
191
|
+
if (isEmpty(value)) continue;
|
|
192
|
+
const walk = !shallow && (isPlainObject(value) || Array.isArray(value));
|
|
193
|
+
const filteredValue = walk ? omitEmpty(value) : value;
|
|
186
194
|
if (Array.isArray(result)) result.push(filteredValue);
|
|
187
195
|
else result[key] = filteredValue;
|
|
188
196
|
}
|
|
@@ -30,18 +30,26 @@ function isPlainObject(x) {
|
|
|
30
30
|
return prototype === Object.prototype || prototype === null;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
// src/lib/objects/empty.js
|
|
34
|
+
function isEmpty(value) {
|
|
35
|
+
if (value === null || value === void 0) return true;
|
|
36
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
37
|
+
return value.length === 0;
|
|
38
|
+
}
|
|
39
|
+
if (isPlainObject(value)) return Object.keys(value).length === 0;
|
|
40
|
+
if (typeof value.size === "number") return value.size === 0;
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
// src/lib/objects/omit-empty.js
|
|
34
45
|
function omitEmpty(obj, options = {}) {
|
|
35
|
-
const { shallow = false
|
|
46
|
+
const { shallow = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
36
47
|
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
37
48
|
const result = Array.isArray(obj) ? [] : {};
|
|
38
49
|
for (const [key, value] of Object.entries(obj)) {
|
|
39
|
-
if (value
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
50
|
+
if (isEmpty(value)) continue;
|
|
51
|
+
const walk = !shallow && (isPlainObject(value) || Array.isArray(value));
|
|
52
|
+
const filteredValue = walk ? omitEmpty(value) : value;
|
|
45
53
|
if (Array.isArray(result)) result.push(filteredValue);
|
|
46
54
|
else result[key] = filteredValue;
|
|
47
55
|
}
|
package/dist/cjs/dom/index.cjs
CHANGED
|
@@ -313,18 +313,26 @@ function isPlainObject(x) {
|
|
|
313
313
|
return prototype === Object.prototype || prototype === null;
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
// src/lib/objects/empty.js
|
|
317
|
+
function isEmpty(value) {
|
|
318
|
+
if (value === null || value === void 0) return true;
|
|
319
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
320
|
+
return value.length === 0;
|
|
321
|
+
}
|
|
322
|
+
if (isPlainObject(value)) return Object.keys(value).length === 0;
|
|
323
|
+
if (typeof value.size === "number") return value.size === 0;
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
|
|
316
327
|
// src/lib/objects/omit-empty.js
|
|
317
328
|
function omitEmpty(obj, options = {}) {
|
|
318
|
-
const { shallow = false
|
|
329
|
+
const { shallow = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
319
330
|
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
320
331
|
const result = Array.isArray(obj) ? [] : {};
|
|
321
332
|
for (const [key, value] of Object.entries(obj)) {
|
|
322
|
-
if (value
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
continue;
|
|
326
|
-
}
|
|
327
|
-
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
333
|
+
if (isEmpty(value)) continue;
|
|
334
|
+
const walk = !shallow && (isPlainObject(value) || Array.isArray(value));
|
|
335
|
+
const filteredValue = walk ? omitEmpty(value) : value;
|
|
328
336
|
if (Array.isArray(result)) result.push(filteredValue);
|
|
329
337
|
else result[key] = filteredValue;
|
|
330
338
|
}
|
package/dist/cjs/lib/index.cjs
CHANGED
|
@@ -835,14 +835,17 @@ function camelCaseKeys(obj) {
|
|
|
835
835
|
}
|
|
836
836
|
|
|
837
837
|
// src/lib/objects/empty.js
|
|
838
|
-
function isEmpty(
|
|
839
|
-
if (
|
|
840
|
-
if (
|
|
841
|
-
|
|
842
|
-
|
|
838
|
+
function isEmpty(value) {
|
|
839
|
+
if (value === null || value === void 0) return true;
|
|
840
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
841
|
+
return value.length === 0;
|
|
842
|
+
}
|
|
843
|
+
if (isPlainObject(value)) return Object.keys(value).length === 0;
|
|
844
|
+
if (typeof value.size === "number") return value.size === 0;
|
|
845
|
+
return false;
|
|
843
846
|
}
|
|
844
|
-
function notEmpty(
|
|
845
|
-
return !isEmpty(
|
|
847
|
+
function notEmpty(value) {
|
|
848
|
+
return !isEmpty(value);
|
|
846
849
|
}
|
|
847
850
|
|
|
848
851
|
// src/lib/objects/equal.js
|
|
@@ -974,16 +977,13 @@ function parseJSON(value, defaultValue = {}) {
|
|
|
974
977
|
|
|
975
978
|
// src/lib/objects/omit-empty.js
|
|
976
979
|
function omitEmpty(obj, options = {}) {
|
|
977
|
-
const { shallow = false
|
|
980
|
+
const { shallow = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
978
981
|
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
979
982
|
const result = Array.isArray(obj) ? [] : {};
|
|
980
983
|
for (const [key, value] of Object.entries(obj)) {
|
|
981
|
-
if (value
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
continue;
|
|
985
|
-
}
|
|
986
|
-
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
984
|
+
if (isEmpty(value)) continue;
|
|
985
|
+
const walk = !shallow && (isPlainObject(value) || Array.isArray(value));
|
|
986
|
+
const filteredValue = walk ? omitEmpty(value) : value;
|
|
987
987
|
if (Array.isArray(result)) result.push(filteredValue);
|
|
988
988
|
else result[key] = filteredValue;
|
|
989
989
|
}
|
|
@@ -23,14 +23,26 @@ __export(empty_exports, {
|
|
|
23
23
|
notEmpty: () => notEmpty
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(empty_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
|
|
26
|
+
|
|
27
|
+
// src/lib/checks.js
|
|
28
|
+
function isPlainObject(x) {
|
|
29
|
+
if (typeof x !== "object" || x === null) return false;
|
|
30
|
+
const prototype = Object.getPrototypeOf(x);
|
|
31
|
+
return prototype === Object.prototype || prototype === null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/lib/objects/empty.js
|
|
35
|
+
function isEmpty(value) {
|
|
36
|
+
if (value === null || value === void 0) return true;
|
|
37
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
38
|
+
return value.length === 0;
|
|
39
|
+
}
|
|
40
|
+
if (isPlainObject(value)) return Object.keys(value).length === 0;
|
|
41
|
+
if (typeof value.size === "number") return value.size === 0;
|
|
42
|
+
return false;
|
|
31
43
|
}
|
|
32
|
-
function notEmpty(
|
|
33
|
-
return !isEmpty(
|
|
44
|
+
function notEmpty(value) {
|
|
45
|
+
return !isEmpty(value);
|
|
34
46
|
}
|
|
35
47
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
48
|
0 && (module.exports = {
|
|
@@ -114,15 +114,28 @@ function camelCaseKeys(obj) {
|
|
|
114
114
|
return result;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
// src/lib/checks.js
|
|
118
|
+
function isObject(x) {
|
|
119
|
+
return typeof x === "object" && !Array.isArray(x) && x !== null;
|
|
120
|
+
}
|
|
121
|
+
function isPlainObject(x) {
|
|
122
|
+
if (typeof x !== "object" || x === null) return false;
|
|
123
|
+
const prototype = Object.getPrototypeOf(x);
|
|
124
|
+
return prototype === Object.prototype || prototype === null;
|
|
125
|
+
}
|
|
126
|
+
|
|
117
127
|
// src/lib/objects/empty.js
|
|
118
|
-
function isEmpty(
|
|
119
|
-
if (
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
function isEmpty(value) {
|
|
129
|
+
if (value === null || value === void 0) return true;
|
|
130
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
131
|
+
return value.length === 0;
|
|
132
|
+
}
|
|
133
|
+
if (isPlainObject(value)) return Object.keys(value).length === 0;
|
|
134
|
+
if (typeof value.size === "number") return value.size === 0;
|
|
135
|
+
return false;
|
|
123
136
|
}
|
|
124
|
-
function notEmpty(
|
|
125
|
-
return !isEmpty(
|
|
137
|
+
function notEmpty(value) {
|
|
138
|
+
return !isEmpty(value);
|
|
126
139
|
}
|
|
127
140
|
|
|
128
141
|
// src/lib/objects/equal.js
|
|
@@ -246,16 +259,6 @@ function extendObject(object) {
|
|
|
246
259
|
return { orig, extended };
|
|
247
260
|
}
|
|
248
261
|
|
|
249
|
-
// src/lib/checks.js
|
|
250
|
-
function isObject(x) {
|
|
251
|
-
return typeof x === "object" && !Array.isArray(x) && x !== null;
|
|
252
|
-
}
|
|
253
|
-
function isPlainObject(x) {
|
|
254
|
-
if (typeof x !== "object" || x === null) return false;
|
|
255
|
-
const prototype = Object.getPrototypeOf(x);
|
|
256
|
-
return prototype === Object.prototype || prototype === null;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
262
|
// src/lib/objects/flatten.js
|
|
260
263
|
function flattenObject(obj, { separator, prefix = "" }) {
|
|
261
264
|
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
@@ -297,16 +300,13 @@ function getNestedValue(object, path) {
|
|
|
297
300
|
|
|
298
301
|
// src/lib/objects/omit-empty.js
|
|
299
302
|
function omitEmpty(obj, options = {}) {
|
|
300
|
-
const { shallow = false
|
|
303
|
+
const { shallow = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
301
304
|
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
302
305
|
const result = Array.isArray(obj) ? [] : {};
|
|
303
306
|
for (const [key, value] of Object.entries(obj)) {
|
|
304
|
-
if (value
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
307
|
+
if (isEmpty(value)) continue;
|
|
308
|
+
const walk = !shallow && (isPlainObject(value) || Array.isArray(value));
|
|
309
|
+
const filteredValue = walk ? omitEmpty(value) : value;
|
|
310
310
|
if (Array.isArray(result)) result.push(filteredValue);
|
|
311
311
|
else result[key] = filteredValue;
|
|
312
312
|
}
|
|
@@ -92,18 +92,26 @@ function isPlainObject(x) {
|
|
|
92
92
|
return prototype === Object.prototype || prototype === null;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
// src/lib/objects/empty.js
|
|
96
|
+
function isEmpty(value) {
|
|
97
|
+
if (value === null || value === void 0) return true;
|
|
98
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
99
|
+
return value.length === 0;
|
|
100
|
+
}
|
|
101
|
+
if (isPlainObject(value)) return Object.keys(value).length === 0;
|
|
102
|
+
if (typeof value.size === "number") return value.size === 0;
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
95
106
|
// src/lib/objects/omit-empty.js
|
|
96
107
|
function omitEmpty(obj, options = {}) {
|
|
97
|
-
const { shallow = false
|
|
108
|
+
const { shallow = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
98
109
|
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
99
110
|
const result = Array.isArray(obj) ? [] : {};
|
|
100
111
|
for (const [key, value] of Object.entries(obj)) {
|
|
101
|
-
if (value
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
112
|
+
if (isEmpty(value)) continue;
|
|
113
|
+
const walk = !shallow && (isPlainObject(value) || Array.isArray(value));
|
|
114
|
+
const filteredValue = walk ? omitEmpty(value) : value;
|
|
107
115
|
if (Array.isArray(result)) result.push(filteredValue);
|
|
108
116
|
else result[key] = filteredValue;
|
|
109
117
|
}
|
|
@@ -30,18 +30,26 @@ function isPlainObject(x) {
|
|
|
30
30
|
return prototype === Object.prototype || prototype === null;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
// src/lib/objects/empty.js
|
|
34
|
+
function isEmpty(value) {
|
|
35
|
+
if (value === null || value === void 0) return true;
|
|
36
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
37
|
+
return value.length === 0;
|
|
38
|
+
}
|
|
39
|
+
if (isPlainObject(value)) return Object.keys(value).length === 0;
|
|
40
|
+
if (typeof value.size === "number") return value.size === 0;
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
// src/lib/objects/omit-empty.js
|
|
34
45
|
function omitEmpty(obj, options = {}) {
|
|
35
|
-
const { shallow = false
|
|
46
|
+
const { shallow = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
36
47
|
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
37
48
|
const result = Array.isArray(obj) ? [] : {};
|
|
38
49
|
for (const [key, value] of Object.entries(obj)) {
|
|
39
|
-
if (value
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
50
|
+
if (isEmpty(value)) continue;
|
|
51
|
+
const walk = !shallow && (isPlainObject(value) || Array.isArray(value));
|
|
52
|
+
const filteredValue = walk ? omitEmpty(value) : value;
|
|
45
53
|
if (Array.isArray(result)) result.push(filteredValue);
|
|
46
54
|
else result[key] = filteredValue;
|
|
47
55
|
}
|
|
@@ -30,18 +30,26 @@ function isPlainObject(x) {
|
|
|
30
30
|
return prototype === Object.prototype || prototype === null;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
// src/lib/objects/empty.js
|
|
34
|
+
function isEmpty(value) {
|
|
35
|
+
if (value === null || value === void 0) return true;
|
|
36
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
37
|
+
return value.length === 0;
|
|
38
|
+
}
|
|
39
|
+
if (isPlainObject(value)) return Object.keys(value).length === 0;
|
|
40
|
+
if (typeof value.size === "number") return value.size === 0;
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
// src/lib/objects/omit-empty.js
|
|
34
45
|
function omitEmpty(obj, options = {}) {
|
|
35
|
-
const { shallow = false
|
|
46
|
+
const { shallow = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
36
47
|
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
37
48
|
const result = Array.isArray(obj) ? [] : {};
|
|
38
49
|
for (const [key, value] of Object.entries(obj)) {
|
|
39
|
-
if (value
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
50
|
+
if (isEmpty(value)) continue;
|
|
51
|
+
const walk = !shallow && (isPlainObject(value) || Array.isArray(value));
|
|
52
|
+
const filteredValue = walk ? omitEmpty(value) : value;
|
|
45
53
|
if (Array.isArray(result)) result.push(filteredValue);
|
|
46
54
|
else result[key] = filteredValue;
|
|
47
55
|
}
|
|
@@ -30,18 +30,26 @@ function isPlainObject(x) {
|
|
|
30
30
|
return prototype === Object.prototype || prototype === null;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
// src/lib/objects/empty.js
|
|
34
|
+
function isEmpty(value) {
|
|
35
|
+
if (value === null || value === void 0) return true;
|
|
36
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
37
|
+
return value.length === 0;
|
|
38
|
+
}
|
|
39
|
+
if (isPlainObject(value)) return Object.keys(value).length === 0;
|
|
40
|
+
if (typeof value.size === "number") return value.size === 0;
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
// src/lib/objects/omit-empty.js
|
|
34
45
|
function omitEmpty(obj, options = {}) {
|
|
35
|
-
const { shallow = false
|
|
46
|
+
const { shallow = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
36
47
|
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
37
48
|
const result = Array.isArray(obj) ? [] : {};
|
|
38
49
|
for (const [key, value] of Object.entries(obj)) {
|
|
39
|
-
if (value
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
50
|
+
if (isEmpty(value)) continue;
|
|
51
|
+
const walk = !shallow && (isPlainObject(value) || Array.isArray(value));
|
|
52
|
+
const filteredValue = walk ? omitEmpty(value) : value;
|
|
45
53
|
if (Array.isArray(result)) result.push(filteredValue);
|
|
46
54
|
else result[key] = filteredValue;
|
|
47
55
|
}
|
package/dist/cjs/lib/sse.cjs
CHANGED
|
@@ -40,18 +40,26 @@ function isPlainObject(x) {
|
|
|
40
40
|
return prototype === Object.prototype || prototype === null;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
// src/lib/objects/empty.js
|
|
44
|
+
function isEmpty(value) {
|
|
45
|
+
if (value === null || value === void 0) return true;
|
|
46
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
47
|
+
return value.length === 0;
|
|
48
|
+
}
|
|
49
|
+
if (isPlainObject(value)) return Object.keys(value).length === 0;
|
|
50
|
+
if (typeof value.size === "number") return value.size === 0;
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
// src/lib/objects/omit-empty.js
|
|
44
55
|
function omitEmpty(obj, options = {}) {
|
|
45
|
-
const { shallow = false
|
|
56
|
+
const { shallow = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
46
57
|
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
47
58
|
const result = Array.isArray(obj) ? [] : {};
|
|
48
59
|
for (const [key, value] of Object.entries(obj)) {
|
|
49
|
-
if (value
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
60
|
+
if (isEmpty(value)) continue;
|
|
61
|
+
const walk = !shallow && (isPlainObject(value) || Array.isArray(value));
|
|
62
|
+
const filteredValue = walk ? omitEmpty(value) : value;
|
|
55
63
|
if (Array.isArray(result)) result.push(filteredValue);
|
|
56
64
|
else result[key] = filteredValue;
|
|
57
65
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (
|
|
4
|
-
if (Array.isArray(
|
|
5
|
-
|
|
1
|
+
import { isPlainObject } from "../checks.js";
|
|
2
|
+
function isEmpty(value) {
|
|
3
|
+
if (value === null || value === void 0) return true;
|
|
4
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
5
|
+
return value.length === 0;
|
|
6
|
+
}
|
|
7
|
+
if (isPlainObject(value)) return Object.keys(value).length === 0;
|
|
8
|
+
if (typeof value.size === "number") return value.size === 0;
|
|
9
|
+
return false;
|
|
6
10
|
}
|
|
7
|
-
function notEmpty(
|
|
8
|
-
return !isEmpty(
|
|
11
|
+
function notEmpty(value) {
|
|
12
|
+
return !isEmpty(value);
|
|
9
13
|
}
|
|
10
14
|
export {
|
|
11
15
|
isEmpty,
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { isPlainObject } from "../checks.js";
|
|
2
|
+
import { isEmpty } from "./empty.js";
|
|
2
3
|
function omitEmpty(obj, options = {}) {
|
|
3
|
-
const { shallow = false
|
|
4
|
+
const { shallow = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
4
5
|
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
5
6
|
const result = Array.isArray(obj) ? [] : {};
|
|
6
7
|
for (const [key, value] of Object.entries(obj)) {
|
|
7
|
-
if (value
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
8
|
+
if (isEmpty(value)) continue;
|
|
9
|
+
const walk = !shallow && (isPlainObject(value) || Array.isArray(value));
|
|
10
|
+
const filteredValue = walk ? omitEmpty(value) : value;
|
|
13
11
|
if (Array.isArray(result)) result.push(filteredValue);
|
|
14
12
|
else result[key] = filteredValue;
|
|
15
13
|
}
|
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Says whether a value holds nothing — absence, or a container with nothing in it. `0` and `false` are answers, not emptiness.
|
|
3
|
+
* @param {any} value - The value to check
|
|
4
|
+
* @returns {boolean} True where there is nothing there
|
|
5
|
+
* @example
|
|
6
|
+
* isEmpty(null) // true
|
|
7
|
+
* isEmpty([]) // true
|
|
8
|
+
* isEmpty(new Map()) // true
|
|
9
|
+
* isEmpty(0) // false
|
|
10
|
+
* isEmpty(false) // false
|
|
11
|
+
* isEmpty(new Date()) // false
|
|
12
|
+
*/
|
|
13
|
+
declare function isEmpty(value: any): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Says whether a value holds something. The inverse of {@link isEmpty}.
|
|
16
|
+
* @param {any} value - The value to check
|
|
17
|
+
* @returns {boolean} True where there is something there
|
|
18
|
+
*/
|
|
19
|
+
declare function notEmpty(value: any): boolean;
|
|
3
20
|
|
|
4
21
|
export { isEmpty, notEmpty };
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Drop the keys holding nothing
|
|
2
|
+
* Drop the keys holding nothing, as {@link isEmpty} reads it.
|
|
3
3
|
*
|
|
4
4
|
* @template {object} T
|
|
5
5
|
* @overload
|
|
6
6
|
* @param {T} obj Object to filter.
|
|
7
7
|
* @param {object} [options]
|
|
8
8
|
* @param {boolean} [options.shallow=false] Leave nested values alone.
|
|
9
|
-
* @param {boolean} [options.omitFalsey=false] Drop 0, false and NaN too.
|
|
10
9
|
* @returns {T extends readonly (infer E)[] ? NonNullable<E>[] : Partial<T>} A copy without the empty keys. An array answers with an array, its element type stripped of `null` and `undefined` — the two entries this always drops.
|
|
11
10
|
*/
|
|
12
11
|
declare function omitEmpty<T extends unknown>(obj: T, options?: {
|
|
13
12
|
shallow?: boolean;
|
|
14
|
-
omitFalsey?: boolean;
|
|
15
13
|
}): T extends readonly (infer E)[] ? NonNullable<E>[] : Partial<T>;
|
|
16
14
|
/**
|
|
17
15
|
* Drop the keys holding nothing.
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splendidlabz/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.1",
|
|
4
4
|
"description": "",
|
|
5
|
+
"license": "Elastic-2.0",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"homepage": "https://splendidlabz.com/docs/utils",
|
|
7
8
|
"sideEffects": false,
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
"sanitize-html": "^2.17.3"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
|
-
"@splendidlabz/eslint-config": "2.
|
|
71
|
+
"@splendidlabz/eslint-config": "2.2.0",
|
|
71
72
|
"np": "^11.1.0",
|
|
72
73
|
"tsup": "^8.5.1",
|
|
73
74
|
"typescript": "^6.0.3",
|