Package Exports
- repl-story
- repl-story/src/repl-story.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (repl-story) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
repl-story
Load history into node repl
Basic Usage
const replHistory = require('repl-story');
const replServer = replHistory('~/.my.wonderful.cli');
// play around in repl
// you can consult history using command .historyApi
replHistory supports differents signatures:
replHistory(repl|replServer, filename); // original signature similar to repl.history
replHistory(filename, [repl|replServer]);
replHistory(options);
replHistory(filename, options);
// -> REPLServerHere are the different possible params:
filenameorhistoryFile: the path toward the history file.filenameis mandatory. However you can skip it and provide it via theoptionsargument as thefilenameproperty (you can also use the aliashistoryFile).replServerorrepl: either thereplmodule, or aReplServer. [default therequire('repl')builtin library]an
optionsobject, this give you better control overreplandrepl-storyconfiguration. This is a plain old js object that support the following propertiesfilenameorhistoryFile: if not provided as leading argument, you can embed the file configuration into the option object.replServerorrepl: either thereplmodule, or aReplServer. [default therequire('repl')builtin library]createornoCreate: whether history file should be created if missing [default:create=true]recordornoRecord: whether new history should be recorded [default:record=true]ignore: an array of values that should not be recorded into history- any other options supported by
repl.start()if you did not provided aReplServerinstance, such as:prompt: optional prompt to use [default'> ']input: Readable stream to read from [default'process.stdin]output: Readable stream to write to [defaultprocess.stdout]- any other option
repl.start()supports likeeval,writer,completer,useColors;terminalreplMode
replHistory() return the REPLServer instance you provided, or otherwise the one it started.
Note: replHistory instrument the repl server so that when it closes the history file is closed properly.
If you want for this to be complete, you can listen the end-of-story event on the replServer itself.
'Complex' Example
Here is an example to illustrate how to configure repl-story:
const repl = require('repl');
const replHistory = require('repl-story');
const replServer = replHistory({
repl,
filename: '~/.my.cli',
record: false, // load history but do no record it. (equivalent to 'noRecord: true')
noCreate: true, // disable creation if missing. (equivalent to 'create: false')
prompt: ':> ' // options are forwarded to repl.start() if no provided replServer
});Acknowledgment
This started as the adaptation of repl.history to current node Apis.
And why story? repl-history was already taken 😉