1.2.0 • Published 10 months ago

@tkku/objsnaketocamelcase v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Installation

yarn add @tkku/objsnaketocamelcase

Usage

/** size is less than 200 B */
import { objSnakeToCamelCase } from '@tkku/objsnaketocamelcase'

objSnakeToCamelCase   (object: Record<string, any>, excludeKeys?: string | Array<string>) => object | null
objSnakeToCamelCase<T>(object: Record<string, any>, excludeKeys?: string | Array<string>) => T | null
// returns null if object is not of an object type (non-array)

Converting keys

/** converts nested keys */
({ key_1: '', key_2: { sub_key: '' } }) => 
 { key1:  '', key2:  { subKey:  '' } }

/** converts an array inside an object */
({ key_1: '', key_2: [{ sub_array_key: '' }] }) =>
 { key1:  '', key2:  [{ subArrayKey:  ''  }] }

Excluding keys from mapping

/** Pass single key to exclude */
({ some_key: '', key_to_exclude: '' }, 'key_to_exclude') =>
 { someKey:  '', key_to_exclude: '' }

/** Pass an array of keys */
({ some_key: '', key_to_exclude: '' }, ['some_key', 'key_to_exclude']) =>
 { some_key: '', key_to_exclude: '' }

/** Pass a nested key */
({ some_object: { nested_key: '' }, nested_key: '' }, 'some_object.nested_key') =>
 { someObject:  { nested_key: '' }, nestedKey:  '' }

/** If you want to exclude top level key without touching the nested one, pass a key with the leading dot */
({ key_key: '', nested_obj: { key_key: '' } }, '.key_key') =>
 { key_key: '', nestedObj:  { keyKey:  '' } }
1.2.0

10 months ago

1.1.3

10 months ago

1.1.2

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago