@inquirer/password
Advanced tools
+3
-4
| { | ||
| "name": "@inquirer/password", | ||
| "version": "5.0.8", | ||
| "version": "5.0.9", | ||
| "description": "Inquirer password prompt", | ||
@@ -71,7 +71,6 @@ "keywords": [ | ||
| "@inquirer/ansi": "^2.0.3", | ||
| "@inquirer/core": "^11.1.5", | ||
| "@inquirer/core": "^11.1.6", | ||
| "@inquirer/type": "^4.0.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@inquirer/testing": "^3.3.0", | ||
| "typescript": "^5.9.3" | ||
@@ -92,3 +91,3 @@ }, | ||
| "types": "./dist/index.d.ts", | ||
| "gitHead": "526eca2e64853510821ffd457561840ec0cbfb93" | ||
| "gitHead": "1ce03199b82b4a5fb6f7c97ce374c6da5087444f" | ||
| } |
| import { type Theme } from '@inquirer/core'; | ||
| import type { PartialDeep } from '@inquirer/type'; | ||
| type PasswordTheme = { | ||
| style: { | ||
| maskedText: string; | ||
| }; | ||
| }; | ||
| type PasswordConfig = { | ||
| message: string; | ||
| mask?: boolean | string; | ||
| validate?: (value: string) => boolean | string | Promise<string | boolean>; | ||
| theme?: PartialDeep<Theme<PasswordTheme>>; | ||
| }; | ||
| declare const _default: import("@inquirer/type").Prompt<string, PasswordConfig>; | ||
| export default _default; |
| import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, makeTheme, } from '@inquirer/core'; | ||
| import { cursorHide } from '@inquirer/ansi'; | ||
| const passwordTheme = { | ||
| style: { | ||
| maskedText: '[input is masked]', | ||
| }, | ||
| }; | ||
| export default createPrompt((config, done) => { | ||
| const { validate = () => true } = config; | ||
| const theme = makeTheme(passwordTheme, config.theme); | ||
| const [status, setStatus] = useState('idle'); | ||
| const [errorMsg, setError] = useState(); | ||
| const [value, setValue] = useState(''); | ||
| const prefix = usePrefix({ status, theme }); | ||
| useKeypress(async (key, rl) => { | ||
| // Ignore keypress while our prompt is doing other processing. | ||
| if (status !== 'idle') { | ||
| return; | ||
| } | ||
| if (isEnterKey(key)) { | ||
| const answer = value; | ||
| setStatus('loading'); | ||
| const isValid = await validate(answer); | ||
| if (isValid === true) { | ||
| setValue(answer); | ||
| setStatus('done'); | ||
| done(answer); | ||
| } | ||
| else { | ||
| // Reset the readline line value to the previous value. On line event, the value | ||
| // get cleared, forcing the user to re-enter the value instead of fixing it. | ||
| rl.write(value); | ||
| setError(isValid || 'You must provide a valid value'); | ||
| setStatus('idle'); | ||
| } | ||
| } | ||
| else { | ||
| setValue(rl.line); | ||
| setError(undefined); | ||
| } | ||
| }); | ||
| const message = theme.style.message(config.message, status); | ||
| let formattedValue = ''; | ||
| let helpTip; | ||
| if (config.mask) { | ||
| const maskChar = typeof config.mask === 'string' ? config.mask : '*'; | ||
| formattedValue = maskChar.repeat(value.length); | ||
| } | ||
| else if (status !== 'done') { | ||
| helpTip = `${theme.style.help(theme.style.maskedText)}${cursorHide}`; | ||
| } | ||
| if (status === 'done') { | ||
| formattedValue = theme.style.answer(formattedValue); | ||
| } | ||
| let error = ''; | ||
| if (errorMsg) { | ||
| error = theme.style.error(errorMsg); | ||
| } | ||
| return [[prefix, message, config.mask ? formattedValue : helpTip].join(' '), error]; | ||
| }); |
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
1
-50%6132
-30.61%3
-40%0
-100%1
Infinity%Updated