Skip to content

Move casing utils to tn-utils instead of having them in tn-models library #194

@lakardion

Description

@lakardion

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions