@splendidlabz/utils 1.15.0 → 1.16.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/cjs/dom/actions/index.cjs +17 -8
- package/dist/cjs/dom/actions/prefer-horizontal-scroll.cjs +17 -8
- package/dist/cjs/dom/index.cjs +17 -8
- 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/dom/actions/prefer-horizontal-scroll.js +2 -1
- 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 +10 -10
- package/package.json +1 -1
|
@@ -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
|
}
|
|
@@ -210,10 +218,11 @@ function preferHorizontalScroll(node, props = {}) {
|
|
|
210
218
|
currentSnapType: null,
|
|
211
219
|
snapTimeoutID: null
|
|
212
220
|
};
|
|
221
|
+
const cssSnapDelay = parseFloat(getCSSVar(node, "--scroll-snap-delay"));
|
|
213
222
|
const options = {
|
|
214
223
|
...DEFAULT_OPTIONS,
|
|
215
224
|
...omitEmpty({
|
|
216
|
-
scrollSnapDelay:
|
|
225
|
+
scrollSnapDelay: Number.isNaN(cssSnapDelay) ? void 0 : cssSnapDelay
|
|
217
226
|
}),
|
|
218
227
|
...omitEmpty(props)
|
|
219
228
|
};
|
|
@@ -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
|
}
|
|
@@ -88,10 +96,11 @@ function preferHorizontalScroll(node, props = {}) {
|
|
|
88
96
|
currentSnapType: null,
|
|
89
97
|
snapTimeoutID: null
|
|
90
98
|
};
|
|
99
|
+
const cssSnapDelay = parseFloat(getCSSVar(node, "--scroll-snap-delay"));
|
|
91
100
|
const options = {
|
|
92
101
|
...DEFAULT_OPTIONS,
|
|
93
102
|
...omitEmpty({
|
|
94
|
-
scrollSnapDelay:
|
|
103
|
+
scrollSnapDelay: Number.isNaN(cssSnapDelay) ? void 0 : cssSnapDelay
|
|
95
104
|
}),
|
|
96
105
|
...omitEmpty(props)
|
|
97
106
|
};
|
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
|
}
|
|
@@ -358,10 +366,11 @@ function preferHorizontalScroll(node, props = {}) {
|
|
|
358
366
|
currentSnapType: null,
|
|
359
367
|
snapTimeoutID: null
|
|
360
368
|
};
|
|
369
|
+
const cssSnapDelay = parseFloat(getCSSVar(node, "--scroll-snap-delay"));
|
|
361
370
|
const options = {
|
|
362
371
|
...DEFAULT_OPTIONS,
|
|
363
372
|
...omitEmpty({
|
|
364
|
-
scrollSnapDelay:
|
|
373
|
+
scrollSnapDelay: Number.isNaN(cssSnapDelay) ? void 0 : cssSnapDelay
|
|
365
374
|
}),
|
|
366
375
|
...omitEmpty(props)
|
|
367
376
|
};
|
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
|
}
|
|
@@ -11,10 +11,11 @@ function preferHorizontalScroll(node, props = {}) {
|
|
|
11
11
|
currentSnapType: null,
|
|
12
12
|
snapTimeoutID: null
|
|
13
13
|
};
|
|
14
|
+
const cssSnapDelay = parseFloat(getCSSVar(node, "--scroll-snap-delay"));
|
|
14
15
|
const options = {
|
|
15
16
|
...DEFAULT_OPTIONS,
|
|
16
17
|
...omitEmpty({
|
|
17
|
-
scrollSnapDelay:
|
|
18
|
+
scrollSnapDelay: Number.isNaN(cssSnapDelay) ? void 0 : cssSnapDelay
|
|
18
19
|
}),
|
|
19
20
|
...omitEmpty(props)
|
|
20
21
|
};
|
|
@@ -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,26 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Drop the keys holding nothing
|
|
2
|
+
* Drop the keys holding nothing, as {@link isEmpty} reads it.
|
|
3
3
|
*
|
|
4
|
+
* @template {object} T
|
|
4
5
|
* @overload
|
|
5
|
-
* @param {
|
|
6
|
+
* @param {T} obj Object to filter.
|
|
6
7
|
* @param {object} [options]
|
|
7
8
|
* @param {boolean} [options.shallow=false] Leave nested values alone.
|
|
8
|
-
* @
|
|
9
|
-
* @returns {object} A copy without the empty keys.
|
|
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.
|
|
10
10
|
*/
|
|
11
|
-
declare function omitEmpty(obj:
|
|
11
|
+
declare function omitEmpty<T extends unknown>(obj: T, options?: {
|
|
12
12
|
shallow?: boolean;
|
|
13
|
-
|
|
14
|
-
}): object;
|
|
13
|
+
}): T extends readonly (infer E)[] ? NonNullable<E>[] : Partial<T>;
|
|
15
14
|
/**
|
|
16
15
|
* Drop the keys holding nothing.
|
|
17
16
|
*
|
|
17
|
+
* @template {object} T
|
|
18
18
|
* @overload
|
|
19
|
-
* @param {
|
|
19
|
+
* @param {T} obj Object to filter.
|
|
20
20
|
* @param {boolean} shallow Leave nested values alone.
|
|
21
|
-
* @returns {
|
|
21
|
+
* @returns {T extends readonly (infer E)[] ? NonNullable<E>[] : Partial<T>} A copy without the empty keys.
|
|
22
22
|
* @deprecated Pass `{ shallow: true }` instead. The boolean goes in 2.0.0.
|
|
23
23
|
*/
|
|
24
|
-
declare function omitEmpty(obj:
|
|
24
|
+
declare function omitEmpty<T extends unknown>(obj: T, shallow: boolean): T extends readonly (infer E)[] ? NonNullable<E>[] : Partial<T>;
|
|
25
25
|
|
|
26
26
|
export { omitEmpty };
|