lines-and-columns
Advanced tools
Comparing version 1.0.1 to 1.0.2
'use strict'; | ||
const LF = '\n'; | ||
const CR = '\r'; | ||
class LinesAndColumns { | ||
@@ -7,13 +10,23 @@ constructor(string) { | ||
const offsets = []; | ||
let offset = 0; | ||
while (true) { | ||
offsets.push(offset); | ||
let next = string.indexOf('\n', offset); | ||
if (next < 0) { | ||
break; | ||
} else { | ||
next += '\n'.length; | ||
const offsets = [0]; | ||
for (let offset = 0; offset < string.length;) { | ||
switch (string[offset]) { | ||
case LF: | ||
offset += LF.length; | ||
offsets.push(offset); | ||
break; | ||
case CR: | ||
offset += CR.length; | ||
if (string[offset] === LF) { | ||
offset += LF.length; | ||
} | ||
offsets.push(offset); | ||
break; | ||
default: | ||
offset++; | ||
break; | ||
} | ||
offset = next; | ||
} | ||
@@ -20,0 +33,0 @@ |
@@ -0,1 +1,4 @@ | ||
const LF = '\n'; | ||
const CR = '\r'; | ||
class LinesAndColumns { | ||
@@ -5,13 +8,23 @@ constructor(string) { | ||
const offsets = []; | ||
let offset = 0; | ||
while (true) { | ||
offsets.push(offset); | ||
let next = string.indexOf('\n', offset); | ||
if (next < 0) { | ||
break; | ||
} else { | ||
next += '\n'.length; | ||
const offsets = [0]; | ||
for (let offset = 0; offset < string.length;) { | ||
switch (string[offset]) { | ||
case LF: | ||
offset += LF.length; | ||
offsets.push(offset); | ||
break; | ||
case CR: | ||
offset += CR.length; | ||
if (string[offset] === LF) { | ||
offset += LF.length; | ||
} | ||
offsets.push(offset); | ||
break; | ||
default: | ||
offset++; | ||
break; | ||
} | ||
offset = next; | ||
} | ||
@@ -18,0 +31,0 @@ |
{ | ||
"name": "lines-and-columns", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Maps lines and columns to character offsets and back.", | ||
@@ -5,0 +5,0 @@ "main": "dist/lines-and-columns.cjs.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
5873
117
0