Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

locater

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

locater

Find line number and cursor of string or regex in a multi-line input

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.8K
increased by301.18%
Maintainers
1
Weekly downloads
 
Created
Source

Locater

Build Status

Find line number and cursor of string or Regex in a multi-line input

Install

npm install locater

Usage

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 }]

Guide

locater(pattern, input)

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.

Contributing

Feel free to open issues with bugs and feature requests.

License

MIT

Keywords

FAQs

Package last updated on 22 Nov 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc