1.38.0pascalCase
Converts a string into PascalCase by tokenizing it, capitalizing the first character of each word, lowercasing the remaining characters, and joining the words without separators.
pascalCase(value):stringBehavior
pascalCase first tokenizes the input into words. For each word, the first character is converted to uppercase and the remaining characters are converted to lowercase. The resulting words are then joined without a separator.
Tokenization
Word extraction is delegated to the internal tokenize utility. The exact word boundaries therefore depend on tokenize.
Casing rules
Every word starts with an uppercase character. All characters after the first one are converted to lowercase.
No separator
After each token is transformed, all tokens are joined directly with no separator.
Parameters
valuestringrequiredThe string to convert to PascalCase.
Returns
stringThe tokenized input converted to PascalCase.
Examples
Basic usage
Convert a space-separated phrase to PascalCase.
import { pascalCase } from "@cyref/js";
pascalCase("hello world");
// "HelloWorld"Multiple words
Each word starts with an uppercase character and the words are joined together.
pascalCase("hello beautiful world");
// "HelloBeautifulWorld"Mixed case
Each token is normalized to an uppercase first character followed by lowercase characters.
pascalCase("hello WoRLD TeST");
// "HelloWorldTest"Single word
A single token is converted to PascalCase.
pascalCase("hELLO");
// "Hello"Empty input
If tokenization produces no words, an empty string is returned.
pascalCase("");
// ""Existing separators
The input is tokenized first, so the resulting words are joined without separators.
pascalCase("hello-world");
// "HelloWorld"