An open API service indexing awesome lists of open source software.

https://github.com/idiocc/debug

The Fork Of Debug For Node That Uses Modern JS.
https://github.com/idiocc/debug

Last synced: 11 months ago
JSON representation

The Fork Of Debug For Node That Uses Modern JS.

Awesome Lists containing this project

README

          

# @idio/debug

[![npm version](https://badge.fury.io/js/%40idio%2Fdebug.svg)](https://npmjs.org/package/@idio/debug)

`@idio/debug` is the fork of the popular [`debug`](https://github.com/visionmedia/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

- [Table Of Contents](#table-of-contents)
- [API](#api)
- [`debug(namespace: string): debugFunction`](#debugnamespace-string-debugfunction)
* [`_debug.Env`](#type-_debugenv)
* [`_debug.DebugContext`](#type-_debugdebugcontext)
* [`_debug.DebugFunction`](#type-_debugdebugfunction)
- [Modifiers](#modifiers)
- [Copyright](#copyright)

## API

The package is available by importing its default function:

```js
import debug from '@idio/debug'
```

## `debug(`
  `namespace: string,`
`): debugFunction`

Creates 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. |
| __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. |

```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
```

## Copyright

Original Authors:

- TJ Holowaychuk
- Nathan Rajlich
- Andrew Rhyne

---




Art Deco


© Art Deco for Idio 2019


Idio




Tech Nation Visa


Tech Nation Visa Sucks