npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

logit-js

v0.2.0

Published

lightweight debug utility

Downloads

13

Readme

logit-js

Logit-js writes informative console logs into javascript files. It can be used as a command line tool or integrated into an editor which is its main use case. It is built upon several small babel plugins in combination with prettier code formatting.

Actively developed. Stable version not yet available.

Current features

  • variable logs after basic variable declarations and variable declarations using es6 destructuring
  • variable logs after assignment expressions and update expressions
  • variable logs of parameter values inside normal functions and arrow functions
  • adds line and column number by default
  • option --verbose prints function names, typeof info and informative logs inside if statements in region
  • option --remove deletes all console logs in region

Input

let bar = 'hello ';
let foo = 'world';
let helloWorld = bar + foo;

const testObject = { hello: 'Hi', world: 'Earth' };
const { hello, world } = testObject;

if (bar.length >= 4) {
    sayHiWithFancyArrowFunction('Alice');
} else if (bar.length < 4) {
    sayHiTo('Bob');
} else {
    sayHiTo('God');
}

function sayHiTo(name) {
    return bar + name;
}
const sayHiWithFancyArrowFunction = name => {
    return bar + name;
};

Output Logit Default

let bar = 'hello ';
console.log('2:0', 'bar :', bar);
let foo = 'world';
console.log('4:0', 'foo :', foo);
let helloWorld = bar + foo;
console.log('6:0', 'helloWorld :', helloWorld);

const testObject = { hello: 'Hi', world: 'Earth' };
console.log('9:0', 'testObject :', testObject);
const { hello, world } = testObject;
console.log('11:0', 'world :', world);
console.log('12:0', 'hello :', hello);

if (bar.length >= 4) {
    sayHiWithFancyArrowFunction('Alice');
} else if (bar.length < 4) {
    sayHiTo('Bob');
} else {
    sayHiTo('God');
}

function sayHiTo(name) {
    console.log('23:4', 'name :', name);
    return bar + name;
}
const sayHiWithFancyArrowFunction = name => {
    console.log('27:4', 'name :', name);
    return bar + name;
};
console.log('30:0', 'sayHiWithFancyArrowFunction :', sayHiWithFancyArrowFunction);

Output Logit Verbose

let bar = 'hello ';
console.log('2:0', 'bar :', bar);
console.log('typeof bar :', typeof bar);
let foo = 'world';
console.log('5:0', 'foo :', foo);
console.log('typeof foo :', typeof foo);
let helloWorld = bar + foo;
console.log('8:0', 'helloWorld :', helloWorld);
console.log('typeof helloWorld :', typeof helloWorld);

const testObject = { hello: 'Hi', world: 'Earth' };
console.log('12:0', 'testObject :', testObject);
console.log('typeof testObject :', typeof testObject);
const { hello, world } = testObject;
console.log('15:0', 'world :', world);
console.log('typeof world :', typeof world);
console.log('17:0', 'hello :', hello);
console.log('typeof hello :', typeof hello);

if (bar.length >= 4) {
    console.log('21:4', 'In IfStatement (bar.length >= 4)');
    sayHiWithFancyArrowFunction('Alice');
} else if (bar.length < 4) {
    console.log('24:4', 'In IfStatement (bar.length < 4)');
    sayHiTo('Bob');
} else {
    console.log('27:4', 'In ElseStatement.');
    sayHiTo('God');
}

function sayHiTo(name) {
    console.log('32:4', 'Function sayHiTo', 'name :', name);
    console.log('typeof name :', typeof name);
    return bar + name;
}
const sayHiWithFancyArrowFunction = name => {
    console.log('37:4', 'Function sayHiWithFancyArrowFunction', 'name :', name);
    console.log('typeof name :', typeof name);
    return bar + name;
};
console.log('41:0', 'sayHiWithFancyArrowFunction :', sayHiWithFancyArrowFunction);
console.log('typeof sayHiWithFancyArrowFunction :', typeof sayHiWithFancyArrowFunction);

Example Usage Emacs

Example Usage Emacs

Example Usage Visual Studio Code

Example Usage Visual Studio Code

Example Usage Atom

Example Usage Atom

Command Line Options

Example Usage Command Line

Install

Logit is available as an npm package:

$ npm install logit-js

In order to be able to use the command line it needs to be installed globally:

$ npm install --global logit-js

API

Logit takes a code string as first parameter and an optional options object as a second parameter.

const logit = require('logit-js')

logit("let test = 1;");
// -> {code: "let test = 1;\nconsole.log('2:0', 'test :', test);\n", success: true}

logit("let test = 1;", {verbose: true});
// -> {code: "let test = 5;\nconsole.log('2:0', 'test :', test);\nconsole.log('typeof test :', typeof test);\n"", success: true}

Editor Plugins

Known Issues

  • variables that are assigned return values of update expressions may produce an error and infinite loop

Wishlist

  • informative console logs inside try and catch scopes
  • option to set customized prettier settings instead of provided default

Contributions

Contributions as well as bug reports are very much welcome.