1.0.4 • Published 7 years ago
str-indexes-of v1.0.4
str-indexes-of
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
Stringexplicitly- throws
TypeErrorwhen it takes anArray
- throws
- supports optional
fromIndexparameter - disallows empty search value
Installation
npm install str-indexes-ofAPI
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