Get unlimited public & private packages + team-based management with npm Teams.Learn more »

substr-distance

1.0.0 • Public • Published

substr-distance

Get the distance of a substring from the start of a line

Travis npm

Installation

npm install substr-distance

Usage

const substrDistance = require('substr-distance');
 
const page = `
<html>
  <body>
    <p id="thing">Find me!</p>
  </body>
</html>
`;
 
substrDistance(page, '<p id="thing">'); // => 4

API

substrDistance(haystack, needle)

Find string needle in haystack, and return the number of characters needle sits from the beginning of the line.

  • haystack (String): String to search in.
  • needle (String): String to search for.

Returns distance from start of line to needle. If needle is not found at all, -1 is returned.

Local Development

git clone https://github.com/gakimball/substr-distance
cd substr-distance
npm install
npm test

License

MIT © Geoff Kimball

Install

npm i substr-distance

DownloadsWeekly Downloads

4

Version

1.0.0

License

MIT

Last publish

Collaborators

  • avatar