@khgtrn/lib 1.0.2 → 1.0.3
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/README.md +3 -0
- package/dist/cjs/func.d.ts +33 -0
- package/dist/cjs/func.js +87 -27
- package/dist/esm/func.d.ts +33 -0
- package/dist/esm/func.js +83 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,9 +61,12 @@ Without an explicit `O`, it defaults to `any`.
|
|
|
61
61
|
| --- | --- |
|
|
62
62
|
| `isEmpty(value)` | Checks whether a value is empty (string, `0`, `false`, null/undefined, empty array/object) |
|
|
63
63
|
| `isNumber(value)` | Type-guard: a valid finite number (not NaN/Infinity) |
|
|
64
|
+
| `nullish(value, defaultValue)` | Returns `value` unless it's `null`/`undefined`, in which case returns `defaultValue` — a `??`-equivalent for pre-3.7 TypeScript |
|
|
65
|
+
| `jsonParse(s, defaultValue?)` | `JSON.parse` with a fallback value instead of throwing on invalid input |
|
|
64
66
|
| `vi2en(s)` | Strips Vietnamese diacritics (`"Điều chỉnh"` -> `"Dieu chinh"`) |
|
|
65
67
|
| `crlf2lf(value)` | Normalizes `\r\n` -> `\n` |
|
|
66
68
|
| `removeNewline(value)` | Removes all newlines, trims surrounding whitespace |
|
|
69
|
+
| `padStart(str, targetLength, padChar?)` / `padEnd(str, targetLength, padChar?)` | Pads a string to a target length by adding characters to the left/right (defaults to `"0"`) |
|
|
67
70
|
| `shuffleArray(array)` | Shuffles an array in place (Fisher-Yates) |
|
|
68
71
|
| `objectValueToArray(obj)` | Collects an object's values into an array |
|
|
69
72
|
| `groupBy(list, fn)` | Groups items by a computed key |
|
package/dist/cjs/func.d.ts
CHANGED
|
@@ -19,6 +19,21 @@ export declare function isEmpty(value: any): boolean;
|
|
|
19
19
|
* @returns Type-guard: `true` if `value` is a finite number.
|
|
20
20
|
*/
|
|
21
21
|
export declare function isNumber(value: any): value is number;
|
|
22
|
+
/**
|
|
23
|
+
* Nếu giá trị của `value` không phải là null hoặc undefined thì lấy, ngược lại trả về `defaultValue`.
|
|
24
|
+
* @note Sử dụng thay cho cú pháp `??`. Nếu TS3.7 trở lên thì không cần dùng.
|
|
25
|
+
* @param value Giá trị cần kiểm tra
|
|
26
|
+
* @param defaultValue Giá trị mặc định trả về nếu `value` là null hoặc undefined
|
|
27
|
+
* @global
|
|
28
|
+
*/
|
|
29
|
+
export declare function nullish(value: any, defaultValue: any): any;
|
|
30
|
+
/**
|
|
31
|
+
* JSON.parse với giá trị mặc định nếu có lỗi
|
|
32
|
+
* @param s giá trị JSON cần parse
|
|
33
|
+
* @param defaultValue giá trị mặc định trả về nếu có lỗi khi parse. Mặc định là null
|
|
34
|
+
* @returns any
|
|
35
|
+
*/
|
|
36
|
+
export declare function jsonParse<T = any>(s: string, defaultValue?: T | any): T | null;
|
|
22
37
|
/**
|
|
23
38
|
* Converts Vietnamese diacritics to their plain ASCII equivalents
|
|
24
39
|
* (e.g. `"Điều chỉnh"` -> `"Dieu chinh"`).
|
|
@@ -40,6 +55,24 @@ export declare function crlf2lf(value: string): string;
|
|
|
40
55
|
* @returns The string with all newlines removed.
|
|
41
56
|
*/
|
|
42
57
|
export declare function removeNewline(value: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Thêm ký tự vào đầu chuỗi cho đến khi đạt được độ dài mục tiêu
|
|
60
|
+
* @param str Chuỗi gốc
|
|
61
|
+
* @param targetLength Độ dài mục tiêu sau khi thêm ký tự
|
|
62
|
+
* @param padChar Ký tự dùng để thêm vào đầu chuỗi (mặc định là "0")
|
|
63
|
+
* @returns Chuỗi đã được thêm ký tự vào đầu nếu cần thiết
|
|
64
|
+
* @global
|
|
65
|
+
*/
|
|
66
|
+
export declare function padStart(str: string, targetLength: number, padChar?: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* Thêm ký tự vào cuối chuỗi cho đến khi đạt được độ dài mục tiêu
|
|
69
|
+
* @param str Chuỗi gốc
|
|
70
|
+
* @param targetLength Độ dài mục tiêu sau khi thêm ký tự
|
|
71
|
+
* @param padChar Ký tự dùng để thêm vào cuối chuỗi (mặc định là "0")
|
|
72
|
+
* @returns Chuỗi đã được thêm ký tự vào cuối nếu cần thiết
|
|
73
|
+
* @global
|
|
74
|
+
*/
|
|
75
|
+
export declare function padEnd(str: string, targetLength: number, padChar?: string): string;
|
|
43
76
|
/**
|
|
44
77
|
* Shuffles an array in place using the Fisher-Yates algorithm.
|
|
45
78
|
* @param array - Array to shuffle (mutated directly).
|
package/dist/cjs/func.js
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isEmpty = isEmpty;
|
|
4
4
|
exports.isNumber = isNumber;
|
|
5
|
+
exports.nullish = nullish;
|
|
6
|
+
exports.jsonParse = jsonParse;
|
|
5
7
|
exports.vi2en = vi2en;
|
|
6
8
|
exports.crlf2lf = crlf2lf;
|
|
7
9
|
exports.removeNewline = removeNewline;
|
|
10
|
+
exports.padStart = padStart;
|
|
11
|
+
exports.padEnd = padEnd;
|
|
8
12
|
exports.shuffleArray = shuffleArray;
|
|
9
13
|
exports.objectValueToArray = objectValueToArray;
|
|
10
14
|
exports.groupBy = groupBy;
|
|
@@ -68,6 +72,30 @@ function isEmpty(value) {
|
|
|
68
72
|
function isNumber(value) {
|
|
69
73
|
return typeof value === "number" && Number.isFinite(value);
|
|
70
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Nếu giá trị của `value` không phải là null hoặc undefined thì lấy, ngược lại trả về `defaultValue`.
|
|
77
|
+
* @note Sử dụng thay cho cú pháp `??`. Nếu TS3.7 trở lên thì không cần dùng.
|
|
78
|
+
* @param value Giá trị cần kiểm tra
|
|
79
|
+
* @param defaultValue Giá trị mặc định trả về nếu `value` là null hoặc undefined
|
|
80
|
+
* @global
|
|
81
|
+
*/
|
|
82
|
+
function nullish(value, defaultValue) {
|
|
83
|
+
return value !== null && value !== undefined ? value : defaultValue;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* JSON.parse với giá trị mặc định nếu có lỗi
|
|
87
|
+
* @param s giá trị JSON cần parse
|
|
88
|
+
* @param defaultValue giá trị mặc định trả về nếu có lỗi khi parse. Mặc định là null
|
|
89
|
+
* @returns any
|
|
90
|
+
*/
|
|
91
|
+
function jsonParse(s, defaultValue = null) {
|
|
92
|
+
try {
|
|
93
|
+
return JSON.parse(s);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
return defaultValue;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
71
99
|
/**
|
|
72
100
|
* Converts Vietnamese diacritics to their plain ASCII equivalents
|
|
73
101
|
* (e.g. `"Điều chỉnh"` -> `"Dieu chinh"`).
|
|
@@ -102,6 +130,40 @@ function crlf2lf(value) {
|
|
|
102
130
|
function removeNewline(value) {
|
|
103
131
|
return crlf2lf(value).trim().replace(/\n/g, "");
|
|
104
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Thêm ký tự vào đầu chuỗi cho đến khi đạt được độ dài mục tiêu
|
|
135
|
+
* @param str Chuỗi gốc
|
|
136
|
+
* @param targetLength Độ dài mục tiêu sau khi thêm ký tự
|
|
137
|
+
* @param padChar Ký tự dùng để thêm vào đầu chuỗi (mặc định là "0")
|
|
138
|
+
* @returns Chuỗi đã được thêm ký tự vào đầu nếu cần thiết
|
|
139
|
+
* @global
|
|
140
|
+
*/
|
|
141
|
+
function padStart(str, targetLength, padChar = "0") {
|
|
142
|
+
str = String(str);
|
|
143
|
+
if (str.length >= targetLength || !padChar)
|
|
144
|
+
return str;
|
|
145
|
+
const padding = padChar
|
|
146
|
+
.repeat(Math.ceil((targetLength - str.length) / padChar.length))
|
|
147
|
+
.substring(0, targetLength - str.length);
|
|
148
|
+
return padding + str;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Thêm ký tự vào cuối chuỗi cho đến khi đạt được độ dài mục tiêu
|
|
152
|
+
* @param str Chuỗi gốc
|
|
153
|
+
* @param targetLength Độ dài mục tiêu sau khi thêm ký tự
|
|
154
|
+
* @param padChar Ký tự dùng để thêm vào cuối chuỗi (mặc định là "0")
|
|
155
|
+
* @returns Chuỗi đã được thêm ký tự vào cuối nếu cần thiết
|
|
156
|
+
* @global
|
|
157
|
+
*/
|
|
158
|
+
function padEnd(str, targetLength, padChar = "0") {
|
|
159
|
+
str = String(str);
|
|
160
|
+
if (str.length >= targetLength || !padChar)
|
|
161
|
+
return str;
|
|
162
|
+
const padding = padChar
|
|
163
|
+
.repeat(Math.ceil((targetLength - str.length) / padChar.length))
|
|
164
|
+
.substring(0, targetLength - str.length);
|
|
165
|
+
return str + padding;
|
|
166
|
+
}
|
|
105
167
|
/**
|
|
106
168
|
* Shuffles an array in place using the Fisher-Yates algorithm.
|
|
107
169
|
* @param array - Array to shuffle (mutated directly).
|
|
@@ -121,10 +183,9 @@ function shuffleArray(array) {
|
|
|
121
183
|
* @returns Array of the object's values.
|
|
122
184
|
*/
|
|
123
185
|
function objectValueToArray(obj) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return arr;
|
|
186
|
+
if (obj === null || obj === undefined)
|
|
187
|
+
return [];
|
|
188
|
+
return Object.keys(obj).map((key) => obj[key]);
|
|
128
189
|
}
|
|
129
190
|
/**
|
|
130
191
|
* Groups list items by the key returned from `fn`, similar to Lodash's
|
|
@@ -161,15 +222,18 @@ function removeByKey(objectOrArray, keys) {
|
|
|
161
222
|
return objectOrArray.map((item) => typeof item === "object" && item !== null ? removeByKey(item, keys) : item);
|
|
162
223
|
}
|
|
163
224
|
if (typeof objectOrArray === "object" && objectOrArray !== null) {
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
|
|
225
|
+
const source = objectOrArray;
|
|
226
|
+
const result = {};
|
|
227
|
+
Object.keys(source).forEach((key) => {
|
|
228
|
+
if (keys.includes(key))
|
|
229
|
+
return;
|
|
230
|
+
const value = source[key];
|
|
231
|
+
result[key] =
|
|
232
|
+
Array.isArray(value) || (typeof value === "object" && value !== null)
|
|
233
|
+
? removeByKey(value, keys)
|
|
234
|
+
: value;
|
|
171
235
|
});
|
|
172
|
-
return
|
|
236
|
+
return result;
|
|
173
237
|
}
|
|
174
238
|
// Primitives are returned as-is
|
|
175
239
|
return objectOrArray;
|
|
@@ -204,22 +268,18 @@ function removeEmptyValue(objectOrArray, options = {}) {
|
|
|
204
268
|
return result;
|
|
205
269
|
}
|
|
206
270
|
if (typeof objectOrArray === "object" && objectOrArray !== null) {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}),
|
|
217
|
-
];
|
|
271
|
+
const source = objectOrArray;
|
|
272
|
+
const result = {};
|
|
273
|
+
Object.keys(source).forEach((key) => {
|
|
274
|
+
const rawValue = source[key];
|
|
275
|
+
const value = Array.isArray(rawValue) || (typeof rawValue === "object" && rawValue !== null)
|
|
276
|
+
? removeEmptyValue(rawValue, { removeNull, removeUndefined, removeEmptyString })
|
|
277
|
+
: rawValue;
|
|
278
|
+
if (!shouldRemove(value)) {
|
|
279
|
+
result[key] = value;
|
|
218
280
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
.filter(([, value]) => !shouldRemove(value));
|
|
222
|
-
return Object.fromEntries(entries);
|
|
281
|
+
});
|
|
282
|
+
return result;
|
|
223
283
|
}
|
|
224
284
|
return objectOrArray;
|
|
225
285
|
}
|
package/dist/esm/func.d.ts
CHANGED
|
@@ -19,6 +19,21 @@ export declare function isEmpty(value: any): boolean;
|
|
|
19
19
|
* @returns Type-guard: `true` if `value` is a finite number.
|
|
20
20
|
*/
|
|
21
21
|
export declare function isNumber(value: any): value is number;
|
|
22
|
+
/**
|
|
23
|
+
* Nếu giá trị của `value` không phải là null hoặc undefined thì lấy, ngược lại trả về `defaultValue`.
|
|
24
|
+
* @note Sử dụng thay cho cú pháp `??`. Nếu TS3.7 trở lên thì không cần dùng.
|
|
25
|
+
* @param value Giá trị cần kiểm tra
|
|
26
|
+
* @param defaultValue Giá trị mặc định trả về nếu `value` là null hoặc undefined
|
|
27
|
+
* @global
|
|
28
|
+
*/
|
|
29
|
+
export declare function nullish(value: any, defaultValue: any): any;
|
|
30
|
+
/**
|
|
31
|
+
* JSON.parse với giá trị mặc định nếu có lỗi
|
|
32
|
+
* @param s giá trị JSON cần parse
|
|
33
|
+
* @param defaultValue giá trị mặc định trả về nếu có lỗi khi parse. Mặc định là null
|
|
34
|
+
* @returns any
|
|
35
|
+
*/
|
|
36
|
+
export declare function jsonParse<T = any>(s: string, defaultValue?: T | any): T | null;
|
|
22
37
|
/**
|
|
23
38
|
* Converts Vietnamese diacritics to their plain ASCII equivalents
|
|
24
39
|
* (e.g. `"Điều chỉnh"` -> `"Dieu chinh"`).
|
|
@@ -40,6 +55,24 @@ export declare function crlf2lf(value: string): string;
|
|
|
40
55
|
* @returns The string with all newlines removed.
|
|
41
56
|
*/
|
|
42
57
|
export declare function removeNewline(value: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Thêm ký tự vào đầu chuỗi cho đến khi đạt được độ dài mục tiêu
|
|
60
|
+
* @param str Chuỗi gốc
|
|
61
|
+
* @param targetLength Độ dài mục tiêu sau khi thêm ký tự
|
|
62
|
+
* @param padChar Ký tự dùng để thêm vào đầu chuỗi (mặc định là "0")
|
|
63
|
+
* @returns Chuỗi đã được thêm ký tự vào đầu nếu cần thiết
|
|
64
|
+
* @global
|
|
65
|
+
*/
|
|
66
|
+
export declare function padStart(str: string, targetLength: number, padChar?: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* Thêm ký tự vào cuối chuỗi cho đến khi đạt được độ dài mục tiêu
|
|
69
|
+
* @param str Chuỗi gốc
|
|
70
|
+
* @param targetLength Độ dài mục tiêu sau khi thêm ký tự
|
|
71
|
+
* @param padChar Ký tự dùng để thêm vào cuối chuỗi (mặc định là "0")
|
|
72
|
+
* @returns Chuỗi đã được thêm ký tự vào cuối nếu cần thiết
|
|
73
|
+
* @global
|
|
74
|
+
*/
|
|
75
|
+
export declare function padEnd(str: string, targetLength: number, padChar?: string): string;
|
|
43
76
|
/**
|
|
44
77
|
* Shuffles an array in place using the Fisher-Yates algorithm.
|
|
45
78
|
* @param array - Array to shuffle (mutated directly).
|
package/dist/esm/func.js
CHANGED
|
@@ -41,6 +41,30 @@ export function isEmpty(value) {
|
|
|
41
41
|
export function isNumber(value) {
|
|
42
42
|
return typeof value === "number" && Number.isFinite(value);
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Nếu giá trị của `value` không phải là null hoặc undefined thì lấy, ngược lại trả về `defaultValue`.
|
|
46
|
+
* @note Sử dụng thay cho cú pháp `??`. Nếu TS3.7 trở lên thì không cần dùng.
|
|
47
|
+
* @param value Giá trị cần kiểm tra
|
|
48
|
+
* @param defaultValue Giá trị mặc định trả về nếu `value` là null hoặc undefined
|
|
49
|
+
* @global
|
|
50
|
+
*/
|
|
51
|
+
export function nullish(value, defaultValue) {
|
|
52
|
+
return value !== null && value !== undefined ? value : defaultValue;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* JSON.parse với giá trị mặc định nếu có lỗi
|
|
56
|
+
* @param s giá trị JSON cần parse
|
|
57
|
+
* @param defaultValue giá trị mặc định trả về nếu có lỗi khi parse. Mặc định là null
|
|
58
|
+
* @returns any
|
|
59
|
+
*/
|
|
60
|
+
export function jsonParse(s, defaultValue = null) {
|
|
61
|
+
try {
|
|
62
|
+
return JSON.parse(s);
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
return defaultValue;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
44
68
|
/**
|
|
45
69
|
* Converts Vietnamese diacritics to their plain ASCII equivalents
|
|
46
70
|
* (e.g. `"Điều chỉnh"` -> `"Dieu chinh"`).
|
|
@@ -75,6 +99,40 @@ export function crlf2lf(value) {
|
|
|
75
99
|
export function removeNewline(value) {
|
|
76
100
|
return crlf2lf(value).trim().replace(/\n/g, "");
|
|
77
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Thêm ký tự vào đầu chuỗi cho đến khi đạt được độ dài mục tiêu
|
|
104
|
+
* @param str Chuỗi gốc
|
|
105
|
+
* @param targetLength Độ dài mục tiêu sau khi thêm ký tự
|
|
106
|
+
* @param padChar Ký tự dùng để thêm vào đầu chuỗi (mặc định là "0")
|
|
107
|
+
* @returns Chuỗi đã được thêm ký tự vào đầu nếu cần thiết
|
|
108
|
+
* @global
|
|
109
|
+
*/
|
|
110
|
+
export function padStart(str, targetLength, padChar = "0") {
|
|
111
|
+
str = String(str);
|
|
112
|
+
if (str.length >= targetLength || !padChar)
|
|
113
|
+
return str;
|
|
114
|
+
const padding = padChar
|
|
115
|
+
.repeat(Math.ceil((targetLength - str.length) / padChar.length))
|
|
116
|
+
.substring(0, targetLength - str.length);
|
|
117
|
+
return padding + str;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Thêm ký tự vào cuối chuỗi cho đến khi đạt được độ dài mục tiêu
|
|
121
|
+
* @param str Chuỗi gốc
|
|
122
|
+
* @param targetLength Độ dài mục tiêu sau khi thêm ký tự
|
|
123
|
+
* @param padChar Ký tự dùng để thêm vào cuối chuỗi (mặc định là "0")
|
|
124
|
+
* @returns Chuỗi đã được thêm ký tự vào cuối nếu cần thiết
|
|
125
|
+
* @global
|
|
126
|
+
*/
|
|
127
|
+
export function padEnd(str, targetLength, padChar = "0") {
|
|
128
|
+
str = String(str);
|
|
129
|
+
if (str.length >= targetLength || !padChar)
|
|
130
|
+
return str;
|
|
131
|
+
const padding = padChar
|
|
132
|
+
.repeat(Math.ceil((targetLength - str.length) / padChar.length))
|
|
133
|
+
.substring(0, targetLength - str.length);
|
|
134
|
+
return str + padding;
|
|
135
|
+
}
|
|
78
136
|
/**
|
|
79
137
|
* Shuffles an array in place using the Fisher-Yates algorithm.
|
|
80
138
|
* @param array - Array to shuffle (mutated directly).
|
|
@@ -94,10 +152,9 @@ export function shuffleArray(array) {
|
|
|
94
152
|
* @returns Array of the object's values.
|
|
95
153
|
*/
|
|
96
154
|
export function objectValueToArray(obj) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return arr;
|
|
155
|
+
if (obj === null || obj === undefined)
|
|
156
|
+
return [];
|
|
157
|
+
return Object.keys(obj).map((key) => obj[key]);
|
|
101
158
|
}
|
|
102
159
|
/**
|
|
103
160
|
* Groups list items by the key returned from `fn`, similar to Lodash's
|
|
@@ -134,15 +191,18 @@ export function removeByKey(objectOrArray, keys) {
|
|
|
134
191
|
return objectOrArray.map((item) => typeof item === "object" && item !== null ? removeByKey(item, keys) : item);
|
|
135
192
|
}
|
|
136
193
|
if (typeof objectOrArray === "object" && objectOrArray !== null) {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
return
|
|
142
|
-
|
|
143
|
-
|
|
194
|
+
const source = objectOrArray;
|
|
195
|
+
const result = {};
|
|
196
|
+
Object.keys(source).forEach((key) => {
|
|
197
|
+
if (keys.includes(key))
|
|
198
|
+
return;
|
|
199
|
+
const value = source[key];
|
|
200
|
+
result[key] =
|
|
201
|
+
Array.isArray(value) || (typeof value === "object" && value !== null)
|
|
202
|
+
? removeByKey(value, keys)
|
|
203
|
+
: value;
|
|
144
204
|
});
|
|
145
|
-
return
|
|
205
|
+
return result;
|
|
146
206
|
}
|
|
147
207
|
// Primitives are returned as-is
|
|
148
208
|
return objectOrArray;
|
|
@@ -177,22 +237,18 @@ export function removeEmptyValue(objectOrArray, options = {}) {
|
|
|
177
237
|
return result;
|
|
178
238
|
}
|
|
179
239
|
if (typeof objectOrArray === "object" && objectOrArray !== null) {
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}),
|
|
190
|
-
];
|
|
240
|
+
const source = objectOrArray;
|
|
241
|
+
const result = {};
|
|
242
|
+
Object.keys(source).forEach((key) => {
|
|
243
|
+
const rawValue = source[key];
|
|
244
|
+
const value = Array.isArray(rawValue) || (typeof rawValue === "object" && rawValue !== null)
|
|
245
|
+
? removeEmptyValue(rawValue, { removeNull, removeUndefined, removeEmptyString })
|
|
246
|
+
: rawValue;
|
|
247
|
+
if (!shouldRemove(value)) {
|
|
248
|
+
result[key] = value;
|
|
191
249
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
.filter(([, value]) => !shouldRemove(value));
|
|
195
|
-
return Object.fromEntries(entries);
|
|
250
|
+
});
|
|
251
|
+
return result;
|
|
196
252
|
}
|
|
197
253
|
return objectOrArray;
|
|
198
254
|
}
|