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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ninja_query

v0.3.3

Published

Middlelayer for Inquirer.js to allow prompting even when output is piped

Downloads

44

Readme

NinjaQuery

Middlelayer for Inquirer.js to allow prompting even when output is piped

NPM Version NPM Downloads

NPM

Installing

Via NPM:

npm install ninja_query

Usage

// Node CommonJS
const ninjaQuery = require('ninja_query');
// Or Node ES6
import ninjaQuery from 'ninja_query';

Examples

// Use ninjaQuery just like you use 
ninjaQuery({
  name: "name",
  message: "What is your name?"
}).then(({name}) => console.log(`Hello, ${name}`))

API

ninjaQuery(questions)

Launch the prompt interface (inquiry session)

ninjaQuery.extend(templateID[, question])

Merge the templateID's default Question with the specified question object.

ninjaQuery.password(question[, options])

  • question: <Question> Question block to be used
  • options: <Object> Password options
    • confirm: <string> Whether or not to request a re-enter for confirmation of input. Default: false
    • confirmMessage: <string> Message to print on the re-enter prompt. Default: 'Re enter password ?'
    • unmatchMessage: <string> Message to print when passwords don't match. Default: '[!] Password mismatch'
  • Returns: <Promise>

Construct a password prompt that inherits from DefaultQuestions.password and can request a password re-entry for confirmation.

ninjaQuery.defaults: DefaultQuestions

Question

A question object is a hash containing question related values:

  • type: <string> Type of the prompt.
  • name: <string> The name to use when storing the answer in the answers hash. If the name contains periods, it will define a path in the answers hash.
  • message: <string| (rootObject: object) => string > The question to print. If defined as a function, the first parameter will be the current inquirer session answers. Defaults to the value of name (followed by a colon).
  • default: <string|number|boolean|array|function> Default value(s) to use if nothing is entered, or a function that returns the default value(s). If defined as a function, the first parameter will be the current inquirer session answers.
  • choices: <array| (rootObject: object) => array > Choices array or a function returning a choices array. If defined as a function, the first parameter will be the current inquirer session answers. Array values can be simple numbers, strings, or objects containing a name (to display in list), a value (to save in the answers hash) and a short (to display after selection) properties. The choices array can also contain a Separator.
  • validate: < (input: string, hash: object) => boolean > Receive the user input and answers hash. Should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.
  • filter: < input => string > Receive the user input and return the filtered value to be used inside the program. The value returned will be added to the Answers hash.
  • transformer: < (input: string, hash: object, flags: object) => string > Receive the user input, answers hash and option flags, and return a transformed value to display to the user. The transformation only impacts what is shown while editing. It does not modify the answers hash.
  • when: < hash => boolean > Receive the current user answers hash and should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.
  • pageSize: <number> Change the number of lines that will be rendered when using list, rawList, expand or checkbox.
  • prefix: <string> Change the default prefix message.
  • suffix: <string> Change the default suffix message.

DefaultQuestions

Default templates for Question

- password

name | type | message | validate ---- | ---- | ------- | -------- 'password' | 'password' | 'Please enter a password :' | function

- `validate`: Password must be 4 characters or more
  - **else** `'Password should contain at least 4 characters'`
  • confirm

    name | type | message ---- | ---- | ------- 'confirm' | 'confirm' | 'Are you sure?'

  • name

    name | type | message | filter | transformer | validate ---- | ---- | ------- | ------ | ----------- | -------- 'name' | 'input' | 'Enter full name :' | function | function | function

    • filter: Autocapitalise first character
    • validate: A least one character must be present
    • transform: Autocapitalise first character, colorise when [Enter] is pressed
  • username

    name | type | message | validate ---- | ---- | ------- | -------- 'username' | 'input' | 'Enter user name :' | function

    • validate: A least one character must be present
  • email

    name | type | message | transformer | validate ---- | ---- | ------- | ----------- | -------- 'email' | 'input' | 'Enter your email :' | function | function

    • validate: Email must be valid
      • else 'Email invalid'
    • transform: Colorise email once email is valid
  • dateofbirth

    name | type | message | filter | transformer | validate | suffix ---- | ---- | ------- | ------ | ----------- | -------- | ------ 'dateofbirth' | 'input' | 'Date Of Birth ' | function | function | function | '[ddmmyy]:'

    • filter: Insert separator '/' to date in answers
    • validate: Must be a valid date in the format 'dd/mm/yy'
      • else 'Date of birth should match the format [dd/mm/yy]'
    • transform: Insert separator '/' to date on input

More Examples

Check out some examples in the examples folder

$ node examples/form.js
$ node examples/login.js
$ node examples/password.js

Development

Building

Feel free to clone, use in adherance to the license and perhaps send pull requests

git clone https://github.com/miraclx/ninjaQuery.git
cd ninjaquery
npm install
# hack on code
npm run build

License

Apache 2.0 © Miraculous Owonubi (@miraclx) <omiraculous@gmail.com>