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 barlength >= 4 ; else if barlength < 4 ; else ; { return bar + name;}const sayHiWithFancyArrowFunction = { return bar + name;};
Output Logit Default
let bar = 'hello ';console;let foo = 'world';console;let helloWorld = bar + foo;console; const testObject = hello: 'Hi' world: 'Earth' ;console;const hello world = testObject;console;console; if barlength >= 4 ; else if barlength < 4 ; else ; { console; return bar + name;}const sayHiWithFancyArrowFunction = { console; return bar + name;};console;
Output Logit Verbose
let bar = 'hello ';console;console;let foo = 'world';console;console;let helloWorld = bar + foo;console;console; const testObject = hello: 'Hi' world: 'Earth' ;console;console;const hello world = testObject;console;console;console;console; if barlength >= 4 console; ; else if barlength < 4 console; ; else console; ; { console; console; return bar + name;}const sayHiWithFancyArrowFunction = { console; console; return bar + name;};console;console;
Example Usage Emacs
Example Usage Visual Studio Code
Example Usage Atom
Command Line Options
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 = ;// -> {code: "let test = 1;\nconsole.log('2:0', 'test :', test);\n", success: true} ;// -> {code: "let test = 5;\nconsole.log('2:0', 'test :', test);\nconsole.log('typeof test :', typeof test);\n"", success: true}
Editor Plugins
- Emacs
- Visual Studio Code
- Atom Contribution by @thomsound
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.