Strip leading @ from password reset input

This commit is contained in:
Alex Gleason
2022-09-16 10:42:05 -05:00
parent 3509fd1c6e
commit c19fe9f167
4 changed files with 26 additions and 13 deletions

View File

@@ -0,0 +1,7 @@
import { normalizeUsername } from '../input';
test('normalizeUsername', () => {
expect(normalizeUsername('@alex')).toBe('alex');
expect(normalizeUsername('alex@alexgleason.me')).toBe('alex@alexgleason.me');
expect(normalizeUsername('@alex@gleasonator.com')).toBe('alex@gleasonator.com');
});

View File

@@ -0,0 +1,13 @@
/** Trim the username and strip the leading @. */
const normalizeUsername = (username: string): string => {
const trimmed = username.trim();
if (trimmed[0] === '@') {
return trimmed.slice(1);
} else {
return trimmed;
}
};
export {
normalizeUsername,
};