![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
npm i carets
import Carets from 'carets'
let params = {
caret: 'carets > ',
docCaret: '$ '
}
// Creates a new Carets instance with the params
let carets = new Carets(params)
carets.prompt(params.caret)
carets.on('line', data => {
// Commands example
let cmd = data.split(' ')
if(cmd[0] === '`'){
cmd.shift()
cmd = cmd.join(' ')
carets.prompt(cmd ? cmd : '')
}
else if(cmd[0] === '~'){
console.log(carets.history)
carets.prompt(params.caret)
} else {
console.log(data)
}
})
let docname
carets.on('doc', data => {
let doc = {}
let keys = Object.keys(data)
let docname = data[Math.min(...keys)]
delete data[docname]
console.log('Name:', docname)
delete data[keys[0]]
if(keys.length > 0){
doc = data
console.log(docname, doc)
}
})
carets.on('docmode', bool => {
if(bool) {
// do something when in docmode
setTimeout(()=>{
carets.prompt('')
})
}
else {
// do something when docmode exits
carets.prompt(params.caret)
}
})
setTimeout(()=>{
// Change the prompt at a later time
carets.prompt('Howdy doody > ')
// get a history of prompts
let history = carets.history
console.log()
console.log(history)
// Change the prompt to something in history
carets.prompt(Object.keys(history)[0])
}, 10000)
CTRL+W
or OPT+BACKSPACE
Toggle between document / multiline object creation mode or line mode
When in document / multiline mode, lines are inserted into an object with UNIX time as their keys. This may be used to sort the document when it is returned.
Exit this mode, save and emit the document / multiline object (if it has data) with CTRL+W
or OPT+BACKSPACE
.
CTRL-V
Paste data from the clipboard into the document
Note:
COMMAND-V
does not work to paste from the clipboard. This is a limitation of the OS terminal.
CTRL+C
Exit the application
CTRL+
key CombinationsSee readline TTY keybindings documentation
new Carets(params)
Creates a new instance of Carets
let params = {
caret: 'carets > ',
docCaret: '$ '
}
let carets = new Carets(params)
Document mode treats the first line entered as the document name. Each subsequent line is the document body. You may paste multiline data from the clipboard with CTRL-V
.
params
params.caret
The string you would like to use as your caret
params.docCaret
The string you would like to use as your caret in document / multiline mode
carets.prompt()
Display a prompt
carets.pause()
Pause the prompt and terminal input processing
carets.resume()
Resume the prompt and terminal input processing. This enables the prompt to repeat after processing new input.
carets.on('line', data => {
console.log(data)
carets.pause()
console.log('Anything')
carets.resume()
carets.prompt()
})
carets.on('line', data)
Listen for new line input
carets.on('line', data => {
console.log(data)
})
carets.on('doc', data)
Listen for new document / multiline object input
let doc = {}
let docName = ''
carets.on('doc', data => {
if(data && typeof data === 'string') docName = data
else if(Object.keys(data).length > 0){
doc = data
console.log('Name:', docName, '\r\n', doc)
}
})
MIT
FAQs
A terminal prompt input library for node with easy multiline input
The npm package carets receives a total of 2 weekly downloads. As such, carets popularity was classified as not popular.
We found that carets 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.