@bitbeater/ecma-utils - v2.9.0
    Preparing search index...

    Function splitRuns

    • Splits a string into pairs of [delimiterRun, token], preserving contiguous delimiter runs.

      Parameters

      • text: string

        The input string to split.

      • isDelimiter: (char: string, index?: number, text?: string) => boolean

        Predicate to determine whether a character is a delimiter.

      Returns SplitTuple[]

      Array of tuples: [delimiterRun, token].

      // Split on spaces and punctuation
      const isDelim = (ch) => ch === ' ' || ch === '-' || ch === '!';

      splitRuns('hello world', isDelim);
      [
      ["", "hello"],
      [" ", "world"],
      ]

      splitRuns('hello world!', isDelim);
      [
      ["", "hello"],
      [" ", "world"],
      ["!", ""]
      ]

      splitRuns('- hello world!', isDelim);
      [
      ["- ", "hello"],
      [" ", "world"],
      ["!", ""]
      ]