password
Masked text input for sensitive values.
Preview
Typing
password
◇ Enter your API key│ ••••••••└
After submit
password
◆ Enter your API key│ ••••••••
Usage
import { password, isCancel } from 'termprompt';
const secret = await password({
message: 'Enter your API key',
});
if (isCancel(secret)) process.exit(0);
console.log(secret);
Props
| Prop | Type | Default | Description |
|---|---|---|---|
message | string | required | Question text |
mask | string | "•" | Character shown for each input |
validate | (value: string) => true | string | none | Return true or an error message |
Custom Mask
const pw = await password({
message: 'Password',
mask: '*',
});
Validation
const pw = await password({
message: 'Password',
validate(value) {
if (value.length < 8) return 'Must be at least 8 characters';
return true;
},
});
Keyboard
| Key | Action |
|---|---|
Backspace | Delete character |
Enter | Submit |
Esc | Cancel |