camelcase-keys
Advanced tools
Comparing version 9.0.0 to 9.1.0
@@ -44,2 +44,3 @@ import type {CamelCase, PascalCase} from 'type-fest'; | ||
IsPascalCase extends boolean = false, | ||
PreserveConsecutiveUppercase extends boolean = false, | ||
Exclude extends readonly unknown[] = EmptyTuple, | ||
@@ -56,2 +57,3 @@ StopPaths extends readonly string[] = EmptyTuple, | ||
IsPascalCase, | ||
PreserveConsecutiveUppercase, | ||
Exclude, | ||
@@ -69,3 +71,3 @@ StopPaths | ||
? PascalCase<P> | ||
: CamelCase<P>]: [IsInclude<StopPaths, AppendPath<Path, P & string>>] extends [ | ||
: CamelCase<P, {preserveConsecutiveUppercase: PreserveConsecutiveUppercase}>]: [IsInclude<StopPaths, AppendPath<Path, P & string>>] extends [ | ||
true, | ||
@@ -80,2 +82,3 @@ ] | ||
IsPascalCase, | ||
PreserveConsecutiveUppercase, | ||
Exclude, | ||
@@ -91,7 +94,34 @@ StopPaths, | ||
type Options = { | ||
export type Options = { | ||
/** | ||
Exclude keys from being camel-cased. | ||
If this option can be statically determined, it's recommended to add `as const` to it. | ||
@default [] | ||
*/ | ||
readonly exclude?: ReadonlyArray<string | RegExp>; | ||
/** | ||
Recurse nested objects and objects in arrays. | ||
@default false | ||
@example | ||
``` | ||
import camelcaseKeys from 'camelcase-keys'; | ||
const object = { | ||
'foo-bar': true, | ||
nested: { | ||
unicorn_rainbow: true | ||
} | ||
}; | ||
camelcaseKeys(object, {deep: true}); | ||
//=> {fooBar: true, nested: {unicornRainbow: true}} | ||
camelcaseKeys(object, {deep: false}); | ||
//=> {fooBar: true, nested: {unicorn_rainbow: true}} | ||
``` | ||
*/ | ||
@@ -101,11 +131,38 @@ readonly deep?: boolean; | ||
/** | ||
Exclude keys from being camel-cased. | ||
Uppercase the first character: `bye-bye` → `ByeBye` | ||
If this option can be statically determined, it's recommended to add `as const` to it. | ||
@default false | ||
@default [] | ||
@example | ||
``` | ||
import camelcaseKeys from 'camelcase-keys'; | ||
camelcaseKeys({'foo-bar': true}, {pascalCase: true}); | ||
//=> {FooBar: true} | ||
camelcaseKeys({'foo-bar': true}, {pascalCase: false}); | ||
//=> {fooBar: true} | ||
```` | ||
*/ | ||
readonly exclude?: ReadonlyArray<string | RegExp>; | ||
readonly pascalCase?: boolean; | ||
/** | ||
Preserve consecutive uppercase characters: `foo-BAR` → `FooBAR` | ||
@default false | ||
@example | ||
``` | ||
import camelcaseKeys from 'camelcase-keys'; | ||
camelcaseKeys({'foo-BAR': true}, {preserveConsecutiveUppercase: true}); | ||
//=> {fooBAR: true} | ||
camelcaseKeys({'foo-BAR': true}, {preserveConsecutiveUppercase: false}); | ||
//=> {fooBar: true} | ||
```` | ||
*/ | ||
readonly preserveConsecutiveUppercase?: boolean; | ||
/** | ||
Exclude children at the given object paths in dot-notation from being camel-cased. For example, with an object like `{a: {b: '🦄'}}`, the object path to reach the unicorn is `'a.b'`. | ||
@@ -121,3 +178,3 @@ | ||
camelcaseKeys({ | ||
const object = { | ||
a_b: 1, | ||
@@ -130,3 +187,5 @@ a_c: { | ||
} | ||
}, { | ||
}; | ||
camelcaseKeys(object, { | ||
deep: true, | ||
@@ -149,9 +208,2 @@ stopPaths: [ | ||
readonly stopPaths?: readonly string[]; | ||
/** | ||
Uppercase the first character as in `bye-bye` → `ByeBye`. | ||
@default false | ||
*/ | ||
readonly pascalCase?: boolean; | ||
}; | ||
@@ -175,12 +227,2 @@ | ||
//=> [{fooBar: true}, {barFoo: false}] | ||
camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true}); | ||
//=> {fooBar: true, nested: {unicornRainbow: true}} | ||
camelcaseKeys({a_b: 1, a_c: {c_d: 1, c_e: {e_f: 1}}}, {deep: true, stopPaths: ['a_c.c_e']}), | ||
//=> {aB: 1, aC: {cD: 1, cE: {e_f: 1}}} | ||
// Convert object keys to pascal case | ||
camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true, pascalCase: true}); | ||
//=> {FooBar: true, Nested: {UnicornRainbow: true}} | ||
``` | ||
@@ -210,4 +252,5 @@ | ||
WithDefault<OptionsType['pascalCase'], false>, | ||
WithDefault<OptionsType['preserveConsecutiveUppercase'], false>, | ||
WithDefault<OptionsType['exclude'], EmptyTuple>, | ||
WithDefault<OptionsType['stopPaths'], EmptyTuple> | ||
>; |
@@ -35,2 +35,3 @@ import mapObject from 'map-obj'; | ||
deep = false, | ||
preserveConsecutiveUppercase = false, | ||
} = options; | ||
@@ -55,3 +56,3 @@ | ||
} else { | ||
const returnValue = camelCase(key, {pascalCase, locale: false}); | ||
const returnValue = camelCase(key, {pascalCase, locale: false, preserveConsecutiveUppercase}); | ||
@@ -58,0 +59,0 @@ if (key.length < 100) { // Prevent abuse |
{ | ||
"name": "camelcase-keys", | ||
"version": "9.0.0", | ||
"version": "9.1.0", | ||
"description": "Convert object keys to camel case", | ||
@@ -59,3 +59,3 @@ "license": "MIT", | ||
"quick-lru": "^6.1.1", | ||
"type-fest": "^4.2.0" | ||
"type-fest": "^4.3.2" | ||
}, | ||
@@ -65,3 +65,3 @@ "devDependencies": { | ||
"matcha": "^0.7.0", | ||
"tsd": "^0.28.1", | ||
"tsd": "^0.29.0", | ||
"xo": "^0.56.0" | ||
@@ -68,0 +68,0 @@ }, |
@@ -23,12 +23,2 @@ # camelcase-keys | ||
//=> [{fooBar: true}, {barFoo: false}] | ||
camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true}); | ||
//=> {fooBar: true, nested: {unicornRainbow: true}} | ||
camelcaseKeys({a_b: 1, a_c: {c_d: 1, c_e: {e_f: 1}}}, {deep: true, stopPaths: ['a_c.c_e']}), | ||
//=> {aB: 1, aC: {cD: 1, cE: {e_f: 1}}} | ||
// Convert object keys to pascal case | ||
camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true, pascalCase: true}); | ||
//=> {FooBar: true, Nested: {UnicornRainbow: true}} | ||
``` | ||
@@ -68,2 +58,60 @@ | ||
##### deep | ||
Type: `boolean`\ | ||
Default: `false` | ||
Recurse nested objects and objects in arrays. | ||
```js | ||
import camelcaseKeys from 'camelcase-keys'; | ||
const object = { | ||
'foo-bar': true, | ||
nested: { | ||
unicorn_rainbow: true | ||
} | ||
}; | ||
camelcaseKeys(object, {deep: true}); | ||
//=> {fooBar: true, nested: {unicornRainbow: true}} | ||
camelcaseKeys(object, {deep: false}); | ||
//=> {fooBar: true, nested: {unicorn_rainbow: true}} | ||
``` | ||
##### pascalCase | ||
Type: `boolean`\ | ||
Default: `false` | ||
Uppercase the first character: `bye-bye` → `ByeBye` | ||
```js | ||
import camelcaseKeys from 'camelcase-keys'; | ||
camelcaseKeys({'foo-bar': true}, {pascalCase: true}); | ||
//=> {FooBar: true} | ||
camelcaseKeys({'foo-bar': true}, {pascalCase: false}); | ||
//=> {fooBar: true} | ||
```` | ||
##### preserveConsecutiveUppercase | ||
Type: `boolean`\ | ||
Default: `false` | ||
Preserve consecutive uppercase characters: `foo-BAR` → `FooBAR` | ||
```js | ||
import camelcaseKeys from 'camelcase-keys'; | ||
camelcaseKeys({'foo-BAR': true}, {preserveConsecutiveUppercase: true}); | ||
//=> {fooBAR: true} | ||
camelcaseKeys({'foo-BAR': true}, {preserveConsecutiveUppercase: false}); | ||
//=> {fooBar: true} | ||
```` | ||
##### stopPaths | ||
@@ -74,6 +122,10 @@ | ||
Exclude children at the given object paths in dot-notation from being camel-cased. For example, with an object like `{a: {b: '🦄'}}`, the object path to reach the unicorn is `'a.b'`. | ||
Exclude children at the given object paths in dot-notation from being camel-cased. | ||
For example, with an object like `{a: {b: '🦄'}}`, the object path to reach the unicorn is `'a.b'`. | ||
```js | ||
camelcaseKeys({ | ||
import camelcaseKeys from 'camelcase-keys'; | ||
const object = { | ||
a_b: 1, | ||
@@ -86,3 +138,5 @@ a_c: { | ||
} | ||
}, { | ||
}; | ||
camelcaseKeys(object, { | ||
deep: true, | ||
@@ -106,16 +160,2 @@ stopPaths: [ | ||
##### deep | ||
Type: `boolean`\ | ||
Default: `false` | ||
Recurse nested objects and objects in arrays. | ||
##### pascalCase | ||
Type: `boolean`\ | ||
Default: `false` | ||
Uppercase the first character as in `bye-bye` → `ByeBye`. | ||
## Related | ||
@@ -122,0 +162,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12362
264
161
Updatedtype-fest@^4.3.2