Skip to content
Vitali Haradkou edited this page Apr 10, 2024 · 1 revision

Installation

pnpm: pnpm add @rslike/dbg -D npm: npm i @rslike/dbg -D yarn: yarn add @rslike/dbg -D

dbg Usage

import { dbg } from '@rslike/dbg';
// or import default
import dbg from '@rslike/dbg';


const a = 123;

dbg(() => a); // a: 123

Advanced Usage

It also supports BigInt, Symbol and undefined and null.

Example:

// BigInt
const a = 123n
dbg(() => a) // a: 123n

// Symbol
const b = Symbol('foo')
dbg(() => b) // b: Symbol(foo)

const information = dbg(() => b, {skipConsoleLog: true}) // nothing to print

console.log('variable name: ', information.name) // variable name: b
console.log('type: ', information.type) // type: symbol

Options

  • fn - arrow function.
  • opts - object with next arguments
    • prefix - prefix before message. Default is dbg |
    • outputFunction - function to print output. Default is console.log
    • delimiter - delimiter between variable name and it's value.

Returns

Returns an object with next fields:

  • name - variable name
  • type - returns from typeof operator.
  • value - variable value.
  • prefix - called prefix from options
  • delimiter - called delimiter from options
Clone this wiki locally