![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
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
.
await
in the REPL without having to wrap your code in async functions$ 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",
]
}
$ npm run repl
This will start a REPL session with lodash
already imported.
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}
]
}
Local modules can be imported, too.
{
"repl": [
{"name": "project", "module": "./"},
{"name": "utils", "module": "./lib/utils"}
]
}
.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
.
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'),
}
}
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,
}
};
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
}
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} $`
}
}
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(', '));
}
}
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: '< -_- > ' });
local-repl
is inspired a number of other great projects:
MIT licensed. See LICENSE for more details.
4.0.0 (2018-05-06)
FAQs
Project-specific REPL configuration
The npm package local-repl receives a total of 1,181 weekly downloads. As such, local-repl popularity was classified as popular.
We found that local-repl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.