How to use the capitalCase function from change-case

Find comprehensive JavaScript change-case.capitalCase code examples handpicked from public code repositorys.

change-case.capitalCase is a function that converts a string to title case by capitalizing the first letter of each word while lowercasing all other letters.

34
35
36
37
38
39
40
41
42
43
44


function swapNameStrings() {
    let pascalName = pascalCase(argv.name);
    let kebabName = paramCase(argv.name);
    let snakeName = snakeCase(argv.name);
    let titleName = capitalCase(argv.name);
    return src(paths, { base: "./" })
        .pipe(replace('ReplaceMe', pascalName))
        .pipe(replace('replace-me', kebabName))
        .pipe(replace('replace_me', snakeName))
fork icon0
star icon1
watch icon1

+ 17 other calls in file

74
75
76
77
78
79
80
81
82
83
const role = interaction.options.getRole('role')
const url = interaction.options.getString('link')
const pattern = /(\/|=)([^/=]*)$/
const match = url.match(pattern)
const collectionSymbol = match ? match[2] : url
const name = interaction.options.getString('name') ?? capitalCase(collectionSymbol)

const selectedMarketplace = MARKET_PLACES.find((item) => item.name === venue)

await interaction.deferReply({
fork icon1
star icon0
watch icon0

How does change-case.capitalCase work?

change-case.capitalCase is a function from the change-case library that takes a string as input and returns a new string with the first letter of each word capitalized and all other letters lowercase. If the input string contains non-word characters (e.g., punctuation), they are preserved in the output.

160
161
162
163
164
165
166
167
168
169
const valuesObj = extractValues(humanInput, similarQuestion, {
  delimiters: ["{", "}"],
});

let { topic } = valuesObj;
topic = capitalCase(topic);

try {
  const wikipediaResponse = await wiki.summary(topic);
  const wikipediaResponseText = wikipediaResponse.extract;
fork icon0
star icon0
watch icon1

+ 8 other calls in file

Ai Example

1
2
3
4
const changeCase = require("change-case");

console.log(changeCase.capitalCase("hello world!")); // Output: 'HelloWorld'
console.log(changeCase.capitalCase("my first ionic app")); // Output: 'MyFirstIonicApp'