@alanscodelog/utils
    Preparing search index...

    Function occurrences

    • Counts the number of times a substring occurs in the given string.

      Does not count overlapping matches by default but can be enabled with the overlapping option.

      Parameters

      • input: string
      • substring: string
      • __namedParameters: { overlapping?: boolean } = {}
        • Optionaloverlapping?: boolean

          Whether to count overlapping matches, false by default.

          occurrences("aaa", "aa") // overlapping false
          // aaa
          // __
          // ^matches
          // ^moves to end of match and finds no further matches

          occurrences("aaa", "aa", { overlapping:true })
          //aaa
          //__
          //^matches
          // ^moves 1 character forward
          // __
          // ^matches
          // ^moves 1 character forward and finds no further matches

      Returns number