package
preview source code for CLI
npm install cli-source-previewGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 2 packages.
54.9 kB
Includes dependencies.
Latest published Sep 19, 2016
Preview source code for CLI, useful when display error message with related source.
$ npm install cli-source-preview'use strict'
const preview = require('cli-source-preview')
const source = `
'use strict'
const chalk = require('chalk')
const PREVIEW_OPTS = {
offset: 5,
lineNumber: true,
delimiter: '\\n'
}
const DELIMITER = '-'.repeat(40)
function rightPad (text, width) {
return text + (width > text.length ? ' '.repeat(width - text.length) : '')
}
`
// preview line 10
console.log(preview(source, 10))
// preview line 5~8
console.log(preview(source, [5, 8]))
// preview line 12:6
console.log(preview(source, { line: 12, column: 6}))
preview (source, line, options)Get source code parts by line and return with highlighted (CLI) string.
[ Number, Number ], the line range to preview{ line: Number, column: Number }, preivew specified line/columnReturn preview parts string of source
preview.readSource (source, from, to, offset, delimiter)Read source code by from/to line range.
options.offsetoptions.delimiterReturn readed source code lines as format:
return [{
number: Number,
source: String
}, ...]MIT