/annotate-code

beautifully annotate source code with a message, given an index, like a parser or compiler

Primary LanguageTypeScript

annotate-code

beautifully annotate source code with a message, given an index, like a parser or compiler

🔧 Install · 🧩 Example · 📜 API docs · 🔥 Releases · 💪🏼 Contribute · 🖐️ Help


Install

$ npm i annotate-code

Example

import { annotate } from 'annotate-code'

console.log(
  annotate({
    message: 'some error message',
    index: 48,
    size: 6,
    input,
  }).message
)

API

Table of Contents

annotate

src/index.ts:44-155

Annotates a source code string given an index and a message.

Parameters

  • settings {message: string, input: string, index: number, linesBefore: number?, linesAfter: number?, size: number?, showLineNumbers: boolean?}

    • 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)

Returns {line: number?, col: number?, message: string}

Contribute

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT © 2021 stagas