-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40463f5
commit b9466c4
Showing
1 changed file
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,81 @@ | ||
# Change Every Case | ||
|
||
Simple library inspired by `change-case` and `change-case/keys`. | ||
A simple library inspired by [`change-case`][1] and its _keys_ functions, | ||
designed to change the casing of object keys. It is useful, for example, | ||
for converting objects from the REST standard to JavaScript best practices, | ||
and vice versa. | ||
|
||
It works like change-case functions but it accepts anything in first parameter. | ||
It functions similarly to `change-case`, but it accepts any type of input | ||
as the first parameter. The options for the second parameter are exactly | ||
the same as those for [`change-case`][1]. | ||
|
||
The options in second parameter and exactly the same as for `change-case`. | ||
|
||
See `index.test.ts` for examples. | ||
## Install | ||
|
||
``` | ||
npm i change-every-case | ||
``` | ||
|
||
## Examples | ||
|
||
Format obects: | ||
|
||
```ts | ||
import { camelKeys } from 'change-every-case'; | ||
|
||
const input = { | ||
lorem_ipsum: 'lorem_ipsum', | ||
hello_planets: [ | ||
{ | ||
planet_earth: 'Hello c', | ||
planet_mars: 'Hello Mars', | ||
} | ||
], | ||
value: 3, | ||
}; | ||
|
||
const result = camelKeys(input); | ||
|
||
// result: | ||
// { | ||
// loremIpsum: 'lorem_ipsum', | ||
// helloPlanets: [ | ||
// { | ||
// planetEarth: 'Hello Hello ', | ||
// planetMars: 'Hello Mars', | ||
// } | ||
// ], | ||
// value: 3, | ||
// }; | ||
``` | ||
|
||
You can also pass arrays: | ||
|
||
```ts | ||
import { camelKeys } from 'change-every-case'; | ||
|
||
const inputArray = [ | ||
{ hello_world: 3 }, | ||
{ foo_bar: 3 } | ||
]; | ||
|
||
const result = camelKeys(inputArray); | ||
|
||
// result: | ||
// [ | ||
// { helloWorld: 3 }, | ||
// { fooBar: 3 } | ||
// ]; | ||
``` | ||
|
||
## Heads up! | ||
|
||
- The passed object or array can be deep up to 1000 levels. | ||
- If you would pass string or number it will be returned as is. | ||
- Date objects are not changed. | ||
|
||
## LICENSE | ||
|
||
[MIT](./LICENSE) of course :) | ||
|
||
[1]: https://www.npmjs.com/package/change-case |