1.2.3 • Published 5 years ago

@idio/debug v1.2.3

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

@idio/debug

npm version

@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.

NameTypeDescription
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*!FunctionSave namespaces.
load*!FunctionLoad 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*!FunctionIs 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

NameTypeDescription
namespace*stringThe namespace for which the debug function was setup.
enabled*booleanWhether the debug function is enabled.
useColors*booleanIf the environment uses colors.
diff*numberThe diff between the prev time and current time.
prev*numberThe previous time.
curr*numberThe current time.
logfunction(...*)The manually set logging function that overrides the environment log function.
color*(number | string)The color for the namespace.
destroy*function(this: _debug.DebugFunction): booleanRemoves the debug function from the namespace.
extend*function(this: _debug.DebugFunction, string, string): _debug.DebugFunctionUsing 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.

ModifierAction
%OMultiline inspect.
%oSingle line inspect.
%fFile-size format of bytes, e.g., 10MB.
%fyFile-size in yellow.
%frFile-size in red.
%fbFile-size in blue.
%fgFile-size in green.
%fcFile-size in cyan
%fmFile-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

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago