Skip to content

splitWords()

splitWords(input, options?): string[]

Defined in: utils/string/splitWords.ts:41

Split a string into "words" based on:

  • Non-alphanumeric separators (spaces, punctuation, etc.)
  • camelCase boundaries ("fooBar""foo", "Bar")
  • optional transitions between letters and digits

This is a small utility intended for implementing casing helpers (kebab-case, snake_case, slugify, etc.).

Parameters

input

string

The input string to split.

options?

SplitWordsOptions = {}

Optional configuration.

Returns

string[]

An array of word tokens.

Example

ts
splitWords('helloWorldAPI42', { splitOnNumbers: true });
// ["hello", "world", "API", "42"]

Released under the MIT License.