1.0.4 • Published 6 years ago

str-indexes-of v1.0.4

Weekly downloads
3
License
CC0-1.0
Repository
github
Last release
6 years ago

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

1.0.4

6 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

8 years ago

0.0.0

8 years ago