Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/14f3v/obj-to-camel
This is a TypeScript function that converts object keys from snake_case to camelCase.
https://github.com/14f3v/obj-to-camel
camelcase conversion javascript library snakecase-to-camelcase typescript
Last synced: 11 days ago
JSON representation
This is a TypeScript function that converts object keys from snake_case to camelCase.
- Host: GitHub
- URL: https://github.com/14f3v/obj-to-camel
- Owner: 14f3v
- License: mit
- Created: 2024-03-02T11:48:27.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-04-10T17:28:07.000Z (7 months ago)
- Last Synced: 2024-10-05T23:21:29.371Z (about 1 month ago)
- Topics: camelcase, conversion, javascript, library, snakecase-to-camelcase, typescript
- Language: TypeScript
- Homepage:
- Size: 43 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# obj-to-camel
This is a TypeScript function that converts object keys from snake_case to camelCase.## Installation
You can install this function via bun/yarn/npm:
incase of using [bun.sh](https://bun.sh)
```bash
bun add git+https://github.com/14f3v/obj-to-camel.git
```incase of using yarn
```bash
yarn add git+https://github.com/14f3v/obj-to-camel.git
```incase of using npm
```bash
npm install git+https://github.com/14f3v/obj-to-camel.git
```## Usage
```typescript
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",
}
*/
```
### Support for nested object
```typescript
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 Signature
```typescript
function keysToCamel>(
obj: T
): { [K in keyof T as CamelCase]: T[K] };
```
This function takes an object with string keys and returns a new object with camelCase keys.## Contributing
Contributions are welcome! Feel free to submit issues and pull requests.### Feedback and Suggestions
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.## License
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.