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 - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

21

lib/locater.js

@@ -10,10 +10,15 @@ /**

//converts all targets to regex
if (!(target instanceof RegExp)) {
target = new RegExp('\\b' + target + '\\b', "g");
}
if (typeof target === 'string') {
var index = 0;
var offset = 0;
while ((match = target.exec(line)) !== null) {
target.lastIndex = match.index + 1;
indices.push(match.index);
while ((index = line.indexOf(target, offset)) !== -1) {
indices.push(index);
offset = index + 1;
}
} else if (target instanceof RegExp) {
while ((match = target.exec(line)) !== null) {
target.lastIndex = match.index + 1;
indices.push(match.index);
}
}

@@ -58,3 +63,3 @@

/**
* Converts sting to lines based on \n. Also removes last line break
* Converts sting to lines based on \n.
* @param source {String} - the string split

@@ -61,0 +66,0 @@ */

{
"name": "locater",
"version": "1.2.1",
"version": "1.2.2",
"description": "Easily locate string or regex in a multi-line input",

@@ -5,0 +5,0 @@ "main": "./lib/locater.js",

@@ -30,4 +30,4 @@ # Locater

locater.find(['my', 'me'], input);
// => [ { line: 1, cursor: 4 }, { line: 2, cursor: 1 }, { line: 2, cursor: 16 },
locater.find(['my', 'some'], input);
// => [ { line: 1, cursor: 4 }, { line: 2, cursor: 1 }, { line: 2, cursor: 19 },
// { line: 3, cursor: 27 } ]

@@ -34,0 +34,0 @@

@@ -10,5 +10,4 @@ var expect = require('chai').expect;

'./test/fixtures/sample_input.txt', {encoding: 'utf8'});
var result = locater.find(['my', 'some'], input);
var result = locater.find(['my', 'me'], input);
expect(result[0].line).to.equal(1);

@@ -19,3 +18,3 @@ expect(result[0].cursor).to.equal(4);

expect(result[2].line).to.equal(2);
expect(result[2].cursor).to.equal(16);
expect(result[2].cursor).to.equal(19);
expect(result[3].line).to.equal(3);

@@ -62,2 +61,12 @@ expect(result[3].cursor).to.equal(27);

it("matches newline character", function() {
var input = "Bacon\n tastes gooood.\nPork chops taste gooood.";
var result = locater.find('\n', input);
expect(result[0].line).to.equal(1);
expect(result[0].cursor).to.equal(6);
expect(result[1].line).to.equal(2);
expect(result[1].cursor).to.equal(16);
});
it("does not return global indices if no option is specified", function() {

@@ -64,0 +73,0 @@ var input = 'Bacon tastes gooood.\nPork chops taste gooood.';

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