From 885d267a338a479422e7ba855d15eca9ac1e5a76 Mon Sep 17 00:00:00 2001 From: ilyevskii Date: Fri, 5 Jul 2024 12:34:29 +0300 Subject: [PATCH 1/3] feat: add flattenObject util --- template/apps/api/src/utils/object.util.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 template/apps/api/src/utils/object.util.ts diff --git a/template/apps/api/src/utils/object.util.ts b/template/apps/api/src/utils/object.util.ts new file mode 100644 index 00000000..71427f5c --- /dev/null +++ b/template/apps/api/src/utils/object.util.ts @@ -0,0 +1,10 @@ +import _ from 'lodash'; + +const flattenObject = (obj: object, path: string[] = []): Record => + !_.isObject(obj) + ? { [path.join('.')]: obj } + : Object.entries(obj).reduce((cur, [key, value]) => _.merge(cur, flattenObject(value, [...path, key])), {}); + +export default { + flattenObject, +}; From d940d0523f31119e938636ea3ad6746e9189ac18 Mon Sep 17 00:00:00 2001 From: ilyevskii Date: Fri, 5 Jul 2024 13:43:10 +0300 Subject: [PATCH 2/3] feat: add imports --- template/apps/api/src/utils/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/template/apps/api/src/utils/index.ts b/template/apps/api/src/utils/index.ts index f4b3c71d..e0535ebd 100644 --- a/template/apps/api/src/utils/index.ts +++ b/template/apps/api/src/utils/index.ts @@ -1,8 +1,9 @@ import * as caseUtil from './case.util'; import configUtil from './config.util'; +import objectUtil from './object.util'; import promiseUtil from './promise.util'; import routeUtil from './routes.util'; import securityUtil from './security.util'; import stringUtil from './string.util'; -export { caseUtil, configUtil, promiseUtil, routeUtil, securityUtil, stringUtil }; +export { caseUtil, configUtil, objectUtil, promiseUtil, routeUtil, securityUtil, stringUtil }; From 472c34ccd1c66769f93000cfb556648bd87d78a3 Mon Sep 17 00:00:00 2001 From: ilyevskii Date: Tue, 9 Jul 2024 16:08:44 +0300 Subject: [PATCH 3/3] refactor: flip condition --- template/apps/api/src/utils/object.util.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/template/apps/api/src/utils/object.util.ts b/template/apps/api/src/utils/object.util.ts index 71427f5c..7178079d 100644 --- a/template/apps/api/src/utils/object.util.ts +++ b/template/apps/api/src/utils/object.util.ts @@ -1,9 +1,9 @@ import _ from 'lodash'; const flattenObject = (obj: object, path: string[] = []): Record => - !_.isObject(obj) - ? { [path.join('.')]: obj } - : Object.entries(obj).reduce((cur, [key, value]) => _.merge(cur, flattenObject(value, [...path, key])), {}); + _.isObject(obj) + ? Object.entries(obj).reduce((cur, [key, value]) => _.merge(cur, flattenObject(value, [...path, key])), {}) + : { [path.join('.')]: obj }; export default { flattenObject,