Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lakardion opened this issue May 29, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@lakardion
Copy link
Member

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

@lakardion lakardion added the enhancement New feature or request label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant