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
- Host: GitHub
- URL: https://github.com/simonwep/previous-index-of
- Owner: simonwep
- License: mit
- Created: 2019-09-27T16:23:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T18:45:15.000Z (over 3 years ago)
- Last Synced: 2025-04-01T03:35:39.950Z (about 1 year ago)
- Topics: string, string-matching, util, utility-function
- Language: JavaScript
- Size: 28.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Previous Index Of
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
```