Skip to content

Commit

Permalink
Improve README
Browse files Browse the repository at this point in the history
  • Loading branch information
marcingajda committed Mar 31, 2024
1 parent c295112 commit b5d47ab
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 29 deletions.
82 changes: 54 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ 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 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].


## Install

```
Expand All @@ -18,34 +13,43 @@ npm i change-every-case

## Examples

Format objects:
You can use this library to change object keys:

```ts
import { dotKeys } from 'change-every-case';

const result = dotKeys({ hello_world: 'Lorem Ipsum' });

// { 'hello.world': 'Lorem Ipsum }
```

You can also work with nested objects containing arrays and other values:

```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,
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,
// loremIpsum: 'lorem_ipsum',
// helloPlanets: [
// {
// planetEarth: 'Hello Hello ',
// planetMars: 'Hello Mars',
// }
// ],
// value: 3,
// };
```

Expand All @@ -55,19 +59,41 @@ You can also pass arrays:
import { camelKeys } from 'change-every-case';

const inputArray = [
{ hello_world: 3 },
{ foo_bar: 3 }
{ hello_world: 3 },
{ foo_bar: 3 }
];

const result = camelKeys(inputArray);

// result:
// [
// { helloWorld: 3 },
// { fooBar: 3 }
// { helloWorld: 3 },
// { fooBar: 3 }
// ];
```

## Supported formats

| **Funtion** | **Key example** |
|-----------------|-----------------|
| noKeys | hello world |
| camelKeys | helloWorld |
| pascalKeys | HelloWorld |
| pascalSnakeKeys | Hello_World |
| capitalKeys | Hello World |
| constantKeys | HELLO_WORLD |
| dotKeys | hello.world |
| kebabKeys | hello-world |
| pathKeys | hello/world |
| sentenceKeys | Hello world |
| snakeKeys | hello_world |
| trainKeys | Hello-World |

## Options

The functions are similar to those in `change-case`, but they accept any
type of input as the first parameter. The options for the second parameter
are exactly the same as those for [`change-case`][1].

## Heads up!

- The passed object or array can be deep up to 1000 levels.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "change-every-case",
"version": "0.2.1",
"version": "0.2.2",
"description": "Recursively change object keys case",
"keywords": [
"change",
Expand Down

0 comments on commit b5d47ab

Please sign in to comment.