From b5d47ab6e1445ba3ece393ebfed5b6c92032ee16 Mon Sep 17 00:00:00 2001 From: Marcin Gajda Date: Sun, 31 Mar 2024 20:03:33 +0200 Subject: [PATCH] Improve README --- README.md | 82 ++++++++++++++++++++++++++++++++++------------------ package.json | 2 +- 2 files changed, 55 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 0b38b11..861afdb 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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, // }; ``` @@ -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. diff --git a/package.json b/package.json index 51368dd..91739de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "change-every-case", - "version": "0.2.1", + "version": "0.2.2", "description": "Recursively change object keys case", "keywords": [ "change",