2024-06-14 16:22:19: merge [main:0f6b5e91772104b617d4a0d9ddf14a9f3f8b806e];

This commit is contained in:
txix committed 2024-06-14 16:22:19 +03:00
1 parent 031a92db3f
commit 151be0e635
25 files changed
+858 -141

No files matched your search

+33 -1
View File
@@ -16,4 +16,36 @@ const sortObject = (obj: any): any => {
return sorted
}
export { sortObject }
function isEmpty(value: unknown): boolean {
return value === undefined ||
value === null ||
(typeof value === 'string' && value.trim() === '') ||
(typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0)
}
function cleanEmptyParamsObject(obj: any): any {
if (typeof obj !== 'object' || obj === null) {
return obj
}
if (Array.isArray(obj)) {
return obj
.map(cleanEmptyParamsObject)
.filter(item => !isEmpty(item))
}
return Object.keys(obj).reduce((acc, key) => {
if (key === 'data') {
acc[key] = obj[key]
} else {
const value = cleanEmptyParamsObject(obj[key])
if (!isEmpty(value)) {
acc[key] = value
}
}
return acc
}, {} as Record<string, unknown>)
}
export { sortObject, cleanEmptyParamsObject }