K2 Javascript Utilities offers several utilities packages. The strings package privide several methods to format strings.
npm install @k2_tools/utils
import {strings} from "@k2_tools/utils";
K2_tools string utilities offers a the following methods to format strings.
capitalizeFirstLetter
titleCase
snakeCase
kebabCase
camelCase
aliasCase
The capitailizeFirstLetter(str)
method accepts a string as its argument and returns a string where the first letter of the accepted string is replaced with its
uppercase variant.
console.log(strings.capitalizrFirstLetter("the quick brown fox!"));
Produces the following output
The quick brown fox!
The titleCase(str)
method accepts a string as its argument and returns the string with the first letter of each word in the string capitalized.
console.log(strings.titleCase("the quick brown fox!"));
Produces the following output
The Quick Brown Fox!
The snakeCase(str)
method accepts a string as its argument and returns the string in alpha-numeric lowercase with underscores _
replacing spaces between words.
console.log(strings.snakeCase("The quick brown fox!"));
Produces the following output
the_quick_brown_fox
The kebabCase(str)
method method accepts a string as its argument and returns the string in alpha-numeric lowercase with hyphens -
replacing spaces between words.
console.log(strings.kebabCase("The quick brown fox!"));
Produces the following output
the-quick-brown-fox
The camelCase(str)
method method accepts a string as its argument and returns the string in alpha-numeric lowercase with the first letter of each word capitalized
and the spaces wetweeb words removed.
console.log(strings.camelCase("The quick brown fox!"));
Produces the following output
TheQuickBrownFox
The aliasCase(str)
method method accepts a string as its argument and returns the string in alpha-numeric lowercase with the first letter of each word capitalized
and the spaces wetweeb words removed but with the very first charter in lowercase.
console.log(strings.aliasCase("The quick brown fox!"));
Produces the following output
theQuickBrownFox