Skip to content

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

License

Notifications You must be signed in to change notification settings

simonwep/previous-index-of

Repository files navigation

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
$ 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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published