Giter Site home page Giter Site logo

deno_dbg's Introduction

dbg

A dbg(…) function for Deno. Heavily inspired by Rusts' dbg!(…) macro.

Examples

import { dbg } from "https://deno.land/x/dbg/mod.ts";

const a = 2;
const b = dbg(a * 2) + 1;
//        ^-- [examples/main.ts:4:11] 4 (number)
console.assert(b === 5);

factorial implementation(examples/factorial.ts):

import { dbg } from "https://deno.land/x/dbg/mod.ts";

function factorial(n: number): number {
  if (dbg(n <= 1)) {
    return dbg(n);
  }

  return dbg(n * factorial(n - 1));
}

function main() {
  dbg(factorial(5));
}

if (import.meta.main) {
  main();
}

This prints:

Advanced Features

Not just console.debug, but more:

  • colorful output(can disable by NO_COLOR ENVIRONMENT)
  • print file name, function name, line and column
  • auto detect --allow-read permission(see Read Permission)

Read Permission

Run with --allow-read flag:

$ deno run --allow-read ./examples/main.ts
[examples/main.ts:4:11] 4 (number)

Run without --allow-read flag:

$ deno run ./examples/main.ts
No read access to <CWD>, use full path. Or run again with --allow-read. See https://github.com/justjavac/deno_dbg#read-permission
[/Users/justjavac/tmp/dbg/examples/main.ts:4:11] 4 (number)

License

deno_dbg is released under the MIT License. See the bundled LICENSE file for details.

deno_dbg's People

Contributors

cgqaq avatar justjavac avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

cgqaq

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.