diff --git a/components/AliasedEmails.tsx b/components/AliasedEmails.tsx index de5f36e..3d086db 100644 --- a/components/AliasedEmails.tsx +++ b/components/AliasedEmails.tsx @@ -28,6 +28,7 @@ import { useAtom } from "jotai" import { colorSelector } from "@/utils/colorSelector" import { localCopyHistoryAtom } from "./global/CopyHistory" import { AliasType } from "@/components/types" +import aliasedEmail, { aliasedEmailObject } from "aliased-email" type Props = { extension?: boolean } @@ -53,12 +54,10 @@ export default function InputCreator({ extension }: Props) { const updateTimestamp = () => { const updatingTimestamp = new Date(Date.now()) - .toLocaleString("en-US", { - hour12: false, - }) - .replaceAll(/[:\,]/g, "") - .replaceAll(/[\/]/g, "_") - .replace(/\s/g, "-") + .toLocaleString("en-US", { hourCycle: "h24" }) + .replace(/[:\/]+/g, ".") + .replace(/,/g, "-") + .replace(/\s+/g, "") setRealtimeTimestamp(updatingTimestamp) } @@ -68,22 +67,19 @@ export default function InputCreator({ extension }: Props) { return () => clearInterval(interval) }, [timestampEnabled]) - const addAliasToEmail = (email: string, alias: string) => { - if (!email) return "" - return email.split("@").join(alias ? "+" + alias + "@" : "" + "@") - } - useEffect(() => { //every time the selected alias changes, update the aliased email setFinalEmail( timestampEnabled - ? addAliasToEmail( + ? aliasedEmail( email, selectedAlias ? `${selectedAlias}-${realtimeTimestamp}` : realtimeTimestamp ) - : addAliasToEmail(email, selectedAlias) + : selectedAlias + ? aliasedEmailObject(email, selectedAlias).email + : aliasedEmailObject(email).email ) }, [email, selectedAlias, realtimeTimestamp, timestampEnabled]) @@ -95,7 +91,7 @@ export default function InputCreator({ extension }: Props) { const handleChangeEmail = (e: React.ChangeEvent) => { setEmail(e.target.value) setFinalEmail( - addAliasToEmail( + aliasedEmail( e.target.value, selectedAlias || new Date(timestamp).getTime().toString() ) diff --git a/package-lock.json b/package-lock.json index ac7b78e..85bcbd6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "@types/react": "18.0.38", "@types/react-dom": "18.0.11", "@vercel/analytics": "^1.0.1", + "aliased-email": "^1.1.2", "analytics": "github:vercel/analytics", "eslint": "8.39.0", "eslint-config-next": "13.3.1", @@ -1156,6 +1157,11 @@ "url": "https://github.com/sponsors/epoberezkin" } }, + "node_modules/aliased-email": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/aliased-email/-/aliased-email-1.1.2.tgz", + "integrity": "sha512-woaConYe3z3wloV7KZ8LDooWos9U7SI4cH1L89447cgfcx5zfbCLVgKDHzSqrT4gj8H5/aDNv5Nu83JmsUDgRA==" + }, "node_modules/analytics": { "resolved": "git+ssh://git@github.com/vercel/analytics.git#1f35f680a34779214816568fbc665a3f7448640b", "license": "MPL-2.0", diff --git a/package.json b/package.json index 67efc8c..3f492e5 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@types/react": "18.0.38", "@types/react-dom": "18.0.11", "@vercel/analytics": "^1.0.1", + "aliased-email": "^1.1.2", "analytics": "github:vercel/analytics", "eslint": "8.39.0", "eslint-config-next": "13.3.1",