Namespace: Split

Split

Functions to split a string

Methods

(static) charCodes(subject) → {Array.<number>}

Split a string into an array of its UTF-16 char codes

Parameters:
Name Type Description
subject string

The string to split

Since:
  • 0.0.1
Returns:

An array of numeric char codes

Type
Array.<number>
Example
encodeUTF16("hello")
// => [104, 101, 108, 108, 111];
encodeUTF16("😁🐶🍕")
// => [55357, 56833, 55357, 56374, 55356, 57173]

(static) graphemes(subject) → {Array.<string>}

Splits a string into an array of Unicode extended grapheme clusters. These more closely correspond to what the reader perceives as characters in cases where code points are not sufficient.

Parameters:
Name Type Description
subject string

String to split into graphemes

Since:
  • 0.0.1
Returns:

An array of graphemes

Type
Array.<string>
Example
graphemes("hello")
// => ["h", "e", "l", "l", "o"]
graphemes("अनुच्छेद")
// => ['अ', 'नु', 'च्', 'छे', 'द']

(static) scalars(subject) → {Array.<string>}

Splits a string into an array of its Unicode scalar values, each of which is represented by a single Unicode code point. Many or even most JavaScript writers call this a "character."

Parameters:
Name Type Description
subject string

String to split

Since:
  • 0.01
Returns:

An array of Unicode scalars

Type
Array.<string>
Example
scalars("hello")
// => ["h", "e", "l", "l", "o"]
scalars("😁🐶🍕")
// => ["😁", "🐶", "🍕"]

(static) words(subject) → {Array.<string>}

Splits a string into words using Unicode UAX #29 and strips punctuation

Parameters:
Name Type Description
subject string

String to split into words

Since:
  • 0.01
Returns:

An array of words

Type
Array.<string>
Example
words("This is a string")
// => ["This", "is", "a", "string"]
words("The quick (“brown”) fox can’t jump 32.3 feet, right?")
// => ["The", "quick", "brown", "fox", "can’t", "jump", "32.3", "feet", "right"]
words("В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!")
// => ["В", "чащах", "юга", "жил", "бы", "цитрус", "Да", "но", "фальшивый", "экземпляр"]
words("thisIsAStringToSplit")
// => ["this", "Is", "A", "String", "To", "Split"]