This is a TypeScript function that converts object keys from snake_case to camelCase.
You can install this function via bun/yarn/npm:
incase of using bun.sh
bun add git+https://github.com/14f3v/obj-to-camel.git
incase of using yarn
yarn add git+https://github.com/14f3v/obj-to-camel.git
incase of using npm
npm install git+https://github.com/14f3v/obj-to-camel.git
import objToCamel from '@14f3v/obj-to-camel';
const originalObject = {
FULL_NAME: "foo",
FAMILY_NAME: "bar",
};
const camelCasedObject = objToCamel(originalObject);
console.log(camelCasedObject);
/* // ? return object would be
camelCasedObject: {
fullName: "foo",
familyName: "bar",
}
*/
import objToCamel from '@14f3v/obj-to-camel';
const originalObject = {
FULL_NAME: "foo",
FAMILY_NAME: "bar",
IDENTITY: {
HOLDER_NAME: "foo",
HOLDER_SURNAME: "bar",
},
};
const camelCasedObject = objToCamel(originalObject);
console.log(camelCasedObject);
/* // ? return object would be
camelCasedObject: {
fullName: "foo",
familyName: "bar",
identity: {
holderName: "foo",
holderSurname: "bar",
},
}
function keysToCamel<T extends Record<string, any>>(
obj: T
): { [K in keyof T as CamelCase<K & string>]: T[K] };
This function takes an object with string keys and returns a new object with camelCase keys.
Contributions are welcome! Feel free to submit issues and pull requests.
If you have any questions, feedback, or suggestions, please open an issue on the repository. We're open to discussions and appreciate any input you may have.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to customize the content according to your project's needs and guidelines. A clear and welcoming contribution section can help foster a collaborative and inclusive community around your project.