Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Tiny debug tool (~500 bytes) for terminal and browser inspired by debug-js/debug API.

License

Notifications You must be signed in to change notification settings

localnerve/debug

 
 

Repository files navigation

@localnerve/debug

Tiny debug tool (~600 bytes) for terminal and browser inspired by debug-js/debug API.

Motivation

Forked from @wbe/debug, this was built in order to be as light as possible for terminal and browser, as the same way as the great debug-js/debug tool, with a few added debug-js/debug parity features. The package is less than 10k unpacked on disk, and published directly from Github with provenance.

Installation

$ npm i @localnerve/debug

debug node

DEBUG=* node file.js

file.js:

import debug from "@localnerve/debug"
const log = debug("namespace")
log("hello") // "namespace hello"

process.env.DEBUG value can be defined as a specific namespace too:

DEBUG=namespace-1 node file.js

Only debug function declaration with namespace-1 declared as namespace will be printed in the console:

import debug from "@localnerve/debug"
const log = debug("namespace-1")
log("hello") // "namespace-1 hello"

process.env.DEBUG value accept "one glob parameter level":

DEBUG=config:* node file.js

Every debug function declaration with namespace config:{somestring} will be logged.

debug in browser

In the same way as nodejs usage, debug is browser compatible with the same API. The only difference is we need to set the current namespace in localStorage.

Add on your browser localStorage:

localStorage.debug = "foo"

Use debug in javascript:

// es6 import
import debug from "@localnerve/debug"
const log = debug("foo")
log("bar") // "foo bar"

Examples

Install dependencies:

Start example:

# browser example
npm run dev:example-browser
# node example
npm run dev:example-dev

Credits

Willy Brauner

Licence

MIT

About

Tiny debug tool (~500 bytes) for terminal and browser inspired by debug-js/debug API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 89.6%
  • SCSS 9.0%
  • HTML 1.4%