debug.trace
A small trace utility that allows debugging info to be printed from any function pipeline.
Why not just console.log?
I'm lazy. It takes a few seconds to convert some arrow functions into
a form that allows console.log
.
For example,
const add = x + y // What was x and y?// I have to modify the add function with curly braces and a return.const add = { console console return x + y} // Or with trace I can leave everything inline, and still have the same effect.const add = x + y // Can even trace the result before returning.const add = x + y
If you use compose from Ramda or Lodash, then you
can simply sprinkle trace
s throughout the pipeline.
const R = const trace = const f = R // prints "before multiply 9", "result 18", then returns 18
Usage
const trace = const x = 11 // prints 'what is x? 1'
You can also import to globals automatically.
API
trace :: String -> A -> A
Prints a message and value, then return the original value. Arguments are curried.
const trace = // => 'Hello World' is printed'World' // => 'Hello World' is printed === 'y' // true
traceP :: String -> Promise A -> Promise A
Prints a message and resolved promise value, then return the promise. Arguments are curried.
const traceP = traceP // => 'Hello World' is printedPromise // => 'Hello World' is printed //resolves to true
traceStack :: String -> A -> A
Prints a message and value, then prints the stack trace, and returns original value. Arguments are curried.
const traceStack = traceStack // => 'Hello World' is printed// stack trace is printed'World' // => 'Hello World' is printed// stack trace is printed === 'y' // true// stack trace is printed