The Fork Of Debug For Node.JS Written In ES6 And Optimised With JavaScript Compiler.
npm install @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.
``sh`
yarn add @idio/debug
- Table Of Contents
- API
- debug(namespace: string): debugFunction
* _debug.Env
* _debug.DebugContext
* _debug.DebugFunction
- Modifiers
- Copyright
The package is available by importing its default function:
`js`
import debug from '@idio/debug'
namespace: string,
): debugFunctionCreates a debug function for the given namespace.
`js
import debug from '@idio/debug'
const log = debug('example')
log('hello')
log('world')
```
example hello +0ms
example world +4ms
Show Types
___debug.Env__: An environment.
| Name | Type | Description |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| __init*__ | function(_debug.DebugFunction) | Env-specific initialization logic for debug instances. |namespaces
| __log__ | function(...) | The logging function. |
| __formatArgs*__ | function(this: _debug.DebugFunction, !Array) | Apply env-specific formatting (colors, etc.). |
| __save*__ | !Function | Save . |namespaces
| __load*__ | !Function | Load . |true
| __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 . |DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
| __colors*__ | !Array<number> | The array of supported colors. |
| __inspectOpts__ | !Object<string, > | The options from the env variables, e.g., . |
| 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.
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. |
`js
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
Original Authors:
- TJ Holowaychuk
- Nathan Rajlich
- Andrew Rhyne
---
![]() | © Art Deco for Idio 2019 | alt="Tech Nation Visa"> | Tech Nation Visa Sucks |
|---|