All Projects → sloria → Local Repl

sloria / Local Repl

Licence: mit
🐚 Project-specific configuration for the Node.js REPL

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Local Repl

Config
A lightweight yet powerful config package for Go projects
Stars: ✭ 126 (-11.89%)
Mutual labels:  configuration
Ngx Config
Configuration utility for Angular
Stars: ✭ 135 (-5.59%)
Mutual labels:  configuration
Surfingkeys Conf
A SurfingKeys configuration which adds 130+ key mappings for 20+ sites & OmniBar search suggestions for 50+ sites
Stars: ✭ 137 (-4.2%)
Mutual labels:  configuration
Docsh
Erlang Docs in the Shell
Stars: ✭ 127 (-11.19%)
Mutual labels:  repl
Replem
🚴 Instantly try npm modules in REPL environment
Stars: ✭ 132 (-7.69%)
Mutual labels:  repl
Gomacro
Interactive Go interpreter and debugger with REPL, Eval, generics and Lisp-like macros
Stars: ✭ 1,784 (+1147.55%)
Mutual labels:  repl
Shadow Cljs
ClojureScript compilation made easy
Stars: ✭ 1,774 (+1140.56%)
Mutual labels:  repl
Autofac.annotation
Autofac extras library for component registration via attributes 用注解来load autofac 摆脱代码或者xml配置和java的spring的注解注入一样的体验
Stars: ✭ 140 (-2.1%)
Mutual labels:  configuration
Ansible Role Dotfiles
Ansible Role - Easy and flexible dotfile installation.
Stars: ✭ 133 (-6.99%)
Mutual labels:  configuration
Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+1197.2%)
Mutual labels:  configuration
Confl
Config parser for go, modeled after Nginx format, Nice lenient syntax with Comments
Stars: ✭ 127 (-11.19%)
Mutual labels:  configuration
Eval In Repl
Consistent ESS-like eval interface for various REPLs
Stars: ✭ 130 (-9.09%)
Mutual labels:  repl
Reconfigure
Config-file-to-Python mapping library (ORM).
Stars: ✭ 136 (-4.9%)
Mutual labels:  configuration
Vim Ipython Cell
Seamlessly run Python code in IPython from Vim
Stars: ✭ 127 (-11.19%)
Mutual labels:  repl
Config
Manage Laravel configuration by persistent storage
Stars: ✭ 139 (-2.8%)
Mutual labels:  configuration
Tmux Config
📗 Example tmux configuration - screen + vim key-bindings, system stat, cpu load bar.
Stars: ✭ 1,633 (+1041.96%)
Mutual labels:  configuration
Configuration
A module to help other modules have settings
Stars: ✭ 135 (-5.59%)
Mutual labels:  configuration
Fig
A minimalist Go configuration library
Stars: ✭ 142 (-0.7%)
Mutual labels:  configuration
Portkey
Live-coding the Cloud
Stars: ✭ 139 (-2.8%)
Mutual labels:  repl
Next Runtime Dotenv
Expose environment variables to the runtime config of Next.js
Stars: ✭ 136 (-4.9%)
Mutual labels:  configuration

🐚 local-repl

Current Version Build Status Dependabot Status

Project-specific REPLs for Node.js. local-repl allows you to automatically import modules and values into your REPL sessions with simple configuration in your project's package.json and/or .replrc.js.

Features!

  • Automatically import modules into your REPL sessions
  • Use await in the REPL without having to wrap your code in async functions
  • Configure the banner and prompt

Add local-repl to your project

$ npm install local-repl --save-dev
# OR
$ yarn add local-repl --dev

Add the following to package.json. Note: lodash is used as an example here; it is not required to use local-repl.

{
  "scripts": {
    "repl": "local-repl"
  },
  "devDependencies": {
    "local-repl": "^3.0.0"
  },
  "dependencies": {
    "lodash": "^4.17.4"
  },
  "repl": [
    "lodash"
  ]
}

Run it

$ npm run repl

This will start a REPL session with lodash already imported.

Specifying aliases

You can pass an array of objects containing the keys "name" (required), "module" (for imports), or "value" (for values).

{
  "repl": [
    {"name": "l", "module": "lodash"},
    {"name": "meaningOfLife", "value": 42}
  ]
}

Importing local modules

Local modules can be imported, too.

{
  "repl": [
    {"name": "project", "module": "./"},
    {"name": "utils", "module": "./lib/utils"}
  ]
}

Using .replrc.js

Instead of defining configuration in "package.json", you may define your configuration in a .replrc.js file. This is useful if you want to dynamically compute modules and values for your REPLs.

// .replrc.js
const User = require('./myapp/models/User');

module.exports = {
  context: [
    'lodash',
    'myapp/utils',
    {name: 'me', value: User.getByEmail('sloria')},
  ]
}

Note: Configuration defined in .replrc.js takes precedence over configuration defined in package.json.

Defining context as an object

Context can be defined as an object rather than an array.

// .replrc.js
const User = require('./myapp/models/User');

module.exports ={
  context: {
    l: require('lodash'),
    utils: require('myapp/utils'),
    me: User.getByEmail('sloria'),
  }
}

Promises as context values

Context values that are promises will be resolved before the REPL starts.

// .replrc.js
const promise = new Promise((resolve) => {
  setTimeout(() => {
    resolve(42);
  }, 500);
});

module.exports = {
  // REPL will have meaningOfLife with value 42 in context
  context: {
    meaningOfLife: promise,
  }
};

await support

You can use await in your REPL sessions without having to create async functions.

Just add the following to your package.json:

{
  "repl": {
    "enableAwait": true
  }
}

Or in .replrc.js

// .replrc.js
module.exports = {
  enableAwait: true
}

More configuration

Configuring the prompt

In package.json:

{
  "repl": {
    "prompt": "myproject $"
  }
}

In .replrc.js:

// .replrc.js
module.exports = {
  prompt: 'myproject $'
}

You can also define prompt as a function in .replrc.js. The function will receive the REPL context and the parsed package.json object.

// .replrc.js
module.exports = {
  prompt: (context, pkg) => {
    return `${pkg.name} ${pkg.version} $`
  }
}

Configuring the banner

In package.json:

{
  "repl": {
    "banner": "Welcome to the myapp REPL. Happy hacking!"
  }
}

You can also define banner as a function in .replrc.js. The function will receive the REPL context and the parsed package.json object.

// .replrc.js
const _ = require('lodash');
const chalk = require('chalk');

module.exports = {
  context: [
    {name: 'l', value: _},
    {name: 'meaningOfLife', value: 42},
  ],
  banner: (context, pkg) => {
    console.log(chalk.bold(`Welcome to the REPL for myapp ${pkg.version}.`));
    console.log(chalk.green('Happy hacking!'));
    console.log(chalk.cyan('Context:'), _.keys(context).sort().join(', '));
  }
}

Programmatic usage

local-repl can be used programatically. The .start(options) function takes the same options as Node's built-in repl.start(options) and returns a Promise that resolves to a REPLServer instance.

const repl = require('local-repl');

repl.start({ prompt: '< -_- > ' });

Inspiration

local-repl is inspired a number of other great projects:

  • konch - REPL configuration for Python
  • n_ - Node.js REPL with lodash

License

MIT licensed. See LICENSE for more details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].