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

locate-character

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

locate-character - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

4

CHANGELOG.md
# locate-character changelog
## 2.0.1
* Port to TypeScript, add typings (no change in functionality)
## 2.0.0

@@ -4,0 +8,0 @@

89

dist/locate-character.es.js

@@ -1,54 +0,43 @@

function getLocator ( source, options ) {
if ( options === void 0 ) options = {};
var offsetLine = options.offsetLine || 0;
var offsetColumn = options.offsetColumn || 0;
var originalLines = source.split( '\n' );
var start = 0;
var lineRanges = originalLines.map( function ( line, i ) {
var end = start + line.length + 1;
var range = { start: start, end: end, line: i };
start = end;
return range;
});
var i = 0;
function rangeContains ( range, index ) {
return range.start <= index && index < range.end;
}
function getLocation ( range, index ) {
return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index };
}
return function locate ( search, startIndex ) {
if ( typeof search === 'string' ) {
search = source.indexOf( search, startIndex || 0 );
}
var range = lineRanges[i];
var d = search >= range.end ? 1 : -1;
while ( range ) {
if ( rangeContains( range, search ) ) return getLocation( range, search );
i += d;
range = lineRanges[i];
}
};
function getLocator(source, options) {
if (options === void 0) { options = {}; }
var offsetLine = options.offsetLine || 0;
var offsetColumn = options.offsetColumn || 0;
var originalLines = source.split('\n');
var start = 0;
var lineRanges = originalLines.map(function (line, i) {
var end = start + line.length + 1;
var range = { start: start, end: end, line: i };
start = end;
return range;
});
var i = 0;
function rangeContains(range, index) {
return range.start <= index && index < range.end;
}
function getLocation(range, index) {
return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index };
}
function locate(search, startIndex) {
if (typeof search === 'string') {
search = source.indexOf(search, startIndex || 0);
}
var range = lineRanges[i];
var d = search >= range.end ? 1 : -1;
while (range) {
if (rangeContains(range, search))
return getLocation(range, search);
i += d;
range = lineRanges[i];
}
}
;
return locate;
}
function locate ( source, search, options ) {
if ( typeof options === 'number' ) {
throw new Error( 'locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument' );
}
return getLocator( source, options )( search, options && options.startIndex );
function locate(source, search, options) {
if (typeof options === 'number') {
throw new Error('locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument');
}
return getLocator(source, options)(search, options && options.startIndex);
}
export { getLocator, locate };
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.locateCharacter = global.locateCharacter || {})));
}(this, function (exports) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.locateCharacter = global.locateCharacter || {})));
}(this, (function (exports) { 'use strict';
function getLocator ( source, options ) {
if ( options === void 0 ) options = {};
function getLocator(source, options) {
if (options === void 0) { options = {}; }
var offsetLine = options.offsetLine || 0;
var offsetColumn = options.offsetColumn || 0;
var originalLines = source.split('\n');
var start = 0;
var lineRanges = originalLines.map(function (line, i) {
var end = start + line.length + 1;
var range = { start: start, end: end, line: i };
start = end;
return range;
});
var i = 0;
function rangeContains(range, index) {
return range.start <= index && index < range.end;
}
function getLocation(range, index) {
return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index };
}
function locate(search, startIndex) {
if (typeof search === 'string') {
search = source.indexOf(search, startIndex || 0);
}
var range = lineRanges[i];
var d = search >= range.end ? 1 : -1;
while (range) {
if (rangeContains(range, search))
return getLocation(range, search);
i += d;
range = lineRanges[i];
}
}
;
return locate;
}
function locate(source, search, options) {
if (typeof options === 'number') {
throw new Error('locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument');
}
return getLocator(source, options)(search, options && options.startIndex);
}
var offsetLine = options.offsetLine || 0;
var offsetColumn = options.offsetColumn || 0;
exports.getLocator = getLocator;
exports.locate = locate;
var originalLines = source.split( '\n' );
Object.defineProperty(exports, '__esModule', { value: true });
var start = 0;
var lineRanges = originalLines.map( function ( line, i ) {
var end = start + line.length + 1;
var range = { start: start, end: end, line: i };
start = end;
return range;
});
var i = 0;
function rangeContains ( range, index ) {
return range.start <= index && index < range.end;
}
function getLocation ( range, index ) {
return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index };
}
return function locate ( search, startIndex ) {
if ( typeof search === 'string' ) {
search = source.indexOf( search, startIndex || 0 );
}
var range = lineRanges[i];
var d = search >= range.end ? 1 : -1;
while ( range ) {
if ( rangeContains( range, search ) ) return getLocation( range, search );
i += d;
range = lineRanges[i];
}
};
}
function locate ( source, search, options ) {
if ( typeof options === 'number' ) {
throw new Error( 'locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument' );
}
return getLocator( source, options )( search, options && options.startIndex );
}
exports.getLocator = getLocator;
exports.locate = locate;
Object.defineProperty(exports, '__esModule', { value: true });
}));
})));
{
"name": "locate-character",
"version": "2.0.0",
"version": "2.0.1",
"description": "Get the line and column number of a specific character in a string",

@@ -39,4 +39,6 @@ "main": "dist/locate-character.umd.js",

"rollup": "^0.34.7",
"rollup-plugin-buble": "^0.12.1"
}
"rollup-plugin-typescript": "^0.8.1",
"typescript": "^2.3.2"
},
"types": "./types.d.ts"
}

@@ -7,3 +7,3 @@ # locate-character

`npm install locate-character`, or get it from [npmcdn.com/locate-character](https://npmcdn.com/locate-character).
`npm install locate-character`, or get it from [unpkg.com/locate-character](https://unpkg.com/locate-character).

@@ -10,0 +10,0 @@

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