Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Find line number and cursor of string or Regex in a multi-line input
npm install locater
Locater supports string and regex matching. Below is an example showing both usage with a given input.
input.txt
In my younger and more vulnerable years
my father gave me some advice that
I've been turning over in my mind ever since.
js
var locater = require('locater');
var input = fs.readFileSync('./input.txt', {encoding: 'utf8'});
locater('my', input);
// => [{ line: 1, cursor: 4 }, { line: 2, cursor: 1 }, { line: 3, cursor: 27 }]
locater(/[a-zA-Z]{7}\s/g, input);
// => [{ line: 1, cursor: 7 }, { line: 1, cursor: 27 }, { line: 3, cursor: 11 }]
Returns an array of positions of occurrences of pattern
in input
.
A position is represented by an object with keys line
and cursor
.
pattern
can be either String or Regex. If it is a Regex, it should be declared
as global.
If there is no match, locater returns an empty array.
Feel free to open issues with bugs and feature requests.
MIT
FAQs
Easily locate string or regex in a multi-line input
The npm package locater receives a total of 5,468 weekly downloads. As such, locater popularity was classified as popular.
We found that locater demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.