{"id":17242743,"url":"https://github.com/imcuttle/inquirer-store","last_synced_at":"2025-03-26T03:24:43.731Z","repository":{"id":33124436,"uuid":"152428378","full_name":"imcuttle/inquirer-store","owner":"imcuttle","description":"Make inquirer's answers persistence even be aborted halfway","archived":false,"fork":false,"pushed_at":"2022-01-07T14:59:43.000Z","size":122,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T07:02:39.741Z","etag":null,"topics":["answers","inquirer","inquirer-store","persistence","store"],"latest_commit_sha":null,"homepage":"","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/imcuttle.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-10-10T13:30:05.000Z","updated_at":"2019-02-15T06:16:11.000Z","dependencies_parsed_at":"2022-08-07T20:00:50.694Z","dependency_job_id":null,"html_url":"https://github.com/imcuttle/inquirer-store","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Finquirer-store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Finquirer-store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Finquirer-store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Finquirer-store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imcuttle","download_url":"https://codeload.github.com/imcuttle/inquirer-store/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245581541,"owners_count":20638996,"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":["answers","inquirer","inquirer-store","persistence","store"],"created_at":"2024-10-15T06:13:57.655Z","updated_at":"2025-03-26T03:24:43.712Z","avatar_url":"https://github.com/imcuttle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# inquirer-store\n\n[![Build status](https://img.shields.io/travis/imcuttle/inquirer-store/master.svg?style=flat-square)](https://travis-ci.org/imcuttle/inquirer-store)\n[![Test coverage](https://img.shields.io/codecov/c/github/imcuttle/inquirer-store.svg?style=flat-square)](https://codecov.io/github/imcuttle/inquirer-store?branch=master)\n[![NPM version](https://img.shields.io/npm/v/inquirer-store.svg?style=flat-square)](https://www.npmjs.com/package/inquirer-store)\n[![NPM Downloads](https://img.shields.io/npm/dm/inquirer-store.svg?style=flat-square\u0026maxAge=43200)](https://www.npmjs.com/package/inquirer-store)\n[![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://prettier.io/)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=flat-square)](https://conventionalcommits.org)\n\nMake inquirer's answers persistence even be aborted halfway\n\n![](./snapshot.svg)\n\n## How it works?\n\n1.  Get default answers by `store`, if `null`, turn to step 3.\n2.  Reset `default` field of each config.\n3.  Detect each answer's acceptance by calling `prompt.ui.process.subscribe`, then calls `store.set / store.write` for saving.\n\n## Installation\n\n```bash\nnpm install inquirer-store\n# or use yarn\nyarn add inquirer-store\n```\n\n## API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n### inquirerStore\n\n[index.js:37-62](https://github.com/imcuttle/inquirer-store/blob/17cd137b085d33554c711a90ddfff29ec7f0f0a4/index.js#L37-L62 'Source code on GitHub')\n\nMake inquirer's answers persistence\n\n#### Parameters\n\n- `prompt` {Function}\n- `config` same as inquirer\n- `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**\n  - `opts.store` {Store} Use which store\n  - `opts.deniesStoreKey` {string}\n    When config contains `deniesStoreKey` and equals `true`, the prompt's value will not be saved. (optional, default `'deniesStore'`)\n  - `opts.mode` {'duplex'|'write'|'read'} \u003cdiv\u003eThe mode about dealing with `store` \u003c/div\u003e\n    - `duplex`: Read and then write with `store`\n    - `write`: Just write data to `store`\n    - `read`: Just read data from `store` (optional, default `'duplex'`)\n\n#### Examples\n\n```javascript\nconst inquirerStore = require('inquirer-store')\nconst FileStore = require('inquirer-store/FileStore')\nconst inquirer = require('inquirer')\n\ninquirerStore(\n  inquirer.prompt,\n  [\n    { type: 'input', message: 'Hi...', name: 'name' },\n    { type: 'input', message: 'Hi...', name: 'deny', deniesStore: true }\n  ],\n  {\n    store: new FileStore({ storePath: '/path/to/where.json' })\n  }\n).then(answers =\u003e {\n  // `answers` would be setting in `default` as default value at next time\n  //  but excluding `answers.deny`\n})\n```\n\n### Store\n\n[Store.js:30-98](https://github.com/imcuttle/inquirer-store/blob/17cd137b085d33554c711a90ddfff29ec7f0f0a4/Store.js#L30-L98 'Source code on GitHub')\n\nBase Class for storing to anywhere, don't use it directly\n\n#### Parameters\n\n- `options` {object}\n\n#### Examples\n\n```javascript\nconst Store = require('inquirer-store/Store')\n// Write customized store class\nclass MyStore extends Store {\n  static defaultOptions = {\n    data: { name: 'imcuttle' }\n  }\n  // Note: It must be a sync operation\n  _read() {\n    const { data } = this.options\n    return data\n  }\n  // Note: It must be a sync operation\n  _write(data) {\n    // Save data for persistence here\n  }\n}\n```\n\n#### options\n\n[Store.js:37-37](https://github.com/imcuttle/inquirer-store/blob/17cd137b085d33554c711a90ddfff29ec7f0f0a4/Store.js#L37-L37 'Source code on GitHub')\n\nextends from `this.constructor.defaultOptions` and `options`\n\nType: [object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)\n\n#### data\n\n[Store.js:43-43](https://github.com/imcuttle/inquirer-store/blob/17cd137b085d33554c711a90ddfff29ec7f0f0a4/Store.js#L43-L43 'Source code on GitHub')\n\nExisting data in actually\n\nType: [object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)\n\n#### get\n\n[Store.js:57-59](https://github.com/imcuttle/inquirer-store/blob/17cd137b085d33554c711a90ddfff29ec7f0f0a4/Store.js#L57-L59 'Source code on GitHub')\n\nGet `this.data[name]`\n\n##### Parameters\n\n- `name` {string}\n\nReturns **any**\n\n#### set\n\n[Store.js:67-69](https://github.com/imcuttle/inquirer-store/blob/17cd137b085d33554c711a90ddfff29ec7f0f0a4/Store.js#L67-L69 'Source code on GitHub')\n\nSet `this.data[name]` to be `value`\n\n##### Parameters\n\n- `name` {string}\n- `value` {any}\n\n#### unset\n\n[Store.js:76-78](https://github.com/imcuttle/inquirer-store/blob/17cd137b085d33554c711a90ddfff29ec7f0f0a4/Store.js#L76-L78 'Source code on GitHub')\n\nDelete `this.data[name]`\n\n##### Parameters\n\n- `name` {string}\n\n#### clear\n\n[Store.js:84-86](https://github.com/imcuttle/inquirer-store/blob/17cd137b085d33554c711a90ddfff29ec7f0f0a4/Store.js#L84-L86 'Source code on GitHub')\n\nClear `this.data`\n\n#### write\n\n[Store.js:95-97](https://github.com/imcuttle/inquirer-store/blob/17cd137b085d33554c711a90ddfff29ec7f0f0a4/Store.js#L95-L97 'Source code on GitHub')\n\nWrite `this.data` for persistence\n\n##### Parameters\n\n- `data` (optional, default `{}`)\n\n### FileStore\n\n[FileStore.js:24-52](https://github.com/imcuttle/inquirer-store/blob/17cd137b085d33554c711a90ddfff29ec7f0f0a4/FileStore.js#L24-L52 'Source code on GitHub')\n\n**Extends Store**\n\nStore's implementation in file system\n\n#### Parameters\n\n- `options` {object}\n  - `options.key` {string|null}\n    When `null`, use store from `storePath` as data, otherwise use `store[key]` as data. (optional, default `null`)\n  - `options.storePath` {string|null] - File path for storing data (optional, default `null`)\n  - `options.parse` {string: string =\u003e object} Parse the text from file `storePath` (optional, default `JSON.parse`)\n  - `options.stringify` {data: object =\u003e string} Stringify data for saving in `storePath` (optional, default `JSON.stringify`)\n  - `options.fs` It's useful for mocking data by overriding `existsSync / readFileSync / writeFileSync` methods (optional, default `require('fs')`)\n\n### fillConfigDefault\n\n[index.js:79-89](https://github.com/imcuttle/inquirer-store/blob/17cd137b085d33554c711a90ddfff29ec7f0f0a4/index.js#L79-L89 'Source code on GitHub')\n\nFill config's `default` field\n\n#### Parameters\n\n- `config` {Array\u003cobject\u003e | object}\n- `store` {Store}\n\n#### Examples\n\n```javascript\nconst { fillConfigDefault } = require('inquirer-store')\n\nfillConfigDefault(\n  [{ type: 'input', name: 'name', default: 'foo' }],\n  new FileStore({ storePath: '/path/to/where.json' })\n)\n// [{ type: 'input', name: 'name', default: 'the value that you has inputted in last time' }]\n```\n\nReturns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\u0026lt;[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)\u003e**\n\n## Contributing\n\n- Fork it!\n- Create your new branch:  \n  `git checkout -b feature-new` or `git checkout -b fix-which-bug`\n- Start your magic work now\n- Make sure npm test passes\n- Commit your changes:  \n  `git commit -am 'feat: some description (close #123)'` or `git commit -am 'fix: some description (fix #123)'`\n- Push to the branch: `git push`\n- Submit a pull request :)\n\n## Authors\n\nThis library is written and maintained by imcuttle, \u003ca href=\"mailto:moyuyc95@gmail.com\"\u003emoyuyc95@gmail.com\u003c/a\u003e.\n\n## License\n\nMIT - [imcuttle](https://github.com/imcuttle) 🐟\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcuttle%2Finquirer-store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimcuttle%2Finquirer-store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcuttle%2Finquirer-store/lists"}