npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

carets

v2.5.0

Published

A terminal prompt input library for node with easy multiline input

Downloads

8

Readme

Carets

A terminal prompt input library for node with easy multiline input

Install

npm i carets

Example

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)

Keystroke Commands

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

Other CTRL+ key Combinations

See readline TTY keybindings documentation

API

new Carets(params)

Creates a new instance of Carets

Example

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

Methods

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.

Example

carets.on('line', data => { 
  console.log(data)
  carets.pause()
  
  console.log('Anything')
  
  carets.resume()
  carets.prompt()

})

Events

carets.on('line', data)

Listen for new line input

Example

carets.on('line', data => { 
  console.log(data)
})

carets.on('doc', data)

Listen for new document / multiline object input

Example

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)
  }
})

LICENCE

MIT