You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

annotate-code

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

annotate-code

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

2.0.4
latest
Source
npmnpm
Version published
Weekly downloads
8
Maintainers
1
Weekly downloads
 
Created
Source

annotate-code

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

npm i annotate-code pnpm add annotate-code yarn add annotate-code

Examples

# basic
    # view source example/basic.ts

    import { annotate } from 'annotate-code'
    
    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,
        index: 48,
        size: 6,
        input,
      }).message
    )
    
    print(
      annotate({
        message,
        index: 0,
        input,
      }).message
    )
    
    print(
      annotate({
        message,
        index: input.length,
        input,
      }).message
    )
    
    print(
      annotate({
        message,
        index: 0,
        input,
        linesAfter: 5,
      }).message
    )
    
    print(
      annotate({
        message,
        index: 0,
        input,
        linesAfter: 100,
      }).message
    )
    
    print(
      annotate({
        message,
        index: input.length,
        linesBefore: 5,
        input,
      }).message
    )
    
    print(
      annotate({
        message,
        index: input.length,
        linesBefore: 100,
        input,
      }).message
    )
    
    print(
      annotate({
        message,
        index: 7,
        linesAfter: 100,
        input,
      }).message
    )
    
    print(
      annotate({
        message,
        index: 5,
        linesBefore: 2,
        input,
      }).message
    )
    
    print(
      annotate({
        message,
        index: 0,
        linesAfter: 1,
        input,
      }).message
    )
    
    print(
      annotate({
        message,
        index: 0,
        linesAfter: 1,
        input: `12345`,
      }).message
    )
    
    print(
      annotate({
        message,
        index: 0,
        input: ``,
      }).message
    )
    
    print(
      annotate({
        message,
        index: 1,
        input: ``,
      }).message
    )
    
    print(
      annotate({
        message,
        index: -1,
        input: `abc`,
      }).message
    )
    

API

# annotate({ index, input, linesAfter, linesBefore, message, showLineNumbers, size }) – Annotates a source code string given an index and a message. src/index.ts#L44

Contributing

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT © 2022 stagas

Keywords

annotate

FAQs

Package last updated on 30 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts