Change Case
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.
Usage
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.
camelCase
Return as a string with the separators denoted by having the next letter capitalized.
camelCase("test string");
//=> "testString"
constantCase
Return as an upper case, underscore separated string.
constantCase("test string");
//=> "TEST_STRING"
dotCase
Return as a lower case, period separated string.
dotCase("test string");
//=> "test.string"
headerCase
Return as a title cased, dash separated string.
headerCase("test string");
//=> "Test-String"
lowerCase
Return the string in lower case.
lowerCase("TEST STRING");
//=> "test string"
lowerFirstCase
Return the string with the first character lower cased.
lowerFirstCase("TEST");
//=> "tEST"
normalCase
no
clear
Return the string without any casing (lower case, space separated).
normalCase("test string");
//=> "test string"
paramCase
Aliases
kebabCase
hyphenCase
Return as a lower case, dash separated string.
paramCase("test string");
//=> "test-string"
pascalCase
Return as a string denoted in the same fashion as camelCase
, but with the
first letter also capitalized.
pascalCase("test string");
//=> "TestString"
pathCase
Return as a lower case, slash separated string.
pathCase("test string");
//=> "test/string"
sentenceCase
Return as a lower case, space separated string with the first letter upper case.
sentenceCase("testString");
//=> "Test string"
snakeCase
Return as a lower case, underscore separated string.
snakeCase("test string");
//=> "test_string"
swapCase
Return as a string with every character case reversed.
swapCase("Test String");
//=> "tEST sTRING"
titleCase
Return as a space separated string with the first character of every word upper cased.
titleCase("a simple test");
//=> "A Simple Test"
upperCase
Return the string in upper case.
upperCase("test string");
//=> "TEST STRING"
upperFirstCase
Return the string with the first character upper cased.
upperFirstCase("test");
//=> "Test"
Credits
License
deno-change-case is released under the MIT License. See the bundled LICENSE file for details.