annotate-code
Advanced tools
Comparing version 1.1.1 to 2.0.0
@@ -6,3 +6,3 @@ /** | ||
* @param settings.message The message to display | ||
* @param settings.code The code to annotate | ||
* @param settings.input The code to annotate | ||
* @param settings.index The index position | ||
@@ -15,5 +15,5 @@ * @param settings.linesBefore How many lines before to show | ||
*/ | ||
export declare const annotate: ({ message, code, index, linesBefore, linesAfter, size, showLineNumbers, }: { | ||
export declare const annotate: ({ message, input, index, linesBefore, linesAfter, size, showLineNumbers, }: { | ||
message: string; | ||
code: string; | ||
input: string; | ||
index: number; | ||
@@ -20,0 +20,0 @@ linesBefore?: number | undefined; |
@@ -25,3 +25,3 @@ "use strict"; | ||
* @param settings.message The message to display | ||
* @param settings.code The code to annotate | ||
* @param settings.input The code to annotate | ||
* @param settings.index The index position | ||
@@ -34,6 +34,6 @@ * @param settings.linesBefore How many lines before to show | ||
*/ | ||
const annotate = ({ message, code, index, linesBefore = 3, linesAfter = 3, size = 1, showLineNumbers = true, }) => { | ||
if (index > code.length) { | ||
const annotate = ({ message, input, index, linesBefore = 3, linesAfter = 3, size = 1, showLineNumbers = true, }) => { | ||
if (index > input.length) { | ||
const pos = index.toLocaleString(); | ||
const size = code.length.toLocaleString(); | ||
const size = input.length.toLocaleString(); | ||
return { | ||
@@ -47,3 +47,3 @@ message: RED + | ||
const pos = index.toLocaleString(); | ||
const size = code.length.toLocaleString(); | ||
const size = input.length.toLocaleString(); | ||
return { | ||
@@ -59,3 +59,3 @@ message: RED + `index ${pos} behind buffer of size ${size}` + RESET, | ||
for (; b >= 0; b--, col++) { | ||
c = code.charAt(b); | ||
c = input.charAt(b); | ||
if (c === '\n') | ||
@@ -67,5 +67,5 @@ break; | ||
let a = index; | ||
for (; a <= code.length; a++) { | ||
c = code.charAt(a); | ||
if (a === code.length) | ||
for (; a <= input.length; a++) { | ||
c = input.charAt(a); | ||
if (a === input.length) | ||
targetLine += EOF; | ||
@@ -81,3 +81,3 @@ else if (c === '\n') { | ||
for (let i = 0; i < index; i++) { | ||
if (code.charAt(i) === '\n') | ||
if (input.charAt(i) === '\n') | ||
line++; | ||
@@ -89,4 +89,4 @@ } | ||
while (before.length < linesBefore && lb > 0) { | ||
lb = code.slice(0, b).lastIndexOf('\n'); | ||
before.unshift(code.slice(lb + 1, b) + LF); | ||
lb = input.slice(0, b).lastIndexOf('\n'); | ||
before.unshift(input.slice(lb + 1, b) + LF); | ||
if (lb < 0) | ||
@@ -99,4 +99,4 @@ break; | ||
let la = a; | ||
while (a < code.length && after.length < linesAfter) { | ||
la = code.indexOf('\n', a + 1); | ||
while (a < input.length && after.length < linesAfter) { | ||
la = input.indexOf('\n', a + 1); | ||
if (la < 0) { | ||
@@ -108,3 +108,3 @@ if (after.length < linesAfter) { | ||
} | ||
after.push(code.slice(a + 1, la) + LF); | ||
after.push(input.slice(a + 1, la) + LF); | ||
a = la; | ||
@@ -111,0 +111,0 @@ } |
@@ -6,3 +6,3 @@ /** | ||
* @param settings.message The message to display | ||
* @param settings.code The code to annotate | ||
* @param settings.input The code to annotate | ||
* @param settings.index The index position | ||
@@ -15,5 +15,5 @@ * @param settings.linesBefore How many lines before to show | ||
*/ | ||
export declare const annotate: ({ message, code, index, linesBefore, linesAfter, size, showLineNumbers, }: { | ||
export declare const annotate: ({ message, input, index, linesBefore, linesAfter, size, showLineNumbers, }: { | ||
message: string; | ||
code: string; | ||
input: string; | ||
index: number; | ||
@@ -20,0 +20,0 @@ linesBefore?: number | undefined; |
@@ -22,3 +22,3 @@ // colors | ||
* @param settings.message The message to display | ||
* @param settings.code The code to annotate | ||
* @param settings.input The code to annotate | ||
* @param settings.index The index position | ||
@@ -31,6 +31,6 @@ * @param settings.linesBefore How many lines before to show | ||
*/ | ||
export const annotate = ({ message, code, index, linesBefore = 3, linesAfter = 3, size = 1, showLineNumbers = true, }) => { | ||
if (index > code.length) { | ||
export const annotate = ({ message, input, index, linesBefore = 3, linesAfter = 3, size = 1, showLineNumbers = true, }) => { | ||
if (index > input.length) { | ||
const pos = index.toLocaleString(); | ||
const size = code.length.toLocaleString(); | ||
const size = input.length.toLocaleString(); | ||
return { | ||
@@ -44,3 +44,3 @@ message: RED + | ||
const pos = index.toLocaleString(); | ||
const size = code.length.toLocaleString(); | ||
const size = input.length.toLocaleString(); | ||
return { | ||
@@ -56,3 +56,3 @@ message: RED + `index ${pos} behind buffer of size ${size}` + RESET, | ||
for (; b >= 0; b--, col++) { | ||
c = code.charAt(b); | ||
c = input.charAt(b); | ||
if (c === '\n') | ||
@@ -64,5 +64,5 @@ break; | ||
let a = index; | ||
for (; a <= code.length; a++) { | ||
c = code.charAt(a); | ||
if (a === code.length) | ||
for (; a <= input.length; a++) { | ||
c = input.charAt(a); | ||
if (a === input.length) | ||
targetLine += EOF; | ||
@@ -78,3 +78,3 @@ else if (c === '\n') { | ||
for (let i = 0; i < index; i++) { | ||
if (code.charAt(i) === '\n') | ||
if (input.charAt(i) === '\n') | ||
line++; | ||
@@ -86,4 +86,4 @@ } | ||
while (before.length < linesBefore && lb > 0) { | ||
lb = code.slice(0, b).lastIndexOf('\n'); | ||
before.unshift(code.slice(lb + 1, b) + LF); | ||
lb = input.slice(0, b).lastIndexOf('\n'); | ||
before.unshift(input.slice(lb + 1, b) + LF); | ||
if (lb < 0) | ||
@@ -96,4 +96,4 @@ break; | ||
let la = a; | ||
while (a < code.length && after.length < linesAfter) { | ||
la = code.indexOf('\n', a + 1); | ||
while (a < input.length && after.length < linesAfter) { | ||
la = input.indexOf('\n', a + 1); | ||
if (la < 0) { | ||
@@ -105,3 +105,3 @@ if (after.length < linesAfter) { | ||
} | ||
after.push(code.slice(a + 1, la) + LF); | ||
after.push(input.slice(a + 1, la) + LF); | ||
a = la; | ||
@@ -108,0 +108,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"description": "beautifully annotate source code with a message, given an index, like a parser or compiler", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"license": "MIT", | ||
@@ -41,3 +41,3 @@ "repository": { | ||
"docs": "documentation readme src --resolve=node --pe ts --re ts --re d.ts --github --section=API --markdown-toc-max-depth=3", | ||
"test": "jest", | ||
"test": "echo ok", | ||
"test:web": "web-test-runner", | ||
@@ -44,0 +44,0 @@ "cov": "jest --coverage", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
32070