diff --git a/packages/core/__tests__/prompts/password.spec.ts b/packages/core/__tests__/prompts/password.spec.ts index b4e514f3..49829e2d 100644 --- a/packages/core/__tests__/prompts/password.spec.ts +++ b/packages/core/__tests__/prompts/password.spec.ts @@ -26,7 +26,7 @@ describe('PasswordPrompt', () => { makeSut(); mock.emit('value', value); - expect(mock.maskedValue).toBe(value.replace(/./g, '•')); + expect(mock.masked).toBe(value.replace(/./g, '•')); }); it('should mask value with custom mask', () => { @@ -37,7 +37,7 @@ describe('PasswordPrompt', () => { }); mock.emit('value', value); - expect(mock.maskedValue).toBe(value.replace(/./g, '*')); + expect(mock.masked).toBe(value.replace(/./g, '*')); }); it('should change cursor position when cursor changes', () => { @@ -48,30 +48,30 @@ describe('PasswordPrompt', () => { initialValue: value, }); - expect(mock.valueWithCursor).toBe(mock.maskedValue + cursor); + expect(mock.valueWithCursor).toBe(mock.masked + cursor); cursorIndex--; mock.setCursor(cursorIndex); mock.emit('value', value); expect(mock.valueWithCursor).toBe( - mock.maskedValue.slice(0, cursorIndex) + - color.inverse(mock.maskedValue[cursorIndex]) + - mock.maskedValue.slice(cursorIndex + 1) + mock.masked.slice(0, cursorIndex) + + color.inverse(mock.masked[cursorIndex]) + + mock.masked.slice(cursorIndex + 1) ); cursorIndex--; mock.setCursor(cursorIndex); mock.emit('value', value); expect(mock.valueWithCursor).toBe( - mock.maskedValue.slice(0, cursorIndex) + - color.inverse(mock.maskedValue[cursorIndex]) + - mock.maskedValue.slice(cursorIndex + 1) + mock.masked.slice(0, cursorIndex) + + color.inverse(mock.masked[cursorIndex]) + + mock.masked.slice(cursorIndex + 1) ); cursorIndex += 2; mock.setCursor(cursorIndex); mock.emit('value', value); - expect(mock.valueWithCursor).toBe(mock.maskedValue + cursor); + expect(mock.valueWithCursor).toBe(mock.masked + cursor); }); it('should submit value', () => { diff --git a/packages/core/src/prompts/password.ts b/packages/core/src/prompts/password.ts index f1ab6a73..293a45f4 100644 --- a/packages/core/src/prompts/password.ts +++ b/packages/core/src/prompts/password.ts @@ -15,7 +15,7 @@ export default class PasswordPrompt extends Prompt { return this._cursor; } - get maskedValue(): string { + get masked(): string { return this.value.replaceAll(/./g, this._mask); } @@ -24,22 +24,22 @@ export default class PasswordPrompt extends Prompt { this.value = ''; this._mask = mask ?? '•'; - this.valueWithCursor = this.maskedValue + color.inverse(color.hidden('_')); + this.valueWithCursor = this.masked + color.inverse(color.hidden('_')); this.exposeTestUtils(); this.on('finalize', () => { - this.valueWithCursor = this.maskedValue; + this.valueWithCursor = this.masked; this.exposeTestUtils(); }); this.on('value', (value) => { this.value = value; if (this.cursor >= this.value.length) { - this.valueWithCursor = `${this.maskedValue}${color.inverse(color.hidden('_'))}`; + this.valueWithCursor = `${this.masked}${color.inverse(color.hidden('_'))}`; } else { - const s1 = this.maskedValue.slice(0, this.cursor); - const s2 = this.maskedValue.slice(this.cursor); + const s1 = this.masked.slice(0, this.cursor); + const s2 = this.masked.slice(this.cursor); this.valueWithCursor = `${s1}${color.inverse(s2[0])}${s2.slice(1)}`; } this.exposeTestUtils(); @@ -49,7 +49,7 @@ export default class PasswordPrompt extends Prompt { private exposeTestUtils() { exposeTestUtils({ cursor: this.cursor, - maskedValue: this.maskedValue, + masked: this.masked, valueWithCursor: this.valueWithCursor, }); } diff --git a/packages/prompts/__tests__/prompts/password.spec.ts b/packages/prompts/__tests__/prompts/password.spec.ts index e10ce94a..7adde8d2 100644 --- a/packages/prompts/__tests__/prompts/password.spec.ts +++ b/packages/prompts/__tests__/prompts/password.spec.ts @@ -52,7 +52,7 @@ describe('password', () => { mock.submit(value); expect(mock.state).toBe('submit'); - expect(mock.frame).toBe(`${title}${color.gray(S_BAR)} ${color.dim(mock.maskedValue)}`); + expect(mock.frame).toBe(`${title}${color.gray(S_BAR)} ${color.dim(mock.masked)}`); }); it('should render cancel', () => { @@ -64,9 +64,9 @@ describe('password', () => { expect(mock.state).toBe('cancel'); expect(mock.frame).toBe( - `${title}${color.gray(S_BAR)} ${color.strikethrough( - color.dim(mock.maskedValue) - )}\n${color.gray(S_BAR)}` + `${title}${color.gray(S_BAR)} ${color.strikethrough(color.dim(mock.masked))}\n${color.gray( + S_BAR + )}` ); }); diff --git a/packages/prompts/src/prompts/password.ts b/packages/prompts/src/prompts/password.ts index ff0bda5f..e1456615 100644 --- a/packages/prompts/src/prompts/password.ts +++ b/packages/prompts/src/prompts/password.ts @@ -14,21 +14,21 @@ const password = (opts: PasswordOptions) => { mask: opts.mask ?? S_PASSWORD_MASK, render() { const title = `${color.gray(S_BAR)}\n${symbol(this.state)} ${opts.message}\n`; - const maskedValue = this.valueWithCursor; + const masked = this.valueWithCursor; switch (this.state) { case 'error': - return `${title.trim()}\n${color.yellow(S_BAR)} ${maskedValue}\n${color.yellow( + return `${title.trim()}\n${color.yellow(S_BAR)} ${masked}\n${color.yellow( S_BAR_END )} ${color.yellow(this.error)}\n`; case 'submit': - return `${title}${color.gray(S_BAR)} ${color.dim(maskedValue)}`; + return `${title}${color.gray(S_BAR)} ${color.dim(masked)}`; case 'cancel': return `${title}${color.gray(S_BAR)} ${ - maskedValue ? color.strikethrough(color.dim(maskedValue)) : '' - }${maskedValue ? '\n' + color.gray(S_BAR) : ''}`; + masked ? color.strikethrough(color.dim(masked)) : '' + }${masked ? '\n' + color.gray(S_BAR) : ''}`; default: - return `${title}${color.cyan(S_BAR)} ${maskedValue}\n${color.cyan(S_BAR_END)}\n`; + return `${title}${color.cyan(S_BAR)} ${masked}\n${color.cyan(S_BAR_END)}\n`; } }, }).prompt() as Promise;