@idio/debug
v1.2.3
Published
The Fork Of Debug For Node.JS Written In ES6 And Optimised With JavaScript Compiler.
Downloads
63
Readme
@idio/debug
@idio/debug
is the fork of the popular debug
package that was rewritten in modern JS using the ES6 modules, to be able to compile it with Closure Compiler. Currently, only the Node.JS version is supported.
yarn add @idio/debug
Table Of Contents
API
The package is available by importing its default function:
import debug from '@idio/debug'
debug(
namespace: string,
): debugFunction
Creates a debug function for the given namespace.
import debug from '@idio/debug'
const log = debug('example')
log('hello')
log('world')
example hello +0ms
example world +4ms
_debug.Env
: An environment.
| Name | Type | Description |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| init* | function(debug.DebugFunction) | Env-specific initialization logic for debug
instances. |
| log* | function(...) | The logging function. |
| __formatArgs_ | function(this: _debug.DebugFunction, !Array) | Apply env-specific formatting (colors, etc.). |
| save* | !Function | Save namespaces
. |
| load* | !Function | Load namespaces
. |
| formatters* | Object<string, function(!Object): string> | Map of special "%n" handling functions, for the debug "format" argument. Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". |
| useColors* | !Function | Is stdout a TTY? Colored output is enabled when true
. |
| colors* | !Array<number> | The array of supported colors. |
| inspectOpts* | !Object<string, *> | The options from the env variables, e.g., DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
. |
_debug.DebugContext
| Name | Type | Description | | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | | namespace* | string | The namespace for which the debug function was setup. | | enabled* | boolean | Whether the debug function is enabled. | | useColors* | boolean | If the environment uses colors. | | diff* | number | The diff between the prev time and current time. | | prev* | number | The previous time. | | curr* | number | The current time. | | log | function(...) | The manually set logging function that overrides the environment log function. | | __color__ | (number | string) | The color for the namespace. | | destroy* | function(this: _debug.DebugFunction): boolean | Removes the debug function from the namespace. | | extend* | function(this: _debug.DebugFunction, string, string): _debug.DebugFunction | Using the debug function, creates a new one. |
function(this:_debug.DebugContext, ...*)
_debug.DebugFunction
: The setup debug function.
Modifiers
The modifiers can be used to print information in formatted way.
| Modifier | Action | | -------- | -------------------------------------- | | %O | Multiline inspect. | | %o | Single line inspect. | | %f | File-size format of bytes, e.g., 10MB. | | %fy | File-size in yellow. | | %fr | File-size in red. | | %fb | File-size in blue. | | %fg | File-size in green. | | %fc | File-size in cyan | | %fm | File-size in magenta. |
import Debug from '@idio/debug'
const debug = Debug('example')
debug('hello %O', { test: 'ok' })
debug('world %f', 105248)
example hello { test: 'ok' } +0ms
example world 102.78KB +16ms
Copyright
Original Authors:
- TJ Holowaychuk
- Nathan Rajlich
- Andrew Rhyne