{"name":"@inquirer/core","version":"2.2.0","keywords":["answer","answers","ask","base","cli","command","command-line","confirm","enquirer","generate","generator","hyper","input","inquire","inquirer","interface","iterm","javascript","menu","node","nodejs","prompt","promptly","prompts","question","readline","scaffold","scaffolder","scaffolding","stdin","stdout","terminal","tty","ui","yeoman","yo","zsh"],"author":{"name":"Simon Boudrias","email":"admin@simonboudrias.com"},"license":"MIT","_id":"@inquirer/core@2.2.0","maintainers":[{"name":"sboudrias","email":"admin@simonboudrias.com"},{"name":"danielchatfield","email":"chatfielddaniel@gmail.com"},{"name":"mischah","email":"mail@michael-kuehnel.de"}],"homepage":"https://github.com/SBoudrias/Inquirer.js/blob/master/packages/core/README.md","bugs":{"url":"https://github.com/SBoudrias/Inquirer.js/issues"},"dist":{"shasum":"90ee16b5edfe0c8870275833589138b0c57db592","tarball":"http://registry-npm.ywwl.com/@inquirer/core/download/@inquirer/core-2.2.0.tgz","fileCount":36,"integrity":"sha512-YcSAyRTEJTzitg3yzEGabz0Jwmi8iO9QiLeDVY8LQLzY9AsLouuGRvUZ2Savp1T7AAYCMqDFLQirzB+eSux2Vg==","signatures":[{"sig":"MEUCIQCh0pvP17zVuLHZ2FonK5NYUaesIWyeH1MCeHkQWYLj4AIgSC6+8UCbtGyeFHYguQsL/YAg74SHSTDB+M9OPLaXECs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":57617,"size":13296,"noattachment":false,"key":"/@inquirer/core/-/@inquirer/core-2.2.0.tgz"},"main":"./dist/cjs/index.js","engines":{"node":">=14.18.0"},"exports":{".":{"import":{"types":"./dist/esm/types/index.d.mts","default":"./dist/esm/index.mjs"},"require":{"types":"./dist/cjs/types/index.d.cts","default":"./dist/cjs/index.js"}}},"gitHead":"ba98109480c442d261f243e4117243a9e2f12fd0","scripts":{"tsc":"yarn run clean && yarn run tsc:esm && yarn run tsc:cjs","clean":"rm -rf dist","fix-ext":"node --no-warnings=ExperimentalWarning --loader=ts-node/esm ../../tools/fix-ext.mts","tsc:cjs":"tsc -p ./tsconfig.cjs.json && yarn run fix-ext","tsc:esm":"tsc -p ./tsconfig.json"},"typings":"./dist/cjs/types/index.d.cts","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"repository":{"url":"git+https://github.com/SBoudrias/Inquirer.js.git","type":"git"},"_npmVersion":"lerna/7.0.2/node@v18.16.0+arm64 (darwin)","description":"Core Inquirer prompt API","directories":{},"_nodeVersion":"18.16.0","dependencies":{"chalk":"^4.1.2","figures":"^3.2.0","cli-width":"^4.0.0","run-async":"^3.0.0","wrap-ansi":"^6.0.1","strip-ansi":"^6.0.1","mute-stream":"^1.0.0","ansi-escapes":"^4.3.2","cli-spinners":"^2.8.0","string-width":"^4.2.3","@inquirer/type":"^1.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@inquirer/testing":"^2.0.0"},"_npmOperationalInternal":{"tmp":"tmp/core_2.2.0_1687545803507_0.5197426628129802","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":1687545803689,"_cnpm_publish_time":1687545803689,"dist-tags":{"latest":"12.1.0"}}