log-editor
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

log-editor

NPM version

Fan of using console.log to debugger? Use your editor to inspect the log instead of scrolling the congested terminal.

- console.log(largeObject)
+ console.logEditor(largeObject)

Install

Only works in Node.js environment.

npm i -D log-editor

Add the following statement at the very beginning of your script:

// inject to `console`
import 'log-editor/console'

Then use console.logEditor instead of console.log whenever you want to see the result in editor. It will launch the corresponsing editor powered by launch_editor.

console.logEditor(largeObject)

or directly import without injection

import { logEditor } from 'log-editor'

Options

Named log

Pass a second argument to specify the key. When calling same key for multiple times, the same temp file will be used and overrides the previous content.

console.logEditor(largeObject, 'foo')

To accumulate the result of multiple calls, setting the override to false.

console.logEditor('message 1', 'key', { override: false })
console.logEditor('message 2', 'key', { override: false })

File Extension

By default, log-editor will use log or json as the temp file's extension. You can change it by passing extension in the options so your editor could provide proper syntax hightlight for you.

const code = `import 'log-editor'`

console.logEditor(code, 'code', { extension: 'ts' })

console.logEditor({ foo: 'bar' }) // will auto infer to use `json` as extension
console.logEditor('bar') // will use `log` as extension

Sponsors

License

MIT License © 2021 Anthony Fu

Readme

Keywords

none

Package Sidebar

Install

npm i log-editor

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

11.9 kB

Total Files

10

Last publish

Collaborators

  • antfu