From simple to complicated examples.
console.log(jsConvert.toCamelCase('param-case')); // paramCase
console.log(jsConvert.toCamelCase('camelCase')); // camelCase
console.log(jsConvert.toCamelCase('Title Case')); // titleCase
// All output are `null`
console.log(jsConvert.camelKeys(undefined));
console.log(jsConvert.camelKeys(null));
console.log(jsConvert.camelKeys(1));
console.log(jsConvert.camelKeys('abc'));
console.log(jsConvert.camelKeys([1, 2, 3]));
jsConvert.camelKeys({
camelCase: 1,
UPPERCASE: 2,
lowercase: 3,
snake_case: 4,
PascalCase: 5,
'Title Case': 6,
'dot.case': 7,
'param-case': 8,
'Sentence case': 9,
'path/case': 10,
'Header-Case': 11
});
{
camelCase: 1,
uppercase: 2,
lowercase: 3,
snakeCase: 4,
pascalCase: 5,
titleCase: 6,
dotCase: 7,
paramCase: 8,
sentenceCase: 9,
pathCase: 10,
headerCase: 11
}
console.log(jsConvert.toSnakeCase('param-case')); // param_case
console.log(jsConvert.toSnakeCase('camelCase')); // camel_case
console.log(jsConvert.toSnakeCase('Title Case')); // title_case
// All output are `null`
console.log(jsConvert.snakeKeys(undefined));
console.log(jsConvert.snakeKeys(null));
console.log(jsConvert.snakeKeys(1));
console.log(jsConvert.snakeKeys('abc'));
console.log(jsConvert.snakeKeys([1, 2, 3]));
jsConvert.snakeKeys({
camelCase: 1,
UPPERCASE: 2,
lowercase: 3,
snake_case: 4,
PascalCase: 5,
'Title Case': 6,
'dot.case': 7,
'param-case': 8,
'Sentence case': 9,
'path/case': 10,
'Header-Case': 11
});
{
camel_case: 1,
uppercase: 2,
lowercase: 3,
snake_case: 4,
pascal_case: 5,
title_case: 6,
dot_case: 7,
param_case: 8,
sentence_case: 9,
path_case: 10,
header_case: 11
}
console.log(jsConvert.toPascalCase('param-case')); // ParamCase
console.log(jsConvert.toPascalCase('camelCase')); // CamelCase
console.log(jsConvert.toPascalCase('Title Case')); // TitleCase
// All output are `null`
console.log(jsConvert.pascalKeys(undefined));
console.log(jsConvert.pascalKeys(null));
console.log(jsConvert.pascalKeys(1));
console.log(jsConvert.pascalKeys('abc'));
console.log(jsConvert.pascalKeys([1, 2, 3]));
jsConvert.pascalKeys({
camelCase: 1,
UPPERCASE: 2,
lowercase: 3,
snake_case: 4,
PascalCase: 5,
'Title Case': 6,
'dot.case': 7,
'param-case': 8,
'Sentence case': 9,
'path/case': 10,
'Header-Case': 11
});
{
CamelCase: 1,
Uppercase: 2,
Lowercase: 3,
SnakeCase: 4,
PascalCase: 5,
TitleCase: 6,
DotCase: 7,
ParamCase: 8,
SentenceCase: 9,
PathCase: 10,
HeaderCase: 11
}
console.log(jsConvert.toDotCase('param-case')); // param.case
console.log(jsConvert.toDotCase('camelCase')); // camel.case
console.log(jsConvert.toDotCase('Title Case')); // title.case
console.log(jsConvert.toPathCase('param-case')); // param/case
console.log(jsConvert.toPathCase('camelCase')); // camel/case
console.log(jsConvert.toPathCase('Title Case')); // title/case
console.log(jsConvert.toTextCase('param-case')); // param case
console.log(jsConvert.toTextCase('camelCase')); // camel case
console.log(jsConvert.toTextCase('Title Case')); // title case
console.log(jsConvert.toSentenceCase('param-case')); // Param case
console.log(jsConvert.toSentenceCase('camelCase')); // Camel case
console.log(jsConvert.toSentenceCase('Title Case')); // Title case
console.log(jsConvert.toHeaderCase('param-case')); // Param Case
console.log(jsConvert.toHeaderCase('camelCase')); // Camel Case
console.log(jsConvert.toHeaderCase('Title Case')); // Title Case
console.log(jsConvert.toLowerCase('param-case')); // param-case
console.log(jsConvert.toLowerCase('Title Case')); // title case
// All output are `null`
console.log(jsConvert.lowerKeys(undefined));
console.log(jsConvert.lowerKeys(null));
console.log(jsConvert.lowerKeys(1));
console.log(jsConvert.lowerKeys('abc'));
console.log(jsConvert.lowerKeys([1, 2, 3]));
jsConvert.lowerKeys({
camelCase: 1,
UPPERCASE: 2,
lowercase: 3,
snake_case: 4,
PascalCase: 5,
'Title Case': 6,
'dot.case': 7,
'param-case': 8,
'Sentence case': 9,
'path/case': 10,
'Header-Case': 11
});
{
camelcase: 1,
uppercase: 2,
lowercase: 3,
snake_case: 4,
pascalcase: 5,
'title case': 6,
'dot.case': 7,
'param-case': 8,
'sentence case': 9,
'path/case': 10,
'header-case': 11
}
console.log(jsConvert.toUpperCase('param-case')); // PARAM-CASE
console.log(jsConvert.toUpperCase('Title Case')); // TITLE CASE
// All output are `null`
console.log(jsConvert.upperKeys(undefined));
console.log(jsConvert.upperKeys(null));
console.log(jsConvert.upperKeys(1));
console.log(jsConvert.upperKeys('abc'));
console.log(jsConvert.upperKeys([1, 2, 3]));
jsConvert.upperKeys({
camelCase: 1,
UPPERCASE: 2,
lowercase: 3,
snake_case: 4,
PascalCase: 5,
'Title Case': 6,
'dot.case': 7,
'param-case': 8,
'Sentence case': 9,
'path/case': 10,
'Header-Case': 11
});
{
CAMELCASE: 1,
UPPERCASE: 2,
LOWERCASE: 3,
SNAKE_CASE: 4,
PASCALCASE: 5,
'TITLE CASE': 6,
'DOT.CASE': 7,
'PARAM-CASE': 8,
'SENTENCE CASE': 9,
'PATH/CASE': 10,
'HEADER-CASE': 11
}
console.log(jsConvert.toCamelCase('')); // => ''
console.log(jsConvert.toSnakeCase(null)); // => ''
console.log(jsConvert.toPascalCase(undefined)); // => ''
// Complicated values
const str = '!@#$ -- Hello___world ..<>| \\ 123_ _456 &\l sn_ca - cmCa - PcCa - dot.ca - txt ca - Sen ca - Hd Ca %^$^%&';
console.log(jsConvert.toCamelCase(str)); // => 'helloWorld123456LSnCaCmCaPcCaDotCaTxtCaSenCaHdCa'
console.log(jsConvert.toPascalCase(str)); // => 'HelloWorld123456LSnCaCmCaPcCaDotCaTxtCaSenCaHdCa'
console.log(jsConvert.toSnakeCase(str)); // => 'hello_world_123_456_l_sn_ca_cm_ca_pc_ca_dot_ca_txt_ca_sen_ca_hd_ca'
console.log(jsConvert.toDotCase(str)); // => 'hello.world.123.456.l.sn.ca.cm.ca.pc.ca.dot.ca.txt.ca.sen.ca.hd.ca'
console.log(jsConvert.toPathCase(str)); // => 'hello/world/123/456/l/sn/ca/cm/ca/pc/ca/dot/ca/txt/ca/sen/ca/hd/ca'
console.log(jsConvert.toTextCase(str)); // => 'hello world 123 456 l sn ca cm ca pc ca dot ca txt ca sen ca hd ca'
console.log(jsConvert.toSentenceCase(str)); // => 'Hello world 123 456 l sn ca cm ca pc ca dot ca txt ca sen ca hd ca'
console.log(jsConvert.toHeaderCase(str)); // => 'Hello World 123 456 L Sn Ca Cm Ca Pc Ca Dot Ca Txt Ca Sen Ca Hd Ca'
const core = {
camelCase: 1,
UPPERCASE: 2,
lowercase: 3,
snake_case: 4,
PascalCase: 5,
'Title Case': 6,
'dot.case': 7,
'param-case': 8,
'Sentence case': 9,
'path/case': 10,
'Header-Case': 11
};
const obj = {
...core,
lv1: {
...core,
lv2: {
...core
}
}
};
const res = jsConvert.upperKeys(obj, { recursive: true });
console.log(JSON.stringify(res));
const res = jsConvert.pascalKeys(obj, { recursive: true });
console.log(JSON.stringify(res));
{
"CAMELCASE": 1,
"UPPERCASE": 2,
"LOWERCASE": 3,
"SNAKE_CASE": 4,
"PASCALCASE": 5,
"TITLE CASE": 6,
"DOT.CASE": 7,
"PARAM-CASE": 8,
"SENTENCE CASE": 9,
"PATH/CASE": 10,
"HEADER-CASE": 11,
"LV1": {
"CAMELCASE": 1,
"UPPERCASE": 2,
"LOWERCASE": 3,
"SNAKE_CASE": 4,
"PASCALCASE": 5,
"TITLE CASE": 6,
"DOT.CASE": 7,
"PARAM-CASE": 8,
"SENTENCE CASE": 9,
"PATH/CASE": 10,
"HEADER-CASE": 11,
"LV2": {
"CAMELCASE": 1,
"UPPERCASE": 2,
"LOWERCASE": 3,
"SNAKE_CASE": 4,
"PASCALCASE": 5,
"TITLE CASE": 6,
"DOT.CASE": 7,
"PARAM-CASE": 8,
"SENTENCE CASE": 9,
"PATH/CASE": 10,
"HEADER-CASE": 11
}
}
}
{
"CamelCase": 1,
"Uppercase": 2,
"Lowercase": 3,
"SnakeCase": 4,
"PascalCase": 5,
"TitleCase": 6,
"DotCase": 7,
"ParamCase": 8,
"SentenceCase": 9,
"PathCase": 10,
"HeaderCase": 11,
"Lv1": {
"CamelCase": 1,
"Uppercase": 2,
"Lowercase": 3,
"SnakeCase": 4,
"PascalCase": 5,
"TitleCase": 6,
"DotCase": 7,
"ParamCase": 8,
"SentenceCase": 9,
"PathCase": 10,
"HeaderCase": 11,
"Lv2": {
"CamelCase": 1,
"Uppercase": 2,
"Lowercase": 3,
"SnakeCase": 4,
"PascalCase": 5,
"TitleCase": 6,
"DotCase": 7,
"ParamCase": 8,
"SentenceCase": 9,
"PathCase": 10,
"HeaderCase": 11
}
}
}