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

ask-once

v0.6.2

Published

Only ask a question one time and store the answer.

Downloads

122

Readme

ask-once NPM version Build Status

Only ask a question one time and store the answer.

Install

Install with npm

$ npm i ask-once --save

Usage

var ask = require('ask-once')();

Ask a question

ask.once('May I have your username?', function (err, answer) {
  console.log(answer);
});

The user's answer is saved, and the question won't be asked again unless:

  • force: true is passed on the options, or
  • the answer is deleted directly

FAQ

Where are the answers stored?

The user's answers are saved on a global config store that is uniquely identified to the application using ask-once.

Can I change where answers are stored?

Yes, you can pass the name of a data-store with the cwd option set to whatever you want it to be. Here's an example:

// pass the name of a data-store, so you can use
// whatever storage location you want
var ask = require('ask-once')({
  store: {
    name: 'foo',
    cwd: 'bar'
  }
});

ask.once('May I have your username?' function (err, answer) {
  console.log(answer);
});

Docs

options

To re-ask questions or reset the stored values:

  • options.force: will re-ask the given question or questions, regardless of whether or not previously stored values exists.
  • options.init: will delete the entire store and start over again.

API

Ask

Returns a question-asking function that only asks a question if the answer is not already stored, or if forced.

Params

  • options {Object}
  • options.questions {Object}: (optional) Options to be passed to question-cache
  • options.store {Object}: (optional) Options to be passed to data-store

Example

var ask = new Ask({questions: questions});

.set

Set answer key with the given value. Answers are cached in memory on the ask.answers.data object, and they are also persisted to disk.

Params

  • key {String}

Example

ask.set('a', 'b');
console.log(ask.answers.data.a)
//=> 'b'

.get

Get answer key from the answer store.

Params

  • key {String}

Example

ask.set('a', 'b');
ask.get('a');
//=> 'b'

.del

Delete an answer from the answer store.

Params

  • key {String|Array|Object}: Pass a string or array of keys, or {force: true} to wipe out the entire store.

Example

ask.del('foo');
ask.del(['foo', 'bar']);
// delete the entire store
ask.del({force: true});

.once

Ask a question only if the answer is not already stored. If the answer is passed on the options the question is bypassed and the answer is be returned.

Params

  • question {String}: Key of the question to ask.
  • options {Object}: Answers or options to force re-asking questions.
  • cb {Function}: Callback function with err and answer.

Examples

First time the program is run, the user is prompted to answer a question:

image

Additional runs of the program will skip prompting the user:

image

Passing the init option will delete all the stored answers and prompt the user to answer the question again:

image

Additional runs after clearing the stop will return the newly saved answer:

image

Passing the force option will force the question to be asked:

image

Additional runs after forcing the question, will return the newly saved answer:

image

Related projects

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Brian Woodward

License

Copyright © 2015 Brian Woodward Released under the MIT license.


This file was generated by verb-cli on October 24, 2015.