Skip to content

Commit

Permalink
Chore (password): fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
matteosacchetto committed Nov 23, 2023
1 parent 1739492 commit 7c6507b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/password/password.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('password prompt', () => {
const { answer, events, getScreen } = await render(password, {
message: 'Enter your password',
mask: true,
allowShowPassowrd: false,
allowShowPassword: false,
});

expect(getScreen()).toMatchInlineSnapshot('"? Enter your password"');
Expand All @@ -128,7 +128,7 @@ describe('password prompt', () => {
const { answer, events, getScreen } = await render(password, {
message: 'Enter your password',
mask: true,
allowShowPassowrd: true,
allowShowPassword: true,
});

expect(getScreen()).toMatchInlineSnapshot(
Expand Down
14 changes: 7 additions & 7 deletions packages/password/src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Context } from '@inquirer/type';
type PasswordConfig = PromptConfig<{
mask?: boolean | string;
validate?: (value: string) => boolean | string | Promise<string | boolean>;
allowShowPassowrd?: boolean;
allowShowPassword?: boolean;
}>;

const transformer = (
Expand Down Expand Up @@ -41,11 +41,11 @@ export default (config: PasswordConfig, context?: Context | undefined) => {
}

return createPrompt<string, PasswordConfig>((_config, done) => {
const { validate = () => true, allowShowPassowrd } = _config;
const { validate = () => true, allowShowPassword } = _config;
const [status, setStatus] = useState<string>('pending');
const [errorMsg, setError] = useState<string | undefined>(undefined);
const [value, setValue] = useState<string>('');
const [togglePassowrd, setTogglePassword] = useState<boolean>(false);
const [togglePassword, setTogglePassword] = useState<boolean>(false);

const isLoading = status === 'loading';
const prefix = usePrefix(isLoading);
Expand All @@ -71,12 +71,12 @@ export default (config: PasswordConfig, context?: Context | undefined) => {
setError(isValid || 'You must provide a valid value');
setStatus('pending');
}
} else if (allowShowPassowrd && key.ctrl === true && key.name === '`') {
} else if (allowShowPassword && key.ctrl === true && key.name === '`') {
// CTRL + Space
// I only tried on Linux, but the combination on Linux was reported like that
// key.crtl = true
// key.name = '`'
setTogglePassword(!togglePassowrd);
setTogglePassword(!togglePassword);
setValue(rl.line);
setError(undefined);
} else {
Expand All @@ -87,7 +87,7 @@ export default (config: PasswordConfig, context?: Context | undefined) => {

const message = chalk.bold(_config.message);
let formattedValue = transformer(value, _config.mask, { isFinal: status === 'done' });
if (togglePassowrd && status !== 'done') {
if (togglePassword && status !== 'done') {
formattedValue = value;
}

Expand All @@ -102,7 +102,7 @@ export default (config: PasswordConfig, context?: Context | undefined) => {

return [
`${prefix} ${message}${
allowShowPassowrd ? chalk.dim(' (press CTRL+Space to show the password)') : ''
allowShowPassword ? chalk.dim(' (press CTRL+Space to show the password)') : ''
} ${formattedValue}`,
error,
];
Expand Down

0 comments on commit 7c6507b

Please sign in to comment.