Convert strings between camelCase
, PascalCase
, Title Case
, snake_case
,
lowercase
, UPPERCASE
, CONSTANT_CASE
and more.
All methods support Unicode (non-ASCII characters) and non-string entities, such
as objects with a toString
property, numbers and booleans. Empty values
(null
and undefined
) will result in an empty string.
Source code based on blakeembrey/change-case with TypeScript.
import { camelCase } from "https://deno.land/x/case/mod.ts";
camelCase("test string");
// => 'testString'
or
import camelCase from "https://deno.land/x/case/camelCase.ts";
camelCase("test string");
// => 'testString'
Available methods (short-hand shown below, long-hand available in examples):
camel
constant
dot
header
lower
lowerFirst
normal
- aliases: [no
,clear
]param
- aliases: [kebab
,hyphen
]pascal
path
sentence
snake
swap
title
upper
upperFirst
All methods accept two arguments, the string to change case and an optional locale.
Return as a string with the separators denoted by having the next letter capitalized.
camelCase("test string");
//=> "testString"
Return as an upper case, underscore separated string.
constantCase("test string");
//=> "TEST_STRING"
Return as a lower case, period separated string.
dotCase("test string");
//=> "test.string"
Return as a title cased, dash separated string.
headerCase("test string");
//=> "Test-String"
Return the string in lower case.
lowerCase("TEST STRING");
//=> "test string"
Return the string with the first character lower cased.
lowerFirstCase("TEST");
//=> "tEST"
no
clear
Return the string without any casing (lower case, space separated).
normalCase("test string");
//=> "test string"
kebabCase
hyphenCase
Return as a lower case, dash separated string.
paramCase("test string");
//=> "test-string"
Return as a string denoted in the same fashion as camelCase
, but with the
first letter also capitalized.
pascalCase("test string");
//=> "TestString"
Return as a lower case, slash separated string.
pathCase("test string");
//=> "test/string"
Return as a lower case, space separated string with the first letter upper case.
sentenceCase("testString");
//=> "Test string"
Return as a lower case, underscore separated string.
snakeCase("test string");
//=> "test_string"
Return as a string with every character case reversed.
swapCase("Test String");
//=> "tEST sTRING"
Return as a space separated string with the first character of every word upper cased.
titleCase("a simple test");
//=> "A Simple Test"
Return the string in upper case.
upperCase("test string");
//=> "TEST STRING"
Return the string with the first character upper cased.
upperFirstCase("test");
//=> "Test"
deno-change-case is released under the MIT License. See the bundled LICENSE file for details.