Socket
Book a DemoInstallSign in
Socket

nth-indexof

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nth-indexof

Find the nth position of a pattern in a string

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

nth-indexof

Find the nth position of a pattern in a string.

Similar to str.indexOf(pattern) except that you can choose how many occurrences of pattern you wish to skip before getting the index.

Build status js-standard-style

Installation

npm install nth-indexof --save

Usage

const indexOf = require('nth-indexof')

const text = 'foo\nbar\nbaz'

console.log('The index of the 2nd linebreak is:', indexOf(text, '\n', 1)) // => 7

API

index = indexOf(haystack, needle[, skip][, offset])

Returns the index of the needle in the haystack ignoring the first skip occurrences indicated.

Arguments:

  • haystack - A string in which to search
  • needle - The string to search for
  • skip - Optional number of instances of needle to skip before finding the next index (default: 0)
  • offset - Optional offset in the haystack from where to start the search

Returns -1 if no match is found.

License

MIT

Keywords

indexOf

FAQs

Package last updated on 26 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts