Function splitByLength

Splits a string into length-size chunks.

If length is greater than the length of source, a single element array is returned with source. The final array element may be smaller if we ran out of characters.

splitByLength(`hello there`, 2);
// Yields:
// [`he`, `ll`, `o `, `th`, `er`, `e`]
  • Parameters

    • source: null | string

      Source string

    • length: number

      Length of each chunk

    Returns readonly string[]