Skip to content
 
 

Repository files navigation

n_

Node.js REPL with lodash

Build Status Coverage Status Dependency Status npm version

animated gif showing usage of n_

Why?

Sometimes we use the Node.js REPL interface to experiment with code. Wouldn’t it be great to have that interface with lodash required by default?

Installation

$ npm install -g n_

Usage

$ n_
n_ >

lodash is now attached to the REPL context as _, so just use it:

n_ > _.compact([0, 1, false, 2, '', 3]);
[ 1, 2, 3 ]
n_ >

FP mode

It is possible to use lodash's functional programming variant lodash/fp:

$ n_ --fp
n_ > _.map(function(v) { return v * 2; }, [1, 2, 3]);
[ 2, 4, 6 ]
n_ >

Strict mode

It is possible to enable strict mode in Node.js >= 4.x:

$ n_ --use_strict
n_ >

Or alternatively:

$ NODE_REPL_MODE=strict n_
n_ >

Note:

The _ character is special in the Node REPL (see nodejs.org/api/repl.html). n_ redirects this special variable to $ per default, but you can set your own using the environment variable SPECIAL_VAR like this:

$ SPECIAL_VAR=my_var n_
n_ > 123
123
n_ > my_var
123
n_ >

Also note that using the command .clear you clear the context lodash is bound to.

Enjoy!

About

Node.js REPL with lodash

Resources

Code of conduct

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages