We currently have these function utils being used internally in the library but they were developed because the ones that tn-utils had available were not working properly for our use case.
|
//TODO: this should probably move to tn-utils but will keep it here for a quick release |
|
export const objectToCamelCaseArr = <T extends object>(obj: T): CamelCasedPropertiesDeep<T> => { |
|
if (typeof obj !== "object" || obj === null) return obj |
|
if (Array.isArray(obj)) return obj.map((o) => objectToCamelCaseArr(o)) as CamelCasedPropertiesDeep<T> |
|
const entries = Object.entries(obj) |
|
const newEntries = [] |
|
for (const [k, v] of entries) { |
|
newEntries.push([toCamelCase(k), objectToCamelCaseArr(v)]) |
|
} |
|
return Object.fromEntries(newEntries) |
|
} |
|
export const objectToSnakeCaseArr = <T extends object>(obj: T): SnakeCasedPropertiesDeep<T> => { |
|
if (typeof obj !== "object" || obj === null) return obj |
|
if (Array.isArray(obj)) return obj.map((o) => objectToSnakeCaseArr(o)) as SnakeCasedPropertiesDeep<T> |
|
const entries = Object.entries(obj) |
|
const newEntries = [] |
|
for (const [k, v] of entries) { |
|
newEntries.push([toSnakeCase(k), objectToSnakeCaseArr(v)]) |
|
} |
|
return Object.fromEntries(newEntries) |
|
} |
Move these to https://github.com/thinknimble/tn-utils
We currently have these function utils being used internally in the library but they were developed because the ones that
tn-utilshad available were not working properly for our use case.tn-models-fp/src/utils/api/api.ts
Lines 20 to 40 in a9a123d
Move these to https://github.com/thinknimble/tn-utils