1.2.1 • Published 5 years ago
previous-index-of v1.2.1
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