previous-index-of
v1.2.1
Published
Find the previous index of a char-sequence at a given offset in a string
Downloads
7
Readme
Find the index of a specific char-sequence in a string at a given offset.
Installation
NPM
$ npm i previous-index-of
Yarn
$ yarn add previous-index-of
Usage
const previousIndexOf = require('previous-index-of');
// previousIndexOf(sourceString: <string>, target: <string>, offset: <number|undefined>)
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