@dintero/email-chk
v1.1.0
Published
Check if an email address contains a typo and suggest the correct one.
Downloads
579
Readme
email-chk
Check if an email address contains a typo and suggest the correct one.
Usage
Conventional Typescript:
import { EmailChk } from '@dintero/email-chk';
const emailChk = EmailChk({
domains: ['gmail.com', 'hotmail.com', 'yahoo.com'],
levensteinThreshold: 3,
});
const email = "[email protected]";
const result = emailChk(email); // [email protected]
React:
...
import { EmailChk } from '@dintero/email-chk';
const App = () => {
const [email, setEmail] = useState('');
const [suggestion, setSuggestion] = useState('');
const emailChk = EmailChk({
domains: ['gmail.com', 'hotmail.com', 'yahoo.com'],
levensteinThreshold: 3,
});
const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
const { value } = e.target;
setEmail(value);
setSuggestion(emailChk(value)); // [email protected]
}, [email]);
return (
<div>
<input type="text" value={email} onChange={handleChange} />
{suggestion && <p>Did you mean {suggestion}?</p>}
</div>
);
};