str-indexes-of

1.0.4 • Public • Published

str-indexes-of

npm version Build Status Coverage Status

Like String#indexOf(), but return all indexes instead of the first one

import strIndexesOf from 'str-indexes-of';
 
strIndexesOf('aaa', 'a'); //=> [0, 1, 2]
strIndexesOf('ffoofffofofofofofffooffoo', 'foo'); //=> [1, 18, 22]

Almost the same module as indexes-of, but:

  • only supports String explicitly
    • throws TypeError when it takes an Array
  • supports optional fromIndex parameter
  • disallows empty search value

Installation

Use npm.

npm install str-indexes-of

API

import strIndexesOf from 'str-indexes-of';

strIndexesOf(str, searchValue [, fromIndex])

str: string
searchValue: string (value to search for)
fromIndex: number (index in the string where to begin searching)
Return: Array of string

strIndexesOf('ABC-ABC', 'A'); //=> [0, 4]
strIndexesOf('ABC-ABC', 'A', 4); //=> [4]

Related project

arr-indexes-of - Array#indexOf() version

License

Creative Commons Zero v1.0 Universal

/str-indexes-of/

    Package Sidebar

    Install

    npm i str-indexes-of

    Weekly Downloads

    1

    Version

    1.0.4

    License

    CC0-1.0

    Unpacked Size

    5.17 kB

    Total Files

    4

    Last publish

    Collaborators

    • shinnn