{"id":15683593,"url":"https://github.com/doowb/ask-once","last_synced_at":"2025-05-07T13:46:22.820Z","repository":{"id":36080716,"uuid":"40380895","full_name":"doowb/ask-once","owner":"doowb","description":"Only ask a question one time and store the answer.","archived":false,"fork":false,"pushed_at":"2015-10-24T05:17:15.000Z","size":276,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T08:42:36.866Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/doowb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-07T21:04:26.000Z","updated_at":"2021-04-12T22:05:28.000Z","dependencies_parsed_at":"2022-09-14T09:01:05.848Z","dependency_job_id":null,"html_url":"https://github.com/doowb/ask-once","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fask-once","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fask-once/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fask-once/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fask-once/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doowb","download_url":"https://codeload.github.com/doowb/ask-once/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251837015,"owners_count":21651754,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T17:07:31.124Z","updated_at":"2025-05-07T13:46:22.803Z","avatar_url":"https://github.com/doowb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ask-once [![NPM version](https://badge.fury.io/js/ask-once.svg)](http://badge.fury.io/js/ask-once)  [![Build Status](https://travis-ci.org/doowb/ask-once.svg)](https://travis-ci.org/doowb/ask-once)\n\n\u003e Only ask a question one time and store the answer.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/)\n\n```sh\n$ npm i ask-once --save\n```\n\n## Usage\n\n```js\nvar ask = require('ask-once')();\n```\n\n**Ask a question**\n\n```js\nask.once('May I have your username?', function (err, answer) {\n  console.log(answer);\n});\n```\n\nThe user's answer is saved, and the question won't be asked again unless:\n\n* `force: true` is passed on the options, or\n* the answer is deleted directly\n\n## FAQ\n\n**Where are the answers stored?**\n\nThe user's answers are saved on a global config store that is uniquely identified to the application using `ask-once`.\n\n**Can I change where answers are stored?**\n\nYes, you can pass the name of a [data-store](https://github.com/jonschlinkert/data-store) with the `cwd` option set to whatever you want it to be. Here's an example:\n\n```js\n// pass the name of a data-store, so you can use\n// whatever storage location you want\nvar ask = require('ask-once')({\n  store: {\n    name: 'foo',\n    cwd: 'bar'\n  }\n});\n\nask.once('May I have your username?' function (err, answer) {\n  console.log(answer);\n});\n```\n\n## Docs\n\n### options\n\n\u003e To re-ask questions or reset the stored values:\n\n* `options.force`: will re-ask the given question or questions, regardless of whether or not previously stored values exists.\n* `options.init`: will **delete the entire store** and start over again.\n\n### API\n\n### [Ask](index.js#L27)\n\nReturns a question-asking function that only asks a question if the answer is not already stored, or if forced.\n\n**Params**\n\n* `options` **{Object}**\n* `options.questions` **{Object}**: (optional) Options to be passed to [question-cache](https://github.com/jonschlinkert/question-cache)\n* `options.store` **{Object}**: (optional) Options to be passed to [data-store](https://github.com/jonschlinkert/data-store)\n\n**Example**\n\n```js\nvar ask = new Ask({questions: questions});\n```\n\n### [.set](index.js#L64)\n\nSet answer `key` with the given `value`. Answers are cached in memory on the `ask.answers.data` object, and they are also persisted to disk.\n\n**Params**\n\n* `key` **{String}**\n\n**Example**\n\n```js\nask.set('a', 'b');\nconsole.log(ask.answers.data.a)\n//=\u003e 'b'\n```\n\n### [.get](index.js#L81)\n\nGet answer `key` from the answer store.\n\n**Params**\n\n* `key` **{String}**\n\n**Example**\n\n```js\nask.set('a', 'b');\nask.get('a');\n//=\u003e 'b'\n```\n\n### [.del](index.js#L98)\n\nDelete an answer from the answer store.\n\n**Params**\n\n* `key` **{String|Array|Object}**: Pass a string or array of keys, or `{force: true}` to wipe out the entire store.\n\n**Example**\n\n```js\nask.del('foo');\nask.del(['foo', 'bar']);\n// delete the entire store\nask.del({force: true});\n```\n\n### [.once](index.js#L114)\n\nAsk a question only if the answer is not already stored. If\nthe answer is passed on the options the question is bypassed\nand the answer is be returned.\n\n**Params**\n\n* `question` **{String}**: Key of the question to ask.\n* `options` **{Object}**: Answers or options to force re-asking questions.\n* `cb` **{Function}**: Callback function with `err` and `answer`.\n\n## Examples\n\nFirst time the program is run, the user is prompted to answer a question:\n\n[![image](https://cloud.githubusercontent.com/assets/995160/9158076/78bf87e6-3ede-11e5-8bbc-dac8a55353c2.png)](https://www.npmjs.com/)\n\nAdditional runs of the program will skip prompting the user:\n\n[![image](https://cloud.githubusercontent.com/assets/995160/9158091/ec592b58-3ede-11e5-8f18-4fc4b1327d2b.png)](https://github.com/jonschlinkert/data-store)\n\nPassing the `init` option will delete all the stored answers and prompt the user to answer the question again:\n\n[![image](https://cloud.githubusercontent.com/assets/995160/9158111/22e24ff6-3edf-11e5-95c9-bc2314367557.png)](index.js#L27)\n\nAdditional runs after clearing the stop will return the newly saved answer:\n\n[![image](https://cloud.githubusercontent.com/assets/995160/9158120/43c16d60-3edf-11e5-8d85-a98b029fd743.png)](https://github.com/jonschlinkert/question-cache)\n\nPassing the `force` option will force the question to be asked:\n\n[![image](https://cloud.githubusercontent.com/assets/995160/9158137/740bef0e-3edf-11e5-898d-d9ce72f28ad2.png)](https://github.com/jonschlinkert/data-store)\n\nAdditional runs after forcing the question, will return the newly saved answer:\n\n[![image](https://cloud.githubusercontent.com/assets/995160/9158144/8fd63550-3edf-11e5-8daa-b19fa251bc66.png)](index.js#L64)\n\n## Related projects\n\n* [data-store](https://www.npmjs.com/package/data-store): Easily get, set and persist config data. | [homepage](https://github.com/jonschlinkert/data-store)\n* [inquirer](https://www.npmjs.com/package/inquirer): A collection of common interactive command line user interfaces. | [homepage](https://github.com/sboudrias/Inquirer.js#readme)\n* [question-cache](https://www.npmjs.com/package/question-cache): A wrapper around inquirer that makes it easy to create and selectively reuse questions. | [homepage](https://github.com/jonschlinkert/question-cache)\n* [question-helper](https://www.npmjs.com/package/question-helper): Template helper that asks a question in the command line and resolves the template with… [more](https://www.npmjs.com/package/question-helper) | [homepage](https://github.com/doowb/question-helper)\n\n## Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm i -d \u0026\u0026 npm test\n```\n\n## Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/doowb/ask-once/issues/new).\n\n## Author\n\n**Brian Woodward**\n\n+ [github/doowb](https://github.com/doowb)\n+ [twitter/doowb](http://twitter.com/doowb)\n\n## License\n\nCopyright © 2015 Brian Woodward\nReleased under the MIT license.\n\n***\n\n_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 24, 2015._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fask-once","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoowb%2Fask-once","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fask-once/lists"}