Skip to main content

String Utilities

upperFirst

Takes a string and returns a new string with the first character capitalized.

ArgumentTypeRequiredDescription
strstringYesThe string to parse
ReturnsTypeDescription
stringstringThe transformed string
import {upperFirst} from '@stimulus-library/utilities';
// or
import {upperFirst} from '@stimulus-library';

upperFirst('hello world') // 'Hello world'
upperFirst('helloWorld') // 'HelloWorld'

lowerFirst

Takes a string and returns a new string with the first character lowercased.

ArgumentTypeRequiredDescription
strstringYesThe string to parse
ReturnsTypeDescription
stringstringThe transformed string
import {lowerFirst} from 'stimulus-library';
// or
import {lowerFirst} from '@stimulus-library/utilities';

lowerFirst('Hello world') // 'hello world'
lowerFirst('HelloWorld') // 'helloWorld'

camelCase

Takes a string and returns a new string in camelCase.

ArgumentTypeRequiredDescription
strstringYesThe string to parse
ReturnsTypeDescription
stringstringThe transformed string
import {camelCase} from '@stimulus-library/utilities';
// or
import {camelCase} from '@stimulus-library';

camelCase('hello world'); // 'helloWorld'
camelCase('hello-world'); // 'helloWorld'

pascalCase

Takes a string and returns a new string in PascalCase.

ArgumentTypeRequiredDescription
strstringYesThe string to parse
ReturnsTypeDescription
stringstringThe transformed string
import {pascalCase} from '@stimulus-library/utilities';
// or
import {pascalCase} from 'stimulus-library';

pascalCase('hello world') // 'HelloWorld'
pascalCase('hello-world') // 'HelloWorld'