0.0.18 • Published 1 month ago

@reyalp/debug-utils v0.0.18

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
1 month ago

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" }
        ]
    }
}
0.0.18

1 month ago

0.0.17

2 months ago

0.0.16

3 months ago

0.0.15

3 months ago

0.0.14

3 months ago

0.0.13

4 months ago

0.0.11

4 months ago

0.0.9

4 months ago

0.0.8

4 months ago

0.0.7

4 months ago

0.0.6

4 months ago

0.0.5

4 months ago

0.0.4

4 months ago

0.0.3

4 months ago

0.0.2

4 months ago

0.0.1

4 months ago