annotate-code
Advanced tools
Comparing version 2.0.2 to 2.0.3
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.annotate = void 0; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "annotate", { | ||
enumerable: true, | ||
get: ()=>annotate | ||
}); | ||
// colors | ||
@@ -14,34 +19,17 @@ const isTTY = typeof process !== 'undefined' && process.stdout.isTTY; | ||
const EOF = GREY + '<EOF>' + RESET; | ||
const arrow = ({ | ||
// line, | ||
col, message = '', pad = 0, size = 1, }) => BAR.padStart(pad, ' ') + | ||
RED + | ||
(('^'.repeat(size) + ' ').padStart(col + size, ' ') + message) + | ||
RESET; | ||
/** | ||
* Annotates a source code string given an index and a message. | ||
* | ||
* @param settings | ||
* @param settings.message The message to display | ||
* @param settings.input The code to annotate | ||
* @param settings.index The index position | ||
* @param settings.linesBefore How many lines before to show | ||
* @param settings.linesAfter How many lines after to show | ||
* @param settings.size The size of the arrows ^^^^ | ||
* @param settings.showLineNumbers Whether to show line numbers | ||
* @returns { line, col, message } | ||
*/ | ||
const annotate = ({ message, input, index, linesBefore = 3, linesAfter = 3, size = 1, showLineNumbers = true, }) => { | ||
const arrow = ({ // line, | ||
col , message ='' , pad =0 , size =1 })=>BAR.padStart(pad, ' ') + RED + (('^'.repeat(size) + ' ').padStart(col + size, ' ') + message) + RESET; | ||
const annotate = ({ message , input , index , linesBefore =3 , linesAfter =3 , size =1 , showLineNumbers =true })=>{ | ||
if (index > input.length) { | ||
const pos = index.toLocaleString(); | ||
const size = input.length.toLocaleString(); | ||
const size1 = input.length.toLocaleString(); | ||
return { | ||
message: RED + `index ${pos} past buffer of size ${size}: ${pos} > ${size}` + RESET, | ||
message: RED + `index ${pos} past buffer of size ${size1}: ${pos} > ${size1}` + RESET | ||
}; | ||
} | ||
if (index < 0) { | ||
const pos = index.toLocaleString(); | ||
const size = input.length.toLocaleString(); | ||
const pos1 = index.toLocaleString(); | ||
const size2 = input.length.toLocaleString(); | ||
return { | ||
message: RED + `index ${pos} behind buffer of size ${size}` + RESET, | ||
message: RED + `index ${pos1} behind buffer of size ${size2}` + RESET | ||
}; | ||
@@ -54,6 +42,5 @@ } | ||
let b = index - 1; | ||
for (; b >= 0; b--, col++) { | ||
for(; b >= 0; b--, col++){ | ||
c = input.charAt(b); | ||
if (c === '\n') | ||
break; | ||
if (c === '\n') break; | ||
targetLine = c + targetLine; | ||
@@ -63,17 +50,13 @@ } | ||
let a = index; | ||
for (; a <= input.length; a++) { | ||
for(; a <= input.length; a++){ | ||
c = input.charAt(a); | ||
if (a === input.length) | ||
targetLine += EOF; | ||
if (a === input.length) targetLine += EOF; | ||
else if (c === '\n') { | ||
targetLine += LF; | ||
break; | ||
} | ||
else | ||
targetLine += c; | ||
} else targetLine += c; | ||
} | ||
let line = 1; | ||
for (let i = 0; i < index; i++) { | ||
if (input.charAt(i) === '\n') | ||
line++; | ||
for(let i = 0; i < index; i++){ | ||
if (input.charAt(i) === '\n') line++; | ||
} | ||
@@ -83,7 +66,6 @@ // before lines | ||
let lb = b; | ||
while (before.length < linesBefore && lb > 0) { | ||
while(before.length < linesBefore && lb > 0){ | ||
lb = input.slice(0, b).lastIndexOf('\n'); | ||
before.unshift(input.slice(lb + 1, b) + LF); | ||
if (lb < 0) | ||
break; | ||
if (lb < 0) break; | ||
b = lb; | ||
@@ -94,3 +76,3 @@ } | ||
let la = a; | ||
while (a < input.length && after.length < linesAfter) { | ||
while(a < input.length && after.length < linesAfter){ | ||
la = input.indexOf('\n', a + 1); | ||
@@ -107,21 +89,32 @@ if (la < 0) { | ||
// generate lines | ||
let lines = [...before, targetLine, ...after]; | ||
let lines = [ | ||
...before, | ||
targetLine, | ||
...after | ||
]; | ||
let pad = 0; | ||
if (showLineNumbers) { | ||
pad = (line + after.length).toString().length + 6; | ||
lines = lines.map((s, i) => { | ||
lines = lines.map((s, i)=>{ | ||
const ln = i + (line - before.length); | ||
return ((ln === line ? RED : '') + | ||
((ln === line ? '> ' : '') + ln + RESET + ' │ ').padStart(pad + RESET.length) + | ||
s); | ||
return (ln === line ? RED : '') + ((ln === line ? '> ' : '') + ln + RESET + ' │ ').padStart(pad + RESET.length) + s; | ||
}); | ||
} | ||
// insert arrow ^^^^^ | ||
lines.splice(before.length + 1, 0, arrow({ col, message, size, pad })); | ||
lines.splice(before.length + 1, 0, arrow({ | ||
col, | ||
message, | ||
size, | ||
pad | ||
})); | ||
lines[before.length] = RED + lines[before.length] + RESET; | ||
lines.splice(before.length, 0, BAR.padStart(pad)); | ||
message = lines.join('\n'); | ||
return { line, col, message }; | ||
return { | ||
line, | ||
col, | ||
message | ||
}; | ||
}; | ||
exports.annotate = annotate; | ||
//# sourceMappingURL=index.js.map |
@@ -11,8 +11,4 @@ // colors | ||
const EOF = GREY + '<EOF>' + RESET; | ||
const arrow = ({ | ||
// line, | ||
col, message = '', pad = 0, size = 1, }) => BAR.padStart(pad, ' ') + | ||
RED + | ||
(('^'.repeat(size) + ' ').padStart(col + size, ' ') + message) + | ||
RESET; | ||
const arrow = ({ // line, | ||
col , message ='' , pad =0 , size =1 })=>BAR.padStart(pad, ' ') + RED + (('^'.repeat(size) + ' ').padStart(col + size, ' ') + message) + RESET; | ||
/** | ||
@@ -30,16 +26,15 @@ * Annotates a source code string given an index and a message. | ||
* @returns { line, col, message } | ||
*/ | ||
export const annotate = ({ message, input, index, linesBefore = 3, linesAfter = 3, size = 1, showLineNumbers = true, }) => { | ||
*/ export const annotate = ({ message , input , index , linesBefore =3 , linesAfter =3 , size =1 , showLineNumbers =true })=>{ | ||
if (index > input.length) { | ||
const pos = index.toLocaleString(); | ||
const size = input.length.toLocaleString(); | ||
const size1 = input.length.toLocaleString(); | ||
return { | ||
message: RED + `index ${pos} past buffer of size ${size}: ${pos} > ${size}` + RESET, | ||
message: RED + `index ${pos} past buffer of size ${size1}: ${pos} > ${size1}` + RESET | ||
}; | ||
} | ||
if (index < 0) { | ||
const pos = index.toLocaleString(); | ||
const size = input.length.toLocaleString(); | ||
const pos1 = index.toLocaleString(); | ||
const size2 = input.length.toLocaleString(); | ||
return { | ||
message: RED + `index ${pos} behind buffer of size ${size}` + RESET, | ||
message: RED + `index ${pos1} behind buffer of size ${size2}` + RESET | ||
}; | ||
@@ -52,6 +47,5 @@ } | ||
let b = index - 1; | ||
for (; b >= 0; b--, col++) { | ||
for(; b >= 0; b--, col++){ | ||
c = input.charAt(b); | ||
if (c === '\n') | ||
break; | ||
if (c === '\n') break; | ||
targetLine = c + targetLine; | ||
@@ -61,17 +55,13 @@ } | ||
let a = index; | ||
for (; a <= input.length; a++) { | ||
for(; a <= input.length; a++){ | ||
c = input.charAt(a); | ||
if (a === input.length) | ||
targetLine += EOF; | ||
if (a === input.length) targetLine += EOF; | ||
else if (c === '\n') { | ||
targetLine += LF; | ||
break; | ||
} | ||
else | ||
targetLine += c; | ||
} else targetLine += c; | ||
} | ||
let line = 1; | ||
for (let i = 0; i < index; i++) { | ||
if (input.charAt(i) === '\n') | ||
line++; | ||
for(let i = 0; i < index; i++){ | ||
if (input.charAt(i) === '\n') line++; | ||
} | ||
@@ -81,7 +71,6 @@ // before lines | ||
let lb = b; | ||
while (before.length < linesBefore && lb > 0) { | ||
while(before.length < linesBefore && lb > 0){ | ||
lb = input.slice(0, b).lastIndexOf('\n'); | ||
before.unshift(input.slice(lb + 1, b) + LF); | ||
if (lb < 0) | ||
break; | ||
if (lb < 0) break; | ||
b = lb; | ||
@@ -92,3 +81,3 @@ } | ||
let la = a; | ||
while (a < input.length && after.length < linesAfter) { | ||
while(a < input.length && after.length < linesAfter){ | ||
la = input.indexOf('\n', a + 1); | ||
@@ -105,20 +94,32 @@ if (la < 0) { | ||
// generate lines | ||
let lines = [...before, targetLine, ...after]; | ||
let lines = [ | ||
...before, | ||
targetLine, | ||
...after | ||
]; | ||
let pad = 0; | ||
if (showLineNumbers) { | ||
pad = (line + after.length).toString().length + 6; | ||
lines = lines.map((s, i) => { | ||
lines = lines.map((s, i)=>{ | ||
const ln = i + (line - before.length); | ||
return ((ln === line ? RED : '') + | ||
((ln === line ? '> ' : '') + ln + RESET + ' │ ').padStart(pad + RESET.length) + | ||
s); | ||
return (ln === line ? RED : '') + ((ln === line ? '> ' : '') + ln + RESET + ' │ ').padStart(pad + RESET.length) + s; | ||
}); | ||
} | ||
// insert arrow ^^^^^ | ||
lines.splice(before.length + 1, 0, arrow({ col, message, size, pad })); | ||
lines.splice(before.length + 1, 0, arrow({ | ||
col, | ||
message, | ||
size, | ||
pad | ||
})); | ||
lines[before.length] = RED + lines[before.length] + RESET; | ||
lines.splice(before.length, 0, BAR.padStart(pad)); | ||
message = lines.join('\n'); | ||
return { line, col, message }; | ||
return { | ||
line, | ||
col, | ||
message | ||
}; | ||
}; | ||
//# sourceMappingURL=index.js.map |
115
package.json
@@ -6,3 +6,3 @@ { | ||
"description": "beautifully annotate source code with a message, given an index, like a parser or compiler", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"license": "MIT", | ||
@@ -28,59 +28,76 @@ "repository": { | ||
"files": [ | ||
"dist" | ||
"dist", | ||
"!**/*.tsbuildinfo" | ||
], | ||
"scripts": { | ||
"start": "vite-open example/web.ts", | ||
"start:https": "vite-open --https example/web.ts", | ||
"build:watch": "tsc -p tsconfig.dist.json --outDir dist/esm --module esnext --watch & tsc -p tsconfig.dist.json --outDir dist/cjs --watch", | ||
"start:web": "vite-open example/web --https", | ||
"start:web:debugging": "vite-open example/web --https --debugging-this", | ||
"start:node": "onchange -i src example -- swcno example/node.ts", | ||
"build:watch": "tsc -p tsconfig.dist.json --outDir dist/types --watch & swc -w -C module.type=commonjs ./src -d dist/cjs -w & swc -w -C module.type=es6 ./src -d dist/esm", | ||
"build:dist": "npm run build:bundle && npm run build:min", | ||
"cov:watch": "jest --coverage --watchAll", | ||
"test": "echo ok", | ||
"test:node": "jest", | ||
"test:web": "web-test-runner", | ||
"clean": "rimraf dist", | ||
"docs": "dokio -o README.md && dprint fmt README.md", | ||
"test": "npm run test:node && npm run test:web", | ||
"test:node": "if find test -type f -iregex '.*\\.spec\\.\\(js\\|jsx\\|ts\\|tsx\\)$' | grep -q .; then jest; else echo no node tests; fi", | ||
"test:web": "if find test -type f -iregex '.*\\.spec\\.web\\.\\(js\\|jsx\\|ts\\|tsx\\)$' | grep -q .; then web-test-runner; else echo no web tests; fi", | ||
"cov": "jest --coverage", | ||
"docs": "documentation readme src --resolve=node --pe ts --re ts --re d.ts --github --section=API --markdown-toc-max-depth=3", | ||
"build": "npm run build:cjs && npm run build:esm && echo done.", | ||
"build:cjs": "tsc -p tsconfig.dist.json --outDir dist/cjs", | ||
"build:esm": "tsc -p tsconfig.dist.json --outDir dist/esm --module esnext && echo '{\"type\":\"module\"}' >dist/esm/package.json", | ||
"build:bundle": "esbuild dist/esm/index.js --bundle --format=esm --outfile=\"$(cat package.json | jq -r '.name').js\" && wc -c \"$(cat package.json | jq -r '.name').js\"", | ||
"build:min": "esbuild dist/esm/index.js --bundle --format=esm | terser --compress --module --mangle -o \"$(cat package.json | jq -r '.name').min.js\" && wc -c \"$(cat package.json | jq -r '.name').min.js\"", | ||
"lint": "eslint src && prettier --check src", | ||
"lint:fix": "eslint --fix src && prettier --write src", | ||
"clean": "rimraf dist", | ||
"prepack": "npm run clean && npm run build", | ||
"build": "npm run build:cjs & npm run build:esm & npm run build:types && echo done.", | ||
"build:cjs": "swc -C module.type=commonjs ./src -d dist/cjs", | ||
"build:esm": "swc -C module.type=es6 ./src -d dist/esm && echo '{\"type\":\"module\"}' >dist/esm/package.json", | ||
"build:types": "tsc -p tsconfig.dist.json --outDir dist/types", | ||
"build:bundle": "bunzee src/index.ts \"dist/$(cat package.json | jq -r '.name').js\"", | ||
"build:min": "bunzee -m src/index.ts \"dist/$(cat package.json | jq -r '.name').min.js\"", | ||
"start:web:https": "vite-open --https example/web.ts", | ||
"lint": "eslint src && dprint check", | ||
"lint:fix": "eslint --fix src && dprint fmt", | ||
"prepack": "npm run clean && npm run build && (npm run build:dist || echo unable to bundle)", | ||
"prepack:dry": "npm pack --dry-run", | ||
"prepush": "npm run lint && npm run test", | ||
"prepare": "husky install && node .pull-configs.js" | ||
"prepare": "husky install" | ||
}, | ||
"devDependencies": { | ||
"@n1kk/intspector": "^1.0.2", | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@stagas/documentation-fork": "^13.2.5", | ||
"@stagas/sucrase-jest-plugin": "^2.2.0-fork", | ||
"@swc-node/jest": "^1.4.3", | ||
"@tsconfig/node16": "^1.0.2", | ||
"@types/jest": "^27.4.0", | ||
"@types/node": "^17.0.18", | ||
"@typescript-eslint/eslint-plugin": "^5.12.0", | ||
"@typescript-eslint/parser": "^5.12.0", | ||
"@web/dev-server-rollup": "^0.3.15", | ||
"@web/test-runner": "^0.13.27", | ||
"esbuild": "^0.14.22", | ||
"eslint": "^8.9.0", | ||
"eslint-config-html-jsx": "^1.0.0", | ||
"eslint-plugin-import": "^2.25.4", | ||
"husky": "^7.0.4", | ||
"jest": "^27.5.1", | ||
"jest-browser-globals": "^25.1.0-beta", | ||
"onchange": "^7.1.0", | ||
"prettier": "^2.5.1", | ||
"@n1kk/intspector": "1.0.2", | ||
"@stagas/jest-node-exports-resolver": "1.1.5-require-basedir-2", | ||
"@swc-node/jest": "1.5.2", | ||
"@swc/cli": "0.1.57", | ||
"@swc/core": "1.2.198", | ||
"@tsconfig/node16": "1.0.3", | ||
"@types/audioworklet": "0.0.29", | ||
"@types/jest": "27.5.2", | ||
"@types/node": "17.0.42", | ||
"@types/webmidi": "2.0.6", | ||
"@typescript-eslint/eslint-plugin": "5.27.1", | ||
"@typescript-eslint/parser": "5.27.1", | ||
"@web/test-runner": "0.13.30", | ||
"bunzee": "^0.0.1", | ||
"chokidar": "3.5.3", | ||
"dprint": "0.29.1", | ||
"eslint": "8.17.0", | ||
"eslint-config-html-jsx": "1.0.0", | ||
"eslint-plugin-import": "2.26.0", | ||
"eslint-plugin-react": "7.30.0", | ||
"husky": "7.0.4", | ||
"jest": "27.5.1", | ||
"jest-browser-globals": "25.1.0-beta", | ||
"onchange": "7.1.0", | ||
"pull-configs": "^0.2.0", | ||
"rimraf": "^3.0.2", | ||
"swcno": "^0.1.1", | ||
"terser": "^5.10.0", | ||
"ts-jest": "^27.1.3", | ||
"ts-node": "^10.5.0", | ||
"typescript": "^4.5.5", | ||
"vite-open": "^1.2.0", | ||
"vite-web-test-runner-plugin": "^0.1.0" | ||
} | ||
"rimraf": "3.0.2", | ||
"swcno": "0.1.1", | ||
"ts-jest": "27.1.5", | ||
"ts-node": "10.8.1", | ||
"typescript": "4.7.3", | ||
"vite-open": "^2.3.0", | ||
"wtr-plugin-vite": "^0.0.3" | ||
}, | ||
"trustedDependencies": [ | ||
"@stagas/jest-node-exports-resolver", | ||
"bunzee", | ||
"decarg", | ||
"pull-configs", | ||
"rollup-plugin-debug", | ||
"vite-open", | ||
"wtr-plugin-vite" | ||
], | ||
"types": "./dist/types/index.d.ts" | ||
} |
194
README.md
@@ -1,32 +0,48 @@ | ||
<h1 align="center">annotate-code</h1> | ||
<h1> | ||
annotate-code <a href="https://npmjs.org/package/annotate-code"><img src="https://img.shields.io/badge/npm-v2.0.3-F00.svg?colorA=000"/></a> <a href="src"><img src="https://img.shields.io/badge/loc-120-FFF.svg?colorA=000"/></a> <a href="https://cdn.jsdelivr.net/npm/annotate-code@2.0.3/dist/annotate-code.min.js"><img src="https://img.shields.io/badge/brotli-744b-333.svg?colorA=000"/></a> <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-F0B.svg?colorA=000"/></a> | ||
</h1> | ||
<p align="center"> | ||
<p></p> | ||
beautifully annotate source code with a message, given an index, like a parser or compiler | ||
</p> | ||
<p align="center"> | ||
<a href="#install"> 🔧 <strong>Install</strong></a> | ||
· <a href="#example"> 🧩 <strong>Example</strong></a> | ||
· <a href="#api"> 📜 <strong>API docs</strong></a> | ||
· <a href="https://github.com/stagas/annotate-code/releases"> 🔥 <strong>Releases</strong></a> | ||
· <a href="#contribute"> 💪🏼 <strong>Contribute</strong></a> | ||
· <a href="https://github.com/stagas/annotate-code/issues"> 🖐️ <strong>Help</strong></a> | ||
</p> | ||
<h4> | ||
<table><tr><td title="Triple click to select and copy paste"> | ||
<code>npm i annotate-code </code> | ||
</td><td title="Triple click to select and copy paste"> | ||
<code>pnpm add annotate-code </code> | ||
</td><td title="Triple click to select and copy paste"> | ||
<code>yarn add annotate-code</code> | ||
</td></tr></table> | ||
</h4> | ||
*** | ||
## Examples | ||
## Install | ||
<details id="example$basic" title="basic" open><summary><span><a href="#example$basic">#</a></span> <code><strong>basic</strong></code></summary> <ul> <details id="source$basic" title="basic source code" ><summary><span><a href="#source$basic">#</a></span> <code><strong>view source</strong></code></summary> <a href="example/basic.ts">example/basic.ts</a> <p> | ||
```sh | ||
$ npm i annotate-code | ||
``` | ||
## Example | ||
```ts | ||
import { annotate } from 'annotate-code' | ||
console.log( | ||
const input = `01234 | ||
6789 and a 2 | ||
line 3 | ||
and 4 | ||
another 5 | ||
error should be here 6 | ||
and 7 | ||
more 8 | ||
lines 9 | ||
` | ||
const message = 'some error message' | ||
let i = 0 | ||
const print = (m: string) => { | ||
console.log(++i + ' -------------------------------------') | ||
console.log(m) | ||
} | ||
print( | ||
annotate({ | ||
message: 'some error message', | ||
message, | ||
index: 48, | ||
@@ -37,40 +53,127 @@ size: 6, | ||
) | ||
``` | ||
<img src="demo.png"> | ||
print( | ||
annotate({ | ||
message, | ||
index: 0, | ||
input, | ||
}).message | ||
) | ||
## API | ||
print( | ||
annotate({ | ||
message, | ||
index: input.length, | ||
input, | ||
}).message | ||
) | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
print( | ||
annotate({ | ||
message, | ||
index: 0, | ||
input, | ||
linesAfter: 5, | ||
}).message | ||
) | ||
#### Table of Contents | ||
print( | ||
annotate({ | ||
message, | ||
index: 0, | ||
input, | ||
linesAfter: 100, | ||
}).message | ||
) | ||
* [annotate](#annotate) | ||
* [Parameters](#parameters) | ||
print( | ||
annotate({ | ||
message, | ||
index: input.length, | ||
linesBefore: 5, | ||
input, | ||
}).message | ||
) | ||
### annotate | ||
print( | ||
annotate({ | ||
message, | ||
index: input.length, | ||
linesBefore: 100, | ||
input, | ||
}).message | ||
) | ||
[src/index.ts:44-155](https://github.com/stagas/annotate-code/blob/24f21ac6f7ca15849a13a7dc3d2928995df903f3/src/index.ts#L44-L155 "Source code on GitHub") | ||
print( | ||
annotate({ | ||
message, | ||
index: 7, | ||
linesAfter: 100, | ||
input, | ||
}).message | ||
) | ||
Annotates a source code string given an index and a message. | ||
print( | ||
annotate({ | ||
message, | ||
index: 5, | ||
linesBefore: 2, | ||
input, | ||
}).message | ||
) | ||
#### Parameters | ||
print( | ||
annotate({ | ||
message, | ||
index: 0, | ||
linesAfter: 1, | ||
input, | ||
}).message | ||
) | ||
* `settings` **{message: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), input: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), index: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), linesBefore: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, linesAfter: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, size: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, showLineNumbers: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?}**  | ||
print( | ||
annotate({ | ||
message, | ||
index: 0, | ||
linesAfter: 1, | ||
input: `12345`, | ||
}).message | ||
) | ||
* `settings.message` The message to display | ||
* `settings.input` The code to annotate | ||
* `settings.index` The index position | ||
* `settings.linesBefore` How many lines before to show (optional, default `3`) | ||
* `settings.linesAfter` How many lines after to show (optional, default `3`) | ||
* `settings.size` The size of the arrows ^^^^ (optional, default `1`) | ||
* `settings.showLineNumbers` Whether to show line numbers (optional, default `true`) | ||
print( | ||
annotate({ | ||
message, | ||
index: 0, | ||
input: ``, | ||
}).message | ||
) | ||
Returns **{line: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, col: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, message: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}**  | ||
print( | ||
annotate({ | ||
message, | ||
index: 1, | ||
input: ``, | ||
}).message | ||
) | ||
## Contribute | ||
print( | ||
annotate({ | ||
message, | ||
index: -1, | ||
input: `abc`, | ||
}).message | ||
) | ||
``` | ||
[Fork](https://github.com/stagas/annotate-code/fork) or | ||
[edit](https://github.dev/stagas/annotate-code) and submit a PR. | ||
</p> | ||
</details></ul></details> | ||
## API | ||
<p> <details id="annotate$1" title="Function" open><summary><span><a href="#annotate$1">#</a></span> <code><strong>annotate</strong></code><em>({ index, input, linesAfter, linesBefore, message, showLineNumbers, size })</em> – Annotates a source code string given an index and a message.</summary> <a href="src/index.ts#L44">src/index.ts#L44</a> <ul> <p> <details id="settings$3" title="Parameter" ><summary><span><a href="#settings$3">#</a></span> <code><strong>settings</strong></code> </summary> <ul><p>{<p> <details id="index$7" title="Property" ><summary><span><a href="#index$7">#</a></span> <code><strong>index</strong></code> – The index position</summary> <a href="src/index.ts#L55">src/index.ts#L55</a> <ul><p>number</p> </ul></details><details id="input$6" title="Property" ><summary><span><a href="#input$6">#</a></span> <code><strong>input</strong></code> – The code to annotate</summary> <a href="src/index.ts#L54">src/index.ts#L54</a> <ul><p>string</p> </ul></details><details id="linesAfter$9" title="Property" ><summary><span><a href="#linesAfter$9">#</a></span> <code><strong>linesAfter</strong></code> – How many lines after to show</summary> <a href="src/index.ts#L57">src/index.ts#L57</a> <ul><p>number</p> </ul></details><details id="linesBefore$8" title="Property" ><summary><span><a href="#linesBefore$8">#</a></span> <code><strong>linesBefore</strong></code> – How many lines before to show</summary> <a href="src/index.ts#L56">src/index.ts#L56</a> <ul><p>number</p> </ul></details><details id="message$5" title="Property" ><summary><span><a href="#message$5">#</a></span> <code><strong>message</strong></code> – The message to display</summary> <a href="src/index.ts#L53">src/index.ts#L53</a> <ul><p>string</p> </ul></details><details id="showLineNumbers$11" title="Property" ><summary><span><a href="#showLineNumbers$11">#</a></span> <code><strong>showLineNumbers</strong></code> – Whether to show line numbers</summary> <a href="src/index.ts#L59">src/index.ts#L59</a> <ul><p>boolean</p> </ul></details><details id="size$10" title="Property" ><summary><span><a href="#size$10">#</a></span> <code><strong>size</strong></code> – The size of the arrows ^^^^</summary> <a href="src/index.ts#L58">src/index.ts#L58</a> <ul><p>number</p> </ul></details></p>}</p> </ul></details> <p><strong>annotate</strong><em>({ index, input, linesAfter, linesBefore, message, showLineNumbers, size })</em> => <ul>{<p> <details id="col$14" title="Property" ><summary><span><a href="#col$14">#</a></span> <code><strong>col</strong></code> </summary> <a href="src/index.ts#L62">src/index.ts#L62</a> <ul><p>number</p> </ul></details><details id="line$13" title="Property" ><summary><span><a href="#line$13">#</a></span> <code><strong>line</strong></code> </summary> <a href="src/index.ts#L61">src/index.ts#L61</a> <ul><p>number</p> </ul></details><details id="message$15" title="Property" ><summary><span><a href="#message$15">#</a></span> <code><strong>message</strong></code> </summary> <a href="src/index.ts#L63">src/index.ts#L63</a> <ul><p>string</p> </ul></details></p>}</ul></p></p> </ul></details></p> | ||
## Contributing | ||
[Fork](https://github.com/stagas/annotate-code/fork) or [edit](https://github.dev/stagas/annotate-code) and submit a PR. | ||
All contributions are welcome! | ||
@@ -80,3 +183,2 @@ | ||
MIT © 2021 | ||
[stagas](https://github.com/stagas) | ||
<a href="LICENSE">MIT</a> © 2022 [stagas](https://github.com/stagas) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
48973
13
379
183
32
1