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 0.1.1 to 0.1.2

26

lib/locater.js

@@ -14,18 +14,14 @@ /**

while (index != -1) {
index = line.indexOf(target, offset);
if (index != -1) {
indices.push(index);
offset = index + 1;
}
while ((index = line.indexOf(target, offset)) !== -1) {
indices.push(index);
offset = index + 1;
}
return indices;
} else if (target instanceof RegExp) {
while ((match = target.exec(line)) !== null) {
target.lastIndex = match.index + 1;
indices.push(match.index);
}
}
return indices;
}
return indices;
}

@@ -46,9 +42,7 @@

if (indices.length > 0) {
indices.forEach(function (index) {
var position = {line: lineNumber, cursor: index + 1};
indices.forEach(function (index) {
var position = {line: lineNumber, cursor: index + 1};
results.push(position);
});
}
results.push(position);
});

@@ -55,0 +49,0 @@ lineNumber++;

{
"name": "locater",
"version": "0.1.1",
"version": "0.1.2",
"description": "Find line number and cursor of string or regex in a multi-line input",

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

@@ -31,4 +31,4 @@ # Locater

locater(/[a-zA-Z]{7}/g, input);
// => [{ line: 1, cursor: 7 }, { line: 1, cursor: 24 }, { line: 3, cursor: 11 }]
locater(/[a-zA-Z]{7}\s/g, input);
// => [{ line: 1, cursor: 7 }, { line: 1, cursor: 27 }, { line: 3, cursor: 11 }]
```

@@ -35,0 +35,0 @@

@@ -24,3 +24,3 @@ var expect = require('chai').expect;

var result = locater(/[a-zA-Z]{7}/g, input);
var result = locater(/[a-zA-Z]{7}\s/g, input);

@@ -30,3 +30,3 @@ expect(result[0].line).to.equal(1);

expect(result[1].line).to.equal(1);
expect(result[1].cursor).to.equal(24);
expect(result[1].cursor).to.equal(27);
expect(result[2].line).to.equal(3);

@@ -50,2 +50,15 @@ expect(result[2].cursor).to.equal(11);

});
it("matches multiple occurences of a string in a line", function() {
var result = locater('my', 'my mind my soul');
expect(result[0].line).to.equal(1);
expect(result[0].cursor).to.equal(1);
expect(result[1].line).to.equal(1);
expect(result[1].cursor).to.equal(9);
});
it("matches multiple occurences of a regex in a line", function() {
var result = locater(/[a-zA-Z]{6}/g, 'kaskade - 4AM');
expect(result.length).to.equal(2);
});
});
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