Git Product home page Git Product logo

n_'s Introduction

n_

Node.js REPL with lodash

Coverage Status

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

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

Enable strict mode:

$ n_ --use_strict
n_ >

Repl specificities

Commands

Commands which facilitate changing the lodash flavor can be executed with the .lodash repl command:

  • .lodash fp: switch to lodash/fp
  • .lodash vanilla: switch to vanilla lodash mode
  • .lodash reset: switch to initial lodash mode
  • .lodash swap: switch to the other lodash mode (vanilla/fp)
  • .lodash current: output current lodash flavor in use
  • .lodash version: output lodash version in use

Use .lodash help to view the available repl commands within the repl.

__ as last evaluated expression

The special character _ refers to the lodash instance, and cannot hold the value of the last expression. Use __ to access the last expression instead:

n_ > 10 + 2
12
n_ > 'number ' + __
'number 12'

Configuration options

Aside from --fp and --use_strict/--use-strict, other options are available either as CLI flags or via environment variables (with a trailing _N_).

Available cli options can be viewed with:

n_ --help

Enjoy! 🚀

n_'s People

Contributors

abhisekp avatar adrieankhisbe avatar bnjmnt4n avatar borisdiakur avatar dependabot[bot] avatar jdalton avatar jfmengels avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

n_'s Issues

unable to use _.toInteger() in n_ repl - how can I force lodash major version 4?

Hey @borisdiakur love your library, but I think I'm doing something wrong, I can't get _.toInteger() to work, I get an error - when I install globally I think it's still doing lodash major v 3?

paul42$ npm install -g n_
npm WARN deprecated [email protected]: ⚠️  WARNING ⚠️ tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead: https://npmjs.com/tar
/Users/paul42/.nvm/versions/node/v8.7.0/bin/n_3 -> /Users/paul42/.nvm/versions/node/v8.7.0/lib/node_modules/n_/bin/n_3
/Users/paul42/.nvm/versions/node/v8.7.0/bin/n_ -> /Users/paul42/.nvm/versions/node/v8.7.0/lib/node_modules/n_/bin/n_

> [email protected] postinstall /Users/paul42/.nvm/versions/node/v8.7.0/lib/node_modules/n_
> npm pack lodash@^3 && targz extract lodash-3.*.tgz extraneous/lodash3

lodash-3.10.1.tgz
+ [email protected]
added 26 packages in 3.564s
paul42$ n_4
-bash: n_4: command not found
paul42$ n_3
n_ > _.toInteger('4')
TypeError: _.toInteger is not a function
    at repl:1:3
    at ContextifyScript.Script.runInContext (vm.js:59:29)
    at REPLServer.defaultEval (repl.js:241:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at Array.onLine (repl.js:440:10)
    at REPLServer.<anonymous> (/Users/paul42/.nvm/versions/node/v8.7.0/lib/node_modules/n_/lib/n_.js:75:12)
    at REPLServer.wrapper (/Users/paul42/.nvm/versions/node/v8.7.0/lib/node_modules/n_/extraneous/lodash3/package/index.js:3592:19)
    at emitOne (events.js:115:13)
    at REPLServer.emit (events.js:210:7)
n_ > 

let me know if there is a certain area I can look at to submit a pull request. thanks for the awesome library!

Upgrade to lodash 4.0

With the release of [Lodash 4.0], it will be nice to upgrade n_ to the latest release.

Also it will be nice to tag the n_ repo same as the lodash version.

REPL history.

I was looking at trymodule and noticed it used repl.history
and thought it might be a good thing for n_ too.

I think some shells have a repl history baked in so not too sure if it's needed.

Running on NodeJs v20 locally, interactive session not working

Local NodeJS version is v20.10.0:
$ node -v
v20.10.0

After installing:
npm install -g n_

Running n_ does not work, seems to show an error within the interactive session:
$ n_
n_ > Value of "this" must be of type nullish or must be the global object

The special variable $ no longer works in Node 6

I'm using n_ 1.3.0 and Node 6.0.0.

Instead of being assigned to the most recent output (as it was in Node 5), the variable $ is simply assigned to lodash in Node 6.

n_ > 123
123
n_ > $ // should be 123
{ [Function: lodash]
  templateSettings: 
   { escape: /<%-([\s\S]+?)%>/g,
     evaluate: /<%([\s\S]+?)%>/g,
     interpolate: /<%=([\s\S]+?)%>/g,
     variable: '',
     imports: { _: [Circular] } },
  after: [Function: after],
  ...
}

The issue might be related to this change.

Allow custom lodash version

Would be useful to be able to specify which lodash version n_ relies on, since I'm working on a project that still relies on version 3.10.1.

Not sure if that's possible (npm/npm#5499 may be relevant), but at the very least I'll probably just fork and patch for now 😄

Multi-line commands break lodash binding

I have a weird error: if I run a multi-line command in the REPL (one that causes the ... prefix) and I run that command before I run any command containing _, the binding to lodash gets lost somehow.

You should be able to repeat this behavior by starting n_ and immediately running the two commands found in this example. It should work with any arbitrary multi-line command, as long as that command occurs before any usage of _.

If you run a command containing _ first, there is no problem. Is this expected behavior?
screen shot 2015-02-23 at 12 31 50 pm

npm install does not work

when i am trying to install npm this error is showing up. I tried cleaning cache, deleting node_modules, reinstalling node.js and installing n_ package manually and the problem is still exist.

`npm pack lodash@^3 ; targz extract lodash-3.*.tgz extraneous/lodash3

npm ERR! addLocal Could not install C:\Users\Sinan\Desktop\creosafe\node_modules\n_;

npm ERR! Windows_NT 10.0.15063

npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "pack" "lodash@3" ";" "targz" "extract" "lodash-3.*.tgz" "extraneous/lodash3"

npm ERR! node v6.11.0

npm ERR! npm v3.10.10

npm ERR! path C:\Users\Sinan\Desktop\creosafe\node_modules\n_;

npm ERR! code ENOENT

npm ERR! errno -4058

npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Sinan\Desktop\creosafe\node_modules\n_;'

npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Sinan\Desktop\creosafe\node_modules\n_;'

npm ERR! enoent This is most likely not a problem with npm itself

npm ERR! enoent and is related to npm not being able to find a file.

npm ERR! enoent

npm ERR! Please include the following file with any support request:

npm ERR! C:\Users\Sinan\Desktop\creosafe\node_modules\n_\npm-debug.log

npm ERR! Windows_NT 10.0.15063

npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install"

npm ERR! node v6.11.0

npm ERR! npm v3.10.10

npm ERR! code ELIFECYCLE

npm ERR! [email protected] postinstall: npm pack lodash@^3 ; targz extract lodash-3.*.tgz extraneous/lodash3

npm ERR! Exit status 4294963238

npm ERR!

npm ERR! Failed at the [email protected] postinstall script 'npm pack lodash@^3 ; targz extract lodash-3.*.tgz extraneous/lodash3'.

npm ERR! Make sure you have the latest version of node.js and npm installed.

npm ERR! If you do, this is most likely a problem with the n_ package,

npm ERR! not with npm itself.

npm ERR! Tell the author that this fails on your system:

npm ERR! npm pack lodash@^3 ; targz extract lodash-3.*.tgz extraneous/lodash3

npm ERR! You can get information on how to open an issue for this project with:

npm ERR! npm bugs n_

npm ERR! Or if that isn't available, you can get their info via:

npm ERR! npm owner ls n_

npm ERR! There is likely additional logging output above. ``

Add unit tests.

Unit tests would rock. For a reference grunt-lodash uses nodeunit.

n_ breaks npm ls -g

n_: 1.4.3
npm: 4.0.5
OS: Linux (Arch)

Running:

npm ls -g --depth 0

results in the following error:

npm ERR! extraneous: lodash3 ~/.nvm/versions/node/v7.2.1/lib/node_modules/n_/node_modules/lodash3
npm ERR! error in ~/.nvm/versions/node/v7.2.1/lib/node_modules/n_/node_modules/lodash3: ENOENT: no such file or directory, open '~/.nvm/versions/node/v7.2.1/lib/node_modules/n_/node_modules/lodash3/package.json'

This error doesn't occur with [email protected]. Something to do with this?

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.