{"name":"@inquirer/core","version":"0.0.10-alpha.0","keywords":["cli","prompt","inquirer","command-line"],"author":{"name":"Simon Boudrias"},"license":"MIT","_id":"@inquirer/core@0.0.10-alpha.0","maintainers":[{"name":"danielchatfield","email":"chatfielddaniel@gmail.com"},{"name":"mischah","email":"mail@michael-kuehnel.de"},{"name":"sboudrias","email":"admin@simonboudrias.com"}],"homepage":"https://github.com/SBoudrias/Inquirer.js#readme","bugs":{"url":"https://github.com/SBoudrias/Inquirer.js/issues"},"dist":{"shasum":"b9ddc6503d6904a0622310cbb0cbfe6195f0305b","tarball":"http://registry-npm.ywwl.com/@inquirer/core/download/@inquirer/core-0.0.10-alpha.0.tgz","fileCount":12,"integrity":"sha512-L6Gl4rUhTwcZip0hxHjBV9X+M4wK4KbI+oeTX/PyD6myy8vyVuc0MbLzpjOo3CRbXy0QTVGm5qTAhtbpQWJgKA==","signatures":[{"sig":"MEUCIE6ILgxb3gQMHPipX+xLDQmfb7Xm3og5H0KHb+g1u/ndAiEA16WaTNIgUWVz/a1yYxX6erTu/o0cTf0Qo6n/6zMCmL8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":26742,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe5tRQCRA9TVsSAnZWagAAIMQP/3MFxYw5VAqXMbEPOacA\nzxoHmxf1aTukMfsxAMcqRitldR2cYnTaagA5jIZjzAV+AkCvgaOAzXWls57r\naCr3SyqoJNlusbbPB7gidgCuthUo4ti5Qws2a0ZAUi8kluXNxHJEJLwsIB4e\nSY6WW8lrkJiXSpNPt3qXkq6JrhoOTFJh615/xw5lHpy/Ig12w/3/3ClYGUni\nvTNf8CCwpxyZ3G0FnuZqzO8tjr9x4B3a4JEsDm7VU0Ze5E9wEPmKk3aOWqH9\nRDY3V1ufCbi6p10C2dghflM/0l/9oQpQtb766dENuu7TT7cEU3uM4J8Up0Z9\nNuIo+/T4HFFQL+QX+ZvNjIApefWcciMw+BKSxxnZqe9iA8UFpePwNEga0GMc\nw6VRPC9eSFiJlHdiAq0Jg7eF/ewuyQzFcOTC9E7RwaN0lxbROgmfhCogQnpw\nQzTQC74EvVJJi3pBEUWN7wH/P5GHdTgfDFqPlxLCUx+Kb4G0yEaQr9QtLURr\ncKz8wvbQLOt4JPP+9eqUz1vXjfpGBCGAcTXPoyJ0l5J4RpxtQgKBV6tFFIRm\n+8VWDEmvjJd6g36vIbR9dsQt0rwkS41whHa0/OioY7DcrBC4ZsVxndeJb04g\nBwrLMyvq0FcepP4yZwp0knAoFRSzEwt+W385DnQHmCWI8A6zuCgXov2T9EiP\na67e\r\n=u9tJ\r\n-----END PGP SIGNATURE-----\r\n","size":7522,"noattachment":false,"key":"/@inquirer/core/-/@inquirer/core-0.0.10-alpha.0.tgz"},"main":"index.js","gitHead":"7a699cc7566b4b6bc9a1e8d93490d3f5a01685ef","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"repository":{"url":"git+https://github.com/SBoudrias/Inquirer.js.git","type":"git"},"_npmVersion":"lerna/3.20.2/node@v12.16.1+x64 (darwin)","description":"Core Inquirer prompt API","directories":{},"_nodeVersion":"12.16.1","dependencies":{"chalk":"^3.0.0","lodash":"^4.17.12","cli-width":"^2.2.0","run-async":"^2.3.0","strip-ansi":"^6.0.0","mute-stream":"^0.0.8","ansi-escapes":"^4.2.1","cli-spinners":"^2.2.0","string-width":"^4.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/core_0.0.10-alpha.0_1592185935585_0.3401730709709918","host":"s3://npm-registry-packages"},"readme":"# `@inquirer/core`\n\nThe `@inquirer/core` package is the library enabling the creation of Inquirer prompts.\n\nIt aims to implements a lightweight API similar to React hooks - but without JSX.\n\n# Installation\n\n```sh\nnpm install @inquirer/core\n\nyarn add @inquirer/core\n```\n\n# Usage\n\n```ts\nimport chalk from 'chalk';\nimport {\n  createPrompt,\n  useState,\n  useKeypress,\n  isEnterKey,\n  usePrefix,\n} from '@inquirer/core';\n\nconst confirm = createPrompt<boolean, { message: string; default?: boolean }>(\n  (config, done) => {\n    const [status, setStatus] = useState('pending');\n    const [value, setValue] = useState('');\n    const prefix = usePrefix({});\n\n    useKeypress((key, rl) => {\n      if (isEnterKey(key)) {\n        const answer = value ? /^y(es)?/i.test(value) : config.default !== false;\n        setValue(answer ? 'yes' : 'no');\n        setStatus('done');\n        done(answer);\n      } else {\n        setValue(rl.line);\n      }\n    });\n\n    let formattedValue = value;\n    let defaultValue = '';\n    if (status === 'done') {\n      formattedValue = chalk.cyan(value);\n    } else {\n      defaultValue = chalk.dim(config.default === false ? ' (y/N)' : ' (Y/n)');\n    }\n\n    const message = chalk.bold(config.message);\n    return `${prefix} ${message}${defaultValue} ${formattedValue}`;\n  },\n);\n\n/**\n *  Which then can be used like this:\n */\nconst answer = await confirm({ message: 'Do you want to continue?' });\n```\n\nSee more examples:\n\n- [Confirm Prompt](https://github.com/SBoudrias/Inquirer.js/blob/master/packages/confirm/src/index.mts)\n- [Input Prompt](https://github.com/SBoudrias/Inquirer.js/blob/master/packages/input/src/index.mts)\n- [Password Prompt](https://github.com/SBoudrias/Inquirer.js/blob/master/packages/password/src/index.mts)\n- [Editor Prompt](https://github.com/SBoudrias/Inquirer.js/blob/master/packages/editor/src/index.mts)\n- [Select Prompt](https://github.com/SBoudrias/Inquirer.js/blob/master/packages/select/src/index.mts)\n- [Checkbox Prompt](https://github.com/SBoudrias/Inquirer.js/blob/master/packages/checkbox/src/index.mts)\n- [Rawlist Prompt](https://github.com/SBoudrias/Inquirer.js/blob/master/packages/rawlist/src/index.mts)\n- [Expand Prompt](https://github.com/SBoudrias/Inquirer.js/blob/master/packages/expand/src/index.mts)\n\n## API\n\n### `createPrompt(viewFn)`\n\nThe `createPrompt` function returns an asynchronous function that returns a cancelable promise resolving to the valid answer a user submit. This prompt function takes the prompt configuration as its first argument (this is defined by each prompt), and the context options as a second argument.\n\nThe prompt configuration is unique to each prompt. The context options are:\n\n| Property          | Type                    | Required | Description                                                  |\n| ----------------- | ----------------------- | -------- | ------------------------------------------------------------ |\n| input             | `NodeJS.ReadableStream` | no       | The stdin stream (defaults to `process.stdin`)               |\n| output            | `NodeJS.WritableStream` | no       | The stdout stream (defaults to `process.stdout`)             |\n| clearPromptOnDone | `boolean`               | no       | If true, we'll clear the screen after the prompt is answered |\n\nThe cancelable promise exposes a `cancel` method that'll exit the prompt and reject the promise.\n\n#### Typescript\n\nIf using typescript, `createPrompt` takes 2 generic arguments (ex `createPrompt<string, { message: string }>()`)\n\nThe first one is the type of the resolved value; `function createPrompt<Value>(): Promise<Value> {}`\n\nThe second one is the type of the prompt config; in other words the interface the created prompt will provide to users.\n\n### Hooks\n\nHooks can only be called within the prompt function and are used to handle state and events.\n\nThose hooks are matching the React hooks API:\n\n- `useState`\n- `useRef`\n- `useEffect`\n- `useMemo`\n\nAnd those are custom utilities from Inquirer:\n\n- `useKeypress`\n- `usePagination`\n- `usePrefix`\n\n### Key utilities\n\nListening for keypress events inside an inquirer prompt is a very common pattern. To ease this, we export a few utility functions taking in the keypress event object and return a boolean:\n\n- `isEnterKey()`\n- `isBackspaceKey()`\n- `isSpaceKey()`\n- `isUpKey()` - Note: this utility will handle vim and emacs keybindings (up, `k`, and `ctrl+p`)\n- `isDownKey()` - Note: this utility will handle vim and emacs keybindings (down, `j`, and `ctrl+n`)\n- `isNumberKey()` one of 1, 2, 3, 4, 5, 6, 7, 8, 9, 0\n\n### `usePagination`\n\nWhen looping through a long list of options (like in the `select` prompt), paginating the results appearing on the screen at once can be necessary. The `usePagination` hook is the utility used within the `select` and `checkbox` prompts to cycle through the list of options.\n\nPagination works by taking in the list of options and returning a subset of the rendered items that fit within the page. The hook takes in a few options. It needs a list of options (`items`), and a `pageSize` which is the number of lines to be rendered. The `active` index is the index of the currently selected/selectable item. The `loop` option is a boolean that indicates if the list should loop around when reaching the end: this is the default behavior. The pagination hook renders items only as necessary, so it takes a function that can render an item at an index, including an `active` state, called `renderItem`.\n\n```js\nexport default createPrompt((config, done) => {\n  const [active, setActive] = useState(0);\n\n  const allChoices = config.choices.map((choice) => choice.name);\n\n  const page = usePagination({\n    items: allChoices,\n    active: active,\n    renderItem: ({ item, index, isActive }) => `${isActive ? \">\" : \" \"}${index}. ${item.toString()}`\n    pageSize: config.pageSize,\n    loop: config.loop,\n  });\n\n  return `... ${page}`;\n});\n```\n\n### Theming\n\nTheming utilities will allow you to expose customization of the prompt style. Inquirer also has a few standard theme values shared across all the official prompts.\n\nTo allow standard customization:\n\n```ts\nimport { createPrompt, usePrefix, makeTheme, type Theme } from '@inquirer/core';\nimport type { PartialDeep } from '@inquirer/type';\n\ntype PromptConfig = {\n  theme?: PartialDeep<Theme>;\n};\n\nexport default createPrompt<string, PromptConfig>((config, done) => {\n  const theme = makeTheme(config.theme);\n\n  const prefix = usePrefix({ isLoading, theme });\n\n  return `${prefix} ${theme.style.highlight('hello')}`;\n});\n```\n\nTo setup a custom theme:\n\n```ts\nimport { createPrompt, makeTheme, type Theme } from '@inquirer/core';\nimport type { PartialDeep } from '@inquirer/type';\n\ntype PromptTheme = {};\n\nconst promptTheme: PromptTheme = {\n  icon: '!',\n};\n\ntype PromptConfig = {\n  theme?: PartialDeep<Theme<PromptTheme>>;\n};\n\nexport default createPrompt<string, PromptConfig>((config, done) => {\n  const theme = makeTheme(promptTheme, config.theme);\n\n  const prefix = usePrefix({ isLoading, theme });\n\n  return `${prefix} ${theme.icon}`;\n});\n```\n\nThe [default theme keys cover](https://github.com/SBoudrias/Inquirer.js/blob/theme/packages/core/src/lib/theme.mts):\n\n```ts\ntype DefaultTheme = {\n  prefix: string;\n  spinner: {\n    interval: number;\n    frames: string[];\n  };\n  style: {\n    answer: (text: string) => string;\n    message: (text: string) => string;\n    error: (text: string) => string;\n    defaultAnswer: (text: string) => string;\n    help: (text: string) => string;\n    highlight: (text: string) => string;\n    key: (text: string) => string;\n  };\n};\n```\n\n# License\n\nCopyright (c) 2023 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))<br/>\nLicensed under the MIT license.\n","publish_time":1592185935748,"_cnpm_publish_time":1592185935748,"dist-tags":{"latest":"12.1.0"}}