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
Full TypeScript signature sourced from the util file.
API
Parameters
Input parameters accepted by this util.
- strrequiredstring
- The source string to split.
- sizenumber1
- The length of each chunk. Defaults to 1 (individual characters).
API
Return value
The value returned by this 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
Examples
Ready-to-paste usage snippets.
Split a hex colour into pairs