Skip to main content
@spa-tools/utilities

separateWords()

The separateWords() function takes a string and separates its proper-cased words by inserting a separator between them.

Usage

import { separateWords } from '@spa-tools/utilities';

const value = 'helloWorld';

const separated1 = separateWords(value);
console.log(separated1);
// --> 'hello World'

const separated2 = separateWords(value, '-');
console.log(separated2);
// --> 'hello-World'

const separated3 = separateWords(value, ' ', true);
console.log(separated3);
// --> 'Hello World'

Arguments

NameTypeRequired?DefaultDescription
strstringyes-The value to separate
separatorstringno' 'The separator character to insert between words
ensureProperCasebooleannofalseWhether to capitalize the first letter of each word

Returns

Returns a string.