Skip to content

Commit

Permalink
Project update. [p][robotic]
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswrks committed Dec 30, 2024
1 parent 477db09 commit 508e9e1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 51 deletions.
8 changes: 4 additions & 4 deletions .env.vault
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ DOTENV_VAULT_MAIN="7GW98NfL4hM4N6HbfeDXCKreVxKvcVPupFRnZ8XJ+pomaQ=="
DOTENV_VAULT_MAIN_VERSION=1

# dev
DOTENV_VAULT_DEV="US1rop3pYmURKfra3fhcK84nvvaJma36bO16Oqd4sp4uBh8vYVBRaiKEQ/PfBCCqLxdB8SrcbbrsdSdGgUAXCdxsjb6bmAflNTZboXO6gQAcoX/5J4M/ZG2Vrahp5KwJCoZ6QSEkg6KXLua5lztnFVEUKrWTxYSOdXSrrWtJpHbh5GJF7PEL6w/kvkJdN+11X7hv9HVQVqan2bXx6OsY1gfxAgsR2wgzZxQ1j4YkOGmXeNDgCekbK5k79YABHkNnew=="
DOTENV_VAULT_DEV_VERSION=565
DOTENV_VAULT_DEV="NDC8whQmKFvo+s2rUJVxtghapfZS+TWHI7gNWFhyjmn66HO7ehvNQsv3YJRJ6HneP/xV4y2UOlBY18MhZ0aTG9HZabcqik4lfkGdpXPybVQMUYyw36+Md4r6eIRnKhdtNJjlTxcm5KHmgoNZbtlutVuEF/nYtpfvlP3bJVI9pZCFvdabxrnoMw8Ols5voNLnJrFlQ7wgFpbMk1xMtt33+ft8zRUlFY7VEX1p20hY9flPfxYxr8RteYYiRt9P8UVmfA=="
DOTENV_VAULT_DEV_VERSION=567

# ci
DOTENV_VAULT_CI="fHULMI80OozTOkcBlbiTqCzMicEUj7MssEHrf6gyIghhr4YCXGsLEh7uuJqtcSdaB9Q+7rZZxQHmpogWk2l6X10kvRE8XHrrn3HOVGexbm+MbqzZykpD10eldcGU1y1/Jd2UENN1Ngvdym58uTAZU7yPSXiDv9gd3irRkvvANA=="
DOTENV_VAULT_CI_VERSION=565
DOTENV_VAULT_CI="HjUdUsfrlW6Cj+t8aK/jgfu8XURrsXiBQa/ifv8mg7C6Sd4OI8AcwFU3z2CqXHVjVhKfHWXwzpLdtzvTIModME6VaK+/oR2oHmMT9GhiMSE15Vf1qnUl3prsEijrl6kh8hPjGhOu8JYiZtNC9CPtva+HbaxQ04HKhEKcVPZXeg=="
DOTENV_VAULT_CI_VERSION=567

# stage
DOTENV_VAULT_STAGE="aRP8su2YV4jZu3w1HZ/SLaots0IwJDFw75TCpvXEFeNp7tw="
Expand Down
66 changes: 33 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.0.969",
"version": "1.0.970",
"license": "GPL-3.0-or-later",
"name": "@clevercanyon/utilities",
"description": "Utilities for JavaScript apps running in any environment.",
Expand Down
13 changes: 6 additions & 7 deletions src/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { $str } from '#index.ts';
/**
* Defines types.
*/
export type Addr = { name: string; email: string };
export type Addr = { name?: string; email: string };

/**
* Gets email from an addr.
Expand All @@ -35,13 +35,13 @@ export const fromAddr = (str: string): string => {
*
* @returns Addr parts; else undefined.
*
* @note The limit of 70 characters for the name is consistent with Brevo's API for names.
* @note The limit of 70 chars for `name` is consistent with Brevo's API.
*/
export const parseAddr = (str: string): Addr | undefined => {
if (!str) return; // Empty string.

if ($str.isEmail(str) /* Email only. */) {
return { name: '', email: str };
return { email: str };
}
const parts = str.split(/(?<=")\s(?=<)/u);
if (
Expand All @@ -57,9 +57,8 @@ export const parseAddr = (str: string): Addr | undefined => {
'>' === parts[1][parts[1].length - 1] && // Closing bracket.
$str.isEmail(parts[1].slice(1, -1)) // `<email>` validation.
) {
return {
name: parts[0].slice(1, -1),
email: parts[1].slice(1, -1).toLowerCase(),
};
const name = parts[0].slice(1, -1),
email = parts[1].slice(1, -1).toLowerCase();
return { ...(name.length ? { name } : {}), email };
}
};
12 changes: 6 additions & 6 deletions src/tests/email/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ describe('$email', async () => {
expect($email.fromAddr('"X" <@x>')).toBe('');
});
test('.parseAddr()', async () => {
expect($email.parseAddr('x@x')).toStrictEqual({ name: '', email: 'x@x' });
expect($email.parseAddr('x+x@x')).toStrictEqual({ name: '', email: 'x+x@x' });
expect($email.parseAddr('x@x')).toStrictEqual({ email: 'x@x' });
expect($email.parseAddr('x+x@x')).toStrictEqual({ email: 'x+x@x' });

expect($email.parseAddr('x@localhost')).toStrictEqual({ name: '', email: 'x@localhost' });
expect($email.parseAddr('x+x@localhost')).toStrictEqual({ name: '', email: 'x+x@localhost' });
expect($email.parseAddr('x@localhost')).toStrictEqual({ email: 'x@localhost' });
expect($email.parseAddr('x+x@localhost')).toStrictEqual({ email: 'x+x@localhost' });

expect($email.parseAddr('[email protected]')).toStrictEqual({ name: '', email: '[email protected]' });
expect($email.parseAddr('[email protected]')).toStrictEqual({ name: '', email: '[email protected]' });
expect($email.parseAddr('[email protected]')).toStrictEqual({ email: '[email protected]' });
expect($email.parseAddr('[email protected]')).toStrictEqual({ email: '[email protected]' });

expect($email.parseAddr('"X" <x@x>')).toStrictEqual({ name: 'X', email: 'x@x' });
expect($email.parseAddr('"X" <x+x@x>')).toStrictEqual({ name: 'X', email: 'x+x@x' });
Expand Down

0 comments on commit 508e9e1

Please sign in to comment.