Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/str-indexes-of
Like String#indexOf() but return all indexes
https://github.com/shinnn/str-indexes-of
Last synced: 27 days ago
JSON representation
Like String#indexOf() but return all indexes
- Host: GitHub
- URL: https://github.com/shinnn/str-indexes-of
- Owner: shinnn
- Created: 2016-09-30T08:55:44.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-22T01:45:03.000Z (over 6 years ago)
- Last Synced: 2024-09-24T19:59:12.654Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://runkit.com/npm/str-indexes-of
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# str-indexes-of
[![npm version](https://img.shields.io/npm/v/str-indexes-of.svg)](https://www.npmjs.com/package/str-indexes-of)
[![Build Status](https://travis-ci.org/shinnn/str-indexes-of.svg?branch=master)](https://travis-ci.org/shinnn/str-indexes-of)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/str-indexes-of.svg)](https://coveralls.io/github/shinnn/str-indexes-of)Like [`String#indexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf), but return all indexes instead of the first one
```javascript
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](https://github.com/dominictarr/indexes-of), but:
* only supports `String` explicitly
* throws `TypeError` when it takes an `Array`
* supports optional [`fromIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf#Parameters) parameter
* disallows empty search value## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-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````javascript
strIndexesOf('ABC-ABC', 'A'); //=> [0, 4]
strIndexesOf('ABC-ABC', 'A', 4); //=> [4]
```## Related project
[arr-indexes-of](https://github.com/shinnn/arr-indexes-of) - [`Array#indexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) version
## License
[Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/deed)