
Product
Rust Support in Socket Is Now Generally Available
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.
Only ask a question one time and store the answer.
Install with npm
$ npm i ask-once --save
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, orWhere 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);
});
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.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-cacheoptions.store {Object}: (optional) Options to be passed to data-storeExample
var ask = new Ask({questions: questions});
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 answer key from the answer store.
Params
key {String}Example
ask.set('a', 'b');
ask.get('a');
//=> 'b'
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});
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.First time the program is run, the user is prompted to answer a question:
Additional runs of the program will skip prompting the user:
Passing the init option will delete all the stored answers and prompt the user to answer the question again:
Additional runs after clearing the stop will return the newly saved answer:
Passing the force option will force the question to be asked:
Additional runs after forcing the question, will return the newly saved answer:
Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Brian Woodward
Copyright © 2015 Brian Woodward Released under the MIT license.
This file was generated by verb-cli on October 24, 2015.
FAQs
Only ask a question one time and store the answer.
The npm package ask-once receives a total of 11 weekly downloads. As such, ask-once popularity was classified as not popular.
We found that ask-once demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.

Research
Five coordinated Chrome extensions enable session hijacking and block security controls across enterprise HR and ERP platforms.