Once installed, call it typing
jrn in your terminal, like this:
or specify a glob pointing to some
jsrownum is too long, you can also type
jrn; we wired up that as an alternative.
It updates each
console.log in your
// something on row 1
// something on row 2
console.log('000 var = ' + var); // row 3
console.log('003 var = ' + var);
Because it's on row 3. If you're not using
console.log, and are using for example
log(), put that under "-t" flag:
jrn -t "log"
or if specifying paths,
jrn "folder/*.js" -t "log"
First, it depends, did you specify a path or not.
- If you did, for example,
jsrownum "folder/*.js"it will process that file (or expand glob into a list of files).
- If you didn't, just typed
jsrownum, it will use the current folder where it was called from and look for files in this order:
Once it picks the file, it will look for
console.log statements, and replace the first chunk of an uninterrupted sequence of numbers with a number of a row it sits.
For exampe, on row number 55 there's a
console.log("045 var = " + var).
It will replace
The default padding is three characters, but you can override it, see the optional flags table below.
console.logs help to troubleshoot the code. These days Rollup builds are standard — having a source in ES Modules (and pointing unit tests to it) and using that source to build three types of applications: 1. ESM (same as source); 2. UMD (minified, for browsers and unpkg.com); 3. Common JS — transpiled to ES5, suitable for older platforms.
Now, you can use Rollup to remove comments and
console.logs automatically when producing production builds. During development builds, you can use CLI flags to skip
console.log removal. This way, you get all the goodness of
console.logs in the terminal, and there's no risk that they will spill into production.
Once installed globally, type in your terminal:
jsrownum OR type
If you won't pass any glob file/folder pattern or patterns, for example, just type
jrn, it will look for the following files in this priority order:
If you will pass some globs, for example:
jsrownum --pad="4" "dist/**/*.js test/ index.js"
jrn "test1.js test2.js" -p 2
...it will expand the globs and catch all
.js files in the folders you specified and process them.
Optionally, you can pass the options, which match the API:
|CLI flag||For example,||What it does|
||Lets you set the row number padding. For example,
||Lets you change from "console.log" to any function's name, for example update "001" in
Command line applications have few rules. First, if you want to pass multiple values to a certain flag, put
--***** for each value:
jrn -f "log" -f "yo"
jrn -f "log" "yo"
If you want to put double quotes, escape it like using left slash:
jrn -f "zzz\"yyy"
We set up an alias for
jsrownum, to piggyback on some common command we run often. For example,
git add . - this way all row numbers are processed automatically without any hassle.
See it in the monorepo , on GitHub.
To report bugs or request features or assistance, raise an issue on GitHub .
Any code contributions welcome! All Pull Requests will be dealt promptly.
Copyright © 2010–2021 Roy Revelt and other contributors
console.logs in JS code