How to use the cardinal.highlightFileSync function in cardinal

To help you get started, we’ve selected a few cardinal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tapjs / node-tap / lib / reporter / pretty-source.js View on Github external
module.exports = (diag) => {
  if (!diag || typeof diag.source !== 'string')
    return null

  if (!diag.source || !diag.at || !diag.at.line || !diag.at.file)
    return diag.source

  const source = diag.source

  const at = diag.at
  try {
    const lines = highlightFileSync(at.file, {
      jsx: true,
      theme,
    }).split('\n')

    const ctx = 3
    const startLine = Math.max(at.line - ctx, 0)
    const endLine = Math.min(at.line + ctx, lines.length)
    const numLen = endLine.toString().length + 1

    const caret = at.column
      ? [
        `  ${new Array(numLen).join(' ')
          } ` + hex('#777')('| ') +
          red(`${new Array(at.column).join('-')}${bold('^')}`)
      ] : []

cardinal

Syntax highlights JavaScript code with ANSI colors to be printed to the terminal.

MIT
Latest version published 7 years ago

Package Health Score

67 / 100
Full package analysis