@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
Name | Type | Required? | Default | Description |
---|---|---|---|---|
str | string | yes | - | The value to separate |
separator | string | no | ' ' | The separator character to insert between words |
ensureProperCase | boolean | no | false | Whether to capitalize the first letter of each word |
Returns
Returns a string
.