chunk

Commons
stable

Splits a string into an array of fixed-size substrings. Used internally to segment colour codes and similar fixed-width token sequences.

API

Signature

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

str
requis
string
The source string to split.
size
number
1
The length of each chunk. Defaults to 1 (individual characters).

API

Valeur de retour

La valeur retournée par cet util.

An array of substrings of the given size. The last element may be shorter if the string length is not divisible by size.

Usage

Exemples

Extraits de code prêts à coller.

Split a hex colour into pairs

typescript