An open API service indexing awesome lists of open source software.

https://github.com/simonwep/previous-index-of

Find the previous index of a char-sequence at a given offset in a string
https://github.com/simonwep/previous-index-of

string string-matching util utility-function

Last synced: 5 months ago
JSON representation

Find the previous index of a char-sequence at a given offset in a string

Awesome Lists containing this project

README

          


Previous Index Of


Build Status
Download count
No dependencies
Current version
Support me

Find the index of a specific char-sequence in a string at a given offset.

### Installation
##### NPM
```bash
$ npm i previous-index-of
```
##### Yarn
```bash
$ yarn add previous-index-of
```

### Usage
```js
const previousIndexOf = require('previous-index-of');

// previousIndexOf(sourceString: , target: , offset: )
previousIndexOf('baz bam boo foo bam', 'bam', 12); // 4
previousIndexOf('baz bam boo foo bam', 'bam'); // 16
previousIndexOf('baz bam boo foo bam', 'da'); // -1
previousIndexOf('baz bam boo foo bam', 'bam', {}); // 16
previousIndexOf('baz bam boo foo bam', null); // -1
previousIndexOf(null, 'abc'); // -1
```

### Running tests
```
$ npm install -d && npm test
```