@splendidlabz/utils 1.14.0 → 1.15.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 +16 -5
- package/dist/cjs/dom/actions/prefer-horizontal-scroll.cjs +16 -5
- package/dist/cjs/dom/index.cjs +41 -24
- package/dist/cjs/dom/pkce.cjs +16 -19
- package/dist/cjs/dom/sanitize.cjs +8 -1
- package/dist/cjs/lib/checks.cjs +7 -0
- package/dist/cjs/lib/form/form-data.cjs +10 -1
- package/dist/cjs/lib/form/index.cjs +11 -11
- package/dist/cjs/lib/form/sanitize.cjs +12 -10
- package/dist/cjs/lib/index.cjs +62 -16
- package/dist/cjs/lib/objects/index.cjs +58 -7
- package/dist/cjs/lib/objects/normalize-object.cjs +16 -5
- package/dist/cjs/lib/objects/omit-empty.cjs +18 -5
- package/dist/cjs/lib/objects/remove-invalid.cjs +61 -0
- package/dist/cjs/lib/objects/trim-values.cjs +47 -0
- package/dist/cjs/lib/promises/index.cjs +16 -5
- package/dist/cjs/lib/promises/reject.cjs +16 -5
- package/dist/cjs/lib/sse.cjs +16 -5
- package/dist/cjs/node/index.cjs +20 -17
- package/dist/cjs/node/pkce.cjs +5 -26
- package/dist/cjs/node/sanitize.cjs +8 -1
- package/dist/esm/dom/pkce.js +14 -10
- package/dist/esm/lib/checks.js +6 -0
- package/dist/esm/lib/form/form-data.js +2 -1
- package/dist/esm/lib/form/sanitize.js +4 -10
- package/dist/esm/lib/objects/index.js +2 -0
- package/dist/esm/lib/objects/omit-empty.js +10 -5
- package/dist/esm/lib/objects/remove-invalid.js +28 -0
- package/dist/esm/lib/objects/trim-values.js +14 -0
- package/dist/esm/node/pkce.js +5 -8
- package/dist/types/dom/index.d.cts +1 -1
- package/dist/types/dom/pkce.d.cts +29 -4
- package/dist/types/lib/checks.d.cts +12 -2
- package/dist/types/lib/form/sanitize.d.cts +2 -2
- package/dist/types/lib/index.d.cts +3 -1
- package/dist/types/lib/objects/index.d.cts +2 -0
- package/dist/types/lib/objects/omit-empty.d.cts +24 -1
- package/dist/types/lib/objects/remove-invalid.d.cts +12 -0
- package/dist/types/lib/objects/trim-values.d.cts +8 -0
- package/dist/types/node/index.d.cts +1 -1
- package/dist/types/node/pkce.d.cts +29 -10
- package/package.json +1 -1
|
@@ -47,8 +47,10 @@ __export(objects_exports, {
|
|
|
47
47
|
objectMap: () => objectMap,
|
|
48
48
|
omitEmpty: () => omitEmpty,
|
|
49
49
|
parseJSON: () => parseJSON,
|
|
50
|
+
removeInvalid: () => removeInvalid,
|
|
50
51
|
sizeOf: () => sizeOf,
|
|
51
|
-
splitObject: () => splitObject
|
|
52
|
+
splitObject: () => splitObject,
|
|
53
|
+
trimValues: () => trimValues
|
|
52
54
|
});
|
|
53
55
|
module.exports = __toCommonJS(objects_exports);
|
|
54
56
|
|
|
@@ -248,6 +250,11 @@ function extendObject(object) {
|
|
|
248
250
|
function isObject(x) {
|
|
249
251
|
return typeof x === "object" && !Array.isArray(x) && x !== null;
|
|
250
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
|
+
}
|
|
251
258
|
|
|
252
259
|
// src/lib/objects/flatten.js
|
|
253
260
|
function flattenObject(obj, { separator, prefix = "" }) {
|
|
@@ -289,15 +296,19 @@ function getNestedValue(object, path) {
|
|
|
289
296
|
}
|
|
290
297
|
|
|
291
298
|
// src/lib/objects/omit-empty.js
|
|
292
|
-
function omitEmpty(obj,
|
|
293
|
-
|
|
294
|
-
if (obj
|
|
299
|
+
function omitEmpty(obj, options = {}) {
|
|
300
|
+
const { shallow = false, omitFalsey = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
301
|
+
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
295
302
|
const result = Array.isArray(obj) ? [] : {};
|
|
296
303
|
for (const [key, value] of Object.entries(obj)) {
|
|
297
|
-
if (value === null || value === void 0 || value === ""
|
|
304
|
+
if (value === null || value === void 0 || value === "") continue;
|
|
305
|
+
if (omitFalsey && !value) continue;
|
|
306
|
+
if ((isPlainObject(value) || Array.isArray(value)) && Object.keys(value).length === 0) {
|
|
298
307
|
continue;
|
|
299
308
|
}
|
|
300
|
-
|
|
309
|
+
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
310
|
+
if (Array.isArray(result)) result.push(filteredValue);
|
|
311
|
+
else result[key] = filteredValue;
|
|
301
312
|
}
|
|
302
313
|
return result;
|
|
303
314
|
}
|
|
@@ -307,6 +318,32 @@ function normalizeObject(object) {
|
|
|
307
318
|
return pipe(omitEmpty, camelCaseKeys)(object);
|
|
308
319
|
}
|
|
309
320
|
|
|
321
|
+
// src/lib/objects/remove-invalid.js
|
|
322
|
+
function removeInvalid(values, schema) {
|
|
323
|
+
if (!schema) return values;
|
|
324
|
+
if (Array.isArray(values)) {
|
|
325
|
+
const kept2 = [];
|
|
326
|
+
for (const item of values) {
|
|
327
|
+
if (!isValid(item, schema)) continue;
|
|
328
|
+
kept2.push(removeInvalid(item, schema));
|
|
329
|
+
}
|
|
330
|
+
return kept2;
|
|
331
|
+
}
|
|
332
|
+
if (!isPlainObject(values) || !isPlainObject(schema)) return values;
|
|
333
|
+
const kept = {};
|
|
334
|
+
for (const [key, value] of Object.entries(values)) {
|
|
335
|
+
const keySchema = schema[key];
|
|
336
|
+
if (!isValid(value, keySchema)) continue;
|
|
337
|
+
kept[key] = removeInvalid(value, keySchema);
|
|
338
|
+
}
|
|
339
|
+
return kept;
|
|
340
|
+
}
|
|
341
|
+
function isValid(value, pattern) {
|
|
342
|
+
if (typeof value !== "string") return true;
|
|
343
|
+
if (typeof pattern !== "string" && !(pattern instanceof RegExp)) return true;
|
|
344
|
+
return new RegExp(pattern).test(value);
|
|
345
|
+
}
|
|
346
|
+
|
|
310
347
|
// src/lib/objects/size.js
|
|
311
348
|
function sizeOf(obj) {
|
|
312
349
|
let bytes = 0;
|
|
@@ -356,6 +393,18 @@ function splitObject(obj, keys) {
|
|
|
356
393
|
});
|
|
357
394
|
return { picked, omitted, p: picked, o: omitted };
|
|
358
395
|
}
|
|
396
|
+
|
|
397
|
+
// src/lib/objects/trim-values.js
|
|
398
|
+
function trimValues(values) {
|
|
399
|
+
if (typeof values === "string") return values.trim();
|
|
400
|
+
if (Array.isArray(values)) return values.map(trimValues);
|
|
401
|
+
if (!isPlainObject(values)) return values;
|
|
402
|
+
const trimmed = {};
|
|
403
|
+
for (const [key, value] of Object.entries(values)) {
|
|
404
|
+
trimmed[key] = trimValues(value);
|
|
405
|
+
}
|
|
406
|
+
return trimmed;
|
|
407
|
+
}
|
|
359
408
|
// Annotate the CommonJS export names for ESM import in node:
|
|
360
409
|
0 && (module.exports = {
|
|
361
410
|
camelCaseKeys,
|
|
@@ -376,6 +425,8 @@ function splitObject(obj, keys) {
|
|
|
376
425
|
objectMap,
|
|
377
426
|
omitEmpty,
|
|
378
427
|
parseJSON,
|
|
428
|
+
removeInvalid,
|
|
379
429
|
sizeOf,
|
|
380
|
-
splitObject
|
|
430
|
+
splitObject,
|
|
431
|
+
trimValues
|
|
381
432
|
});
|
|
@@ -85,16 +85,27 @@ function camelCaseKeys(obj) {
|
|
|
85
85
|
return result;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
// src/lib/checks.js
|
|
89
|
+
function isPlainObject(x) {
|
|
90
|
+
if (typeof x !== "object" || x === null) return false;
|
|
91
|
+
const prototype = Object.getPrototypeOf(x);
|
|
92
|
+
return prototype === Object.prototype || prototype === null;
|
|
93
|
+
}
|
|
94
|
+
|
|
88
95
|
// src/lib/objects/omit-empty.js
|
|
89
|
-
function omitEmpty(obj,
|
|
90
|
-
|
|
91
|
-
if (obj
|
|
96
|
+
function omitEmpty(obj, options = {}) {
|
|
97
|
+
const { shallow = false, omitFalsey = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
98
|
+
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
92
99
|
const result = Array.isArray(obj) ? [] : {};
|
|
93
100
|
for (const [key, value] of Object.entries(obj)) {
|
|
94
|
-
if (value === null || value === void 0 || value === ""
|
|
101
|
+
if (value === null || value === void 0 || value === "") continue;
|
|
102
|
+
if (omitFalsey && !value) continue;
|
|
103
|
+
if ((isPlainObject(value) || Array.isArray(value)) && Object.keys(value).length === 0) {
|
|
95
104
|
continue;
|
|
96
105
|
}
|
|
97
|
-
|
|
106
|
+
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
107
|
+
if (Array.isArray(result)) result.push(filteredValue);
|
|
108
|
+
else result[key] = filteredValue;
|
|
98
109
|
}
|
|
99
110
|
return result;
|
|
100
111
|
}
|
|
@@ -22,15 +22,28 @@ __export(omit_empty_exports, {
|
|
|
22
22
|
omitEmpty: () => omitEmpty
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(omit_empty_exports);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
|
|
26
|
+
// src/lib/checks.js
|
|
27
|
+
function isPlainObject(x) {
|
|
28
|
+
if (typeof x !== "object" || x === null) return false;
|
|
29
|
+
const prototype = Object.getPrototypeOf(x);
|
|
30
|
+
return prototype === Object.prototype || prototype === null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/lib/objects/omit-empty.js
|
|
34
|
+
function omitEmpty(obj, options = {}) {
|
|
35
|
+
const { shallow = false, omitFalsey = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
36
|
+
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
28
37
|
const result = Array.isArray(obj) ? [] : {};
|
|
29
38
|
for (const [key, value] of Object.entries(obj)) {
|
|
30
|
-
if (value === null || value === void 0 || value === ""
|
|
39
|
+
if (value === null || value === void 0 || value === "") continue;
|
|
40
|
+
if (omitFalsey && !value) continue;
|
|
41
|
+
if ((isPlainObject(value) || Array.isArray(value)) && Object.keys(value).length === 0) {
|
|
31
42
|
continue;
|
|
32
43
|
}
|
|
33
|
-
|
|
44
|
+
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
45
|
+
if (Array.isArray(result)) result.push(filteredValue);
|
|
46
|
+
else result[key] = filteredValue;
|
|
34
47
|
}
|
|
35
48
|
return result;
|
|
36
49
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/lib/objects/remove-invalid.js
|
|
20
|
+
var remove_invalid_exports = {};
|
|
21
|
+
__export(remove_invalid_exports, {
|
|
22
|
+
removeInvalid: () => removeInvalid
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(remove_invalid_exports);
|
|
25
|
+
|
|
26
|
+
// src/lib/checks.js
|
|
27
|
+
function isPlainObject(x) {
|
|
28
|
+
if (typeof x !== "object" || x === null) return false;
|
|
29
|
+
const prototype = Object.getPrototypeOf(x);
|
|
30
|
+
return prototype === Object.prototype || prototype === null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/lib/objects/remove-invalid.js
|
|
34
|
+
function removeInvalid(values, schema) {
|
|
35
|
+
if (!schema) return values;
|
|
36
|
+
if (Array.isArray(values)) {
|
|
37
|
+
const kept2 = [];
|
|
38
|
+
for (const item of values) {
|
|
39
|
+
if (!isValid(item, schema)) continue;
|
|
40
|
+
kept2.push(removeInvalid(item, schema));
|
|
41
|
+
}
|
|
42
|
+
return kept2;
|
|
43
|
+
}
|
|
44
|
+
if (!isPlainObject(values) || !isPlainObject(schema)) return values;
|
|
45
|
+
const kept = {};
|
|
46
|
+
for (const [key, value] of Object.entries(values)) {
|
|
47
|
+
const keySchema = schema[key];
|
|
48
|
+
if (!isValid(value, keySchema)) continue;
|
|
49
|
+
kept[key] = removeInvalid(value, keySchema);
|
|
50
|
+
}
|
|
51
|
+
return kept;
|
|
52
|
+
}
|
|
53
|
+
function isValid(value, pattern) {
|
|
54
|
+
if (typeof value !== "string") return true;
|
|
55
|
+
if (typeof pattern !== "string" && !(pattern instanceof RegExp)) return true;
|
|
56
|
+
return new RegExp(pattern).test(value);
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
removeInvalid
|
|
61
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/lib/objects/trim-values.js
|
|
20
|
+
var trim_values_exports = {};
|
|
21
|
+
__export(trim_values_exports, {
|
|
22
|
+
trimValues: () => trimValues
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(trim_values_exports);
|
|
25
|
+
|
|
26
|
+
// src/lib/checks.js
|
|
27
|
+
function isPlainObject(x) {
|
|
28
|
+
if (typeof x !== "object" || x === null) return false;
|
|
29
|
+
const prototype = Object.getPrototypeOf(x);
|
|
30
|
+
return prototype === Object.prototype || prototype === null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/lib/objects/trim-values.js
|
|
34
|
+
function trimValues(values) {
|
|
35
|
+
if (typeof values === "string") return values.trim();
|
|
36
|
+
if (Array.isArray(values)) return values.map(trimValues);
|
|
37
|
+
if (!isPlainObject(values)) return values;
|
|
38
|
+
const trimmed = {};
|
|
39
|
+
for (const [key, value] of Object.entries(values)) {
|
|
40
|
+
trimmed[key] = trimValues(value);
|
|
41
|
+
}
|
|
42
|
+
return trimmed;
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
trimValues
|
|
47
|
+
});
|
|
@@ -23,16 +23,27 @@ __export(promises_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(promises_exports);
|
|
25
25
|
|
|
26
|
+
// src/lib/checks.js
|
|
27
|
+
function isPlainObject(x) {
|
|
28
|
+
if (typeof x !== "object" || x === null) return false;
|
|
29
|
+
const prototype = Object.getPrototypeOf(x);
|
|
30
|
+
return prototype === Object.prototype || prototype === null;
|
|
31
|
+
}
|
|
32
|
+
|
|
26
33
|
// src/lib/objects/omit-empty.js
|
|
27
|
-
function omitEmpty(obj,
|
|
28
|
-
|
|
29
|
-
if (obj
|
|
34
|
+
function omitEmpty(obj, options = {}) {
|
|
35
|
+
const { shallow = false, omitFalsey = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
36
|
+
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
30
37
|
const result = Array.isArray(obj) ? [] : {};
|
|
31
38
|
for (const [key, value] of Object.entries(obj)) {
|
|
32
|
-
if (value === null || value === void 0 || value === ""
|
|
39
|
+
if (value === null || value === void 0 || value === "") continue;
|
|
40
|
+
if (omitFalsey && !value) continue;
|
|
41
|
+
if ((isPlainObject(value) || Array.isArray(value)) && Object.keys(value).length === 0) {
|
|
33
42
|
continue;
|
|
34
43
|
}
|
|
35
|
-
|
|
44
|
+
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
45
|
+
if (Array.isArray(result)) result.push(filteredValue);
|
|
46
|
+
else result[key] = filteredValue;
|
|
36
47
|
}
|
|
37
48
|
return result;
|
|
38
49
|
}
|
|
@@ -23,16 +23,27 @@ __export(reject_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(reject_exports);
|
|
25
25
|
|
|
26
|
+
// src/lib/checks.js
|
|
27
|
+
function isPlainObject(x) {
|
|
28
|
+
if (typeof x !== "object" || x === null) return false;
|
|
29
|
+
const prototype = Object.getPrototypeOf(x);
|
|
30
|
+
return prototype === Object.prototype || prototype === null;
|
|
31
|
+
}
|
|
32
|
+
|
|
26
33
|
// src/lib/objects/omit-empty.js
|
|
27
|
-
function omitEmpty(obj,
|
|
28
|
-
|
|
29
|
-
if (obj
|
|
34
|
+
function omitEmpty(obj, options = {}) {
|
|
35
|
+
const { shallow = false, omitFalsey = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
36
|
+
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
30
37
|
const result = Array.isArray(obj) ? [] : {};
|
|
31
38
|
for (const [key, value] of Object.entries(obj)) {
|
|
32
|
-
if (value === null || value === void 0 || value === ""
|
|
39
|
+
if (value === null || value === void 0 || value === "") continue;
|
|
40
|
+
if (omitFalsey && !value) continue;
|
|
41
|
+
if ((isPlainObject(value) || Array.isArray(value)) && Object.keys(value).length === 0) {
|
|
33
42
|
continue;
|
|
34
43
|
}
|
|
35
|
-
|
|
44
|
+
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
45
|
+
if (Array.isArray(result)) result.push(filteredValue);
|
|
46
|
+
else result[key] = filteredValue;
|
|
36
47
|
}
|
|
37
48
|
return result;
|
|
38
49
|
}
|
package/dist/cjs/lib/sse.cjs
CHANGED
|
@@ -33,16 +33,27 @@ function parseJSON(value, defaultValue = {}) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// src/lib/checks.js
|
|
37
|
+
function isPlainObject(x) {
|
|
38
|
+
if (typeof x !== "object" || x === null) return false;
|
|
39
|
+
const prototype = Object.getPrototypeOf(x);
|
|
40
|
+
return prototype === Object.prototype || prototype === null;
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
// src/lib/objects/omit-empty.js
|
|
37
|
-
function omitEmpty(obj,
|
|
38
|
-
|
|
39
|
-
if (obj
|
|
44
|
+
function omitEmpty(obj, options = {}) {
|
|
45
|
+
const { shallow = false, omitFalsey = false } = typeof options === "boolean" ? { shallow: options } : options;
|
|
46
|
+
if (!isPlainObject(obj) && !Array.isArray(obj)) return obj;
|
|
40
47
|
const result = Array.isArray(obj) ? [] : {};
|
|
41
48
|
for (const [key, value] of Object.entries(obj)) {
|
|
42
|
-
if (value === null || value === void 0 || value === ""
|
|
49
|
+
if (value === null || value === void 0 || value === "") continue;
|
|
50
|
+
if (omitFalsey && !value) continue;
|
|
51
|
+
if ((isPlainObject(value) || Array.isArray(value)) && Object.keys(value).length === 0) {
|
|
43
52
|
continue;
|
|
44
53
|
}
|
|
45
|
-
|
|
54
|
+
const filteredValue = shallow ? value : omitEmpty(value, { omitFalsey });
|
|
55
|
+
if (Array.isArray(result)) result.push(filteredValue);
|
|
56
|
+
else result[key] = filteredValue;
|
|
46
57
|
}
|
|
47
58
|
return result;
|
|
48
59
|
}
|
package/dist/cjs/node/index.cjs
CHANGED
|
@@ -217,41 +217,44 @@ function sha256Hash(string) {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
// src/node/pkce.js
|
|
220
|
-
var
|
|
221
|
-
|
|
222
|
-
// src/node/random-string.js
|
|
223
|
-
var import_node_crypto2 = __toESM(require("crypto"), 1);
|
|
224
|
-
function randomString(length = 32) {
|
|
225
|
-
const bytesNeeded = Math.ceil(length * 3 / 4) + 3;
|
|
226
|
-
return import_node_crypto2.default.randomBytes(bytesNeeded).toString("base64").slice(0, length);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// src/node/pkce.js
|
|
220
|
+
var import_node_crypto2 = require("crypto");
|
|
230
221
|
async function PKCE() {
|
|
231
|
-
const codeVerifier =
|
|
232
|
-
const codeChallenge = await getCodeChallenge(codeVerifier);
|
|
222
|
+
const codeVerifier = (0, import_node_crypto2.randomBytes)(32).toString("base64url");
|
|
233
223
|
return {
|
|
234
|
-
state:
|
|
224
|
+
state: (0, import_node_crypto2.randomBytes)(32).toString("base64url"),
|
|
235
225
|
code_verifier: codeVerifier,
|
|
236
|
-
code_challenge:
|
|
226
|
+
code_challenge: getCodeChallenge(codeVerifier),
|
|
237
227
|
code_challenge_method: "S256"
|
|
238
228
|
};
|
|
239
229
|
}
|
|
240
230
|
function getCodeChallenge(verifier) {
|
|
241
|
-
|
|
242
|
-
|
|
231
|
+
return (0, import_node_crypto2.createHash)("sha256").update(verifier).digest("base64url");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// src/node/random-string.js
|
|
235
|
+
var import_node_crypto3 = __toESM(require("crypto"), 1);
|
|
236
|
+
function randomString(length = 32) {
|
|
237
|
+
const bytesNeeded = Math.ceil(length * 3 / 4) + 3;
|
|
238
|
+
return import_node_crypto3.default.randomBytes(bytesNeeded).toString("base64").slice(0, length);
|
|
243
239
|
}
|
|
244
240
|
|
|
245
241
|
// src/node/sanitize.js
|
|
246
242
|
var import_sanitize_html = __toESM(require("sanitize-html"), 1);
|
|
247
243
|
|
|
244
|
+
// src/lib/checks.js
|
|
245
|
+
function isPlainObject(x) {
|
|
246
|
+
if (typeof x !== "object" || x === null) return false;
|
|
247
|
+
const prototype = Object.getPrototypeOf(x);
|
|
248
|
+
return prototype === Object.prototype || prototype === null;
|
|
249
|
+
}
|
|
250
|
+
|
|
248
251
|
// src/lib/form/sanitize.js
|
|
249
252
|
function sanitize(value, options = {}) {
|
|
250
253
|
const { sanitizer, ...rest } = options;
|
|
251
254
|
if (!sanitizer) throw new Error("sanitizer function is required");
|
|
252
255
|
if (typeof value === "string") return sanitizer(value, rest);
|
|
253
256
|
if (Array.isArray(value)) return sanitizeArray(value, { sanitizer, ...rest });
|
|
254
|
-
if (value
|
|
257
|
+
if (isPlainObject(value)) {
|
|
255
258
|
return Object.fromEntries(
|
|
256
259
|
Object.entries(value).map(([key, val]) => [
|
|
257
260
|
key,
|
package/dist/cjs/node/pkce.cjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __export = (target, all) => {
|
|
8
6
|
for (var name in all)
|
|
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
14
|
}
|
|
17
15
|
return to;
|
|
18
16
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
18
|
|
|
29
19
|
// src/node/pkce.js
|
|
@@ -33,29 +23,18 @@ __export(pkce_exports, {
|
|
|
33
23
|
getCodeChallenge: () => getCodeChallenge
|
|
34
24
|
});
|
|
35
25
|
module.exports = __toCommonJS(pkce_exports);
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
// src/node/random-string.js
|
|
39
|
-
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
40
|
-
function randomString(length = 32) {
|
|
41
|
-
const bytesNeeded = Math.ceil(length * 3 / 4) + 3;
|
|
42
|
-
return import_node_crypto.default.randomBytes(bytesNeeded).toString("base64").slice(0, length);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// src/node/pkce.js
|
|
26
|
+
var import_node_crypto = require("crypto");
|
|
46
27
|
async function PKCE() {
|
|
47
|
-
const codeVerifier =
|
|
48
|
-
const codeChallenge = await getCodeChallenge(codeVerifier);
|
|
28
|
+
const codeVerifier = (0, import_node_crypto.randomBytes)(32).toString("base64url");
|
|
49
29
|
return {
|
|
50
|
-
state:
|
|
30
|
+
state: (0, import_node_crypto.randomBytes)(32).toString("base64url"),
|
|
51
31
|
code_verifier: codeVerifier,
|
|
52
|
-
code_challenge:
|
|
32
|
+
code_challenge: getCodeChallenge(codeVerifier),
|
|
53
33
|
code_challenge_method: "S256"
|
|
54
34
|
};
|
|
55
35
|
}
|
|
56
36
|
function getCodeChallenge(verifier) {
|
|
57
|
-
|
|
58
|
-
return hash.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
37
|
+
return (0, import_node_crypto.createHash)("sha256").update(verifier).digest("base64url");
|
|
59
38
|
}
|
|
60
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
40
|
0 && (module.exports = {
|
|
@@ -34,13 +34,20 @@ __export(sanitize_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(sanitize_exports);
|
|
35
35
|
var import_sanitize_html = __toESM(require("sanitize-html"), 1);
|
|
36
36
|
|
|
37
|
+
// src/lib/checks.js
|
|
38
|
+
function isPlainObject(x) {
|
|
39
|
+
if (typeof x !== "object" || x === null) return false;
|
|
40
|
+
const prototype = Object.getPrototypeOf(x);
|
|
41
|
+
return prototype === Object.prototype || prototype === null;
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
// src/lib/form/sanitize.js
|
|
38
45
|
function sanitize(value, options = {}) {
|
|
39
46
|
const { sanitizer, ...rest } = options;
|
|
40
47
|
if (!sanitizer) throw new Error("sanitizer function is required");
|
|
41
48
|
if (typeof value === "string") return sanitizer(value, rest);
|
|
42
49
|
if (Array.isArray(value)) return sanitizeArray(value, { sanitizer, ...rest });
|
|
43
|
-
if (value
|
|
50
|
+
if (isPlainObject(value)) {
|
|
44
51
|
return Object.fromEntries(
|
|
45
52
|
Object.entries(value).map(([key, val]) => [
|
|
46
53
|
key,
|
package/dist/esm/dom/pkce.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import { randomString } from "./random-string.js";
|
|
2
1
|
async function PKCE() {
|
|
3
|
-
const codeVerifier =
|
|
4
|
-
const codeChallenge = await getCodeChallenge(codeVerifier);
|
|
2
|
+
const codeVerifier = randomVerifier();
|
|
5
3
|
return {
|
|
6
|
-
state:
|
|
4
|
+
state: randomVerifier(),
|
|
7
5
|
code_verifier: codeVerifier,
|
|
8
|
-
code_challenge:
|
|
6
|
+
code_challenge: await getCodeChallenge(codeVerifier),
|
|
9
7
|
code_challenge_method: "S256"
|
|
10
8
|
};
|
|
11
9
|
}
|
|
12
10
|
async function getCodeChallenge(verifier) {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
const data = new TextEncoder().encode(verifier);
|
|
12
|
+
const hash = await crypto.subtle.digest("SHA-256", data);
|
|
13
|
+
return toBase64Url(new Uint8Array(hash));
|
|
14
|
+
}
|
|
15
|
+
function randomVerifier() {
|
|
16
|
+
return toBase64Url(crypto.getRandomValues(new Uint8Array(32)));
|
|
17
|
+
}
|
|
18
|
+
function toBase64Url(bytes) {
|
|
19
|
+
return btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
17
20
|
}
|
|
18
21
|
export {
|
|
19
|
-
PKCE
|
|
22
|
+
PKCE,
|
|
23
|
+
getCodeChallenge
|
|
20
24
|
};
|
package/dist/esm/lib/checks.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
function isObject(x) {
|
|
2
2
|
return typeof x === "object" && !Array.isArray(x) && x !== null;
|
|
3
3
|
}
|
|
4
|
+
function isPlainObject(x) {
|
|
5
|
+
if (typeof x !== "object" || x === null) return false;
|
|
6
|
+
const prototype = Object.getPrototypeOf(x);
|
|
7
|
+
return prototype === Object.prototype || prototype === null;
|
|
8
|
+
}
|
|
4
9
|
function isArray(x) {
|
|
5
10
|
return Array.isArray(x);
|
|
6
11
|
}
|
|
@@ -30,5 +35,6 @@ export {
|
|
|
30
35
|
isArray,
|
|
31
36
|
isFunction,
|
|
32
37
|
isObject,
|
|
38
|
+
isPlainObject,
|
|
33
39
|
notObject
|
|
34
40
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isPlainObject } from "../checks.js";
|
|
1
2
|
function formDataToObject(formData) {
|
|
2
3
|
const obj = {};
|
|
3
4
|
for (let [key, value] of formData) {
|
|
@@ -38,7 +39,7 @@ function flattenArrayFields(inputObject) {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
for (const key in result) {
|
|
41
|
-
if (
|
|
42
|
+
if (isPlainObject(result[key]) || Array.isArray(result[key])) {
|
|
42
43
|
if (Object.keys(result[key]).every((k) => !isNaN(parseInt(k)))) {
|
|
43
44
|
result[key] = Object.values(result[key]).filter((item) => {
|
|
44
45
|
if (typeof item === "object") {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { isPlainObject } from "../checks.js";
|
|
1
2
|
function sanitize(value, options = {}) {
|
|
2
3
|
const { sanitizer, ...rest } = options;
|
|
3
4
|
if (!sanitizer) throw new Error("sanitizer function is required");
|
|
4
5
|
if (typeof value === "string") return sanitizer(value, rest);
|
|
5
6
|
if (Array.isArray(value)) return sanitizeArray(value, { sanitizer, ...rest });
|
|
6
|
-
if (value
|
|
7
|
+
if (isPlainObject(value)) {
|
|
7
8
|
return Object.fromEntries(
|
|
8
9
|
Object.entries(value).map(([key, val]) => [
|
|
9
10
|
key,
|
|
@@ -17,15 +18,8 @@ function sanitizeArray(arr, { sanitizer, ...rest }) {
|
|
|
17
18
|
if (!sanitizer) throw new Error("sanitizer function is required");
|
|
18
19
|
return arr.map((item) => sanitize(item, { sanitizer, ...rest }));
|
|
19
20
|
}
|
|
20
|
-
function sanitizeObject(obj,
|
|
21
|
-
|
|
22
|
-
if (Array.isArray(obj)) return sanitizeArray(obj, { sanitizer, ...options });
|
|
23
|
-
return Object.fromEntries(
|
|
24
|
-
Object.entries(obj).map(([key, value]) => [
|
|
25
|
-
key,
|
|
26
|
-
sanitize(value, { sanitizer, ...options })
|
|
27
|
-
])
|
|
28
|
-
);
|
|
21
|
+
function sanitizeObject(obj, options = {}) {
|
|
22
|
+
return sanitize(obj, options);
|
|
29
23
|
}
|
|
30
24
|
export {
|
|
31
25
|
sanitize,
|
|
@@ -9,5 +9,7 @@ export * from "./mix/mix.js";
|
|
|
9
9
|
export * from "./nested-property.js";
|
|
10
10
|
export * from "./normalize-object.js";
|
|
11
11
|
export * from "./omit-empty.js";
|
|
12
|
+
export * from "./remove-invalid.js";
|
|
12
13
|
export * from "./size.js";
|
|
13
14
|
export * from "./split.js";
|
|
15
|
+
export * from "./trim-values.js";
|