@reyalp/debug-utils
TypeScript icon, indicating that this package has built-in type declarations

0.0.18 • Public • Published

debug-utils

debug utilities via typescript transformer

source_location

main.ts:

import { source_location } from '@reyalp/debug-utils'

function foo() {
    function bar() {
        console.log(source_location.file.fullname)
        console.log(source_location.line)
        console.log(source_location.sympath)
        console.log(source_location.up.sympath)

        use_source_location('hello')
    }
}

function use_source_location(v: string, caller = source_location.up.sympath) {
    console.log(v, caller)
}

transpiles to:

function foo() {
    function bar() {
        console.log('main.ts')
        console.log(6)
        console.log('foo.bar')
        console.log('foo')

        use_source_location('hello', 'foo.bar')
    }
}

function use_source_location(v, caller) {
    console.log(v, caller)
}

introspect, quoteval

import { introspect,  } from '@reyalp/debug-utils'

const [expr, val] = introspect(1 + 2 + 3)
console.log(quoteval(1 + 2 + 3))

transpiles to:

const [expr, val] = ['1 + 2 + 3', 1 + 2 + 3]
console.log(`1 + 2 + 3 = ${1 + 2 + 3}`)

Logger

main.ts

import { Logger } from '@reyalp/debug-utils'

const logger = Logger.create()

function foo() {
    logger.info('hello').dump(1 + 2 + 3)
}

foo()

prints:

01-29 12:57:30.771 I main:6 foo: hello 1 + 2 + 3 = 6

tsconfig.json setup

see ts-patch

{
    "compilerOptions": {
        "plugins": [
          { "transform": "@reyalp/debug-utils/lib/transform" }
        ]
    }
}

Package Sidebar

Install

npm i @reyalp/debug-utils

Weekly Downloads

2

Version

0.0.18

License

UNLICENSED

Unpacked Size

85 kB

Total Files

21

Last publish

Collaborators

  • reyalp_