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 2d8e52e commit 8007879
Show file tree
Hide file tree
Showing 19 changed files with 146 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .browserslistrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Dec 29, 2024 6:03 AM UTC.
# Last generated Dec 30, 2024 6:09 AM UTC.

[production]
node >= 20.9.0
Expand Down
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Dec 29, 2024 6:03 AM UTC.
# Last generated Dec 30, 2024 6:09 AM UTC.

# Locals

Expand Down
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="TwxDnS+ApGYMAvvlyy1XL2ZHSF81VkHMf8Yj6YCMH4B3Qpg7jEOPFdVZt/I//Z4cRvmDYrr3+CZp15fx39KmzieZ/hgnf52hL3moq56IMuJQXlRej/pZFo4eV18akkxpltdVVa6qNb/qN8n5uH3dGrEwHZq8CC+zDDc4aMAEqrnqjRKOM04Y4NOCpuE5I+mqpkz+PuhmmknxgIU70eTa29La9LvaRPMTuAW6QXG5lH8izAGHHI0yylR3TtBzcZGz6A=="
DOTENV_VAULT_DEV_VERSION=561
DOTENV_VAULT_DEV="pi+QD4XHVkzTNq/0Fo7sBxeSYxxapR8x2EPN4+RTqu47dEAmcW38KN/YoR9CeBWbqKzhsnyWMBU960reqQzNJEcLPlpQ/U9YvBlMrDjFarx22qI95mt2UVZUuxAp1Yr6k+AYqQf+ikEt+DfsRrxC79v/AKVKEUk1yoHAs3eDqCU7emqwCsS802Mp4gKQ5r9kTxJZQauIT+mw6YT4e7YQbj2rXMwP9uGVTNohBPpm59I279lP9PlCmRvK1PbYyyyyMQ=="
DOTENV_VAULT_DEV_VERSION=563

# ci
DOTENV_VAULT_CI="m73XqNmab2TEtFaq24HgWnbf01VOBtGEgpQLY8GQLzvjhDU+6UctelFDZ2OncOj33NKYJkgtVBx3frHi37rDiTjnmwDu/FD12PFxaRxG+AcJriAXDCHtlYJ5eTUtMgP8EdmRDe1NaTDYQiycRIaSMlGry7bJB5ZQyuVHvkTC7g=="
DOTENV_VAULT_CI_VERSION=561
DOTENV_VAULT_CI="bcZ5LMMuEyegFe6gOzBH8ygDoe/CcPzzd8QIApLkeYBKjU/a0t5DxXgstL0Ym3C/LEybJ7zU7Id1qLNkHuMadgQPVTCrqk/jsnoQIn6e7SUuOGCgTc+zsX9GVygGRTruux/rrlK2D5JAMLbskKs89wBppP/7kUU4ATWjxuek2A=="
DOTENV_VAULT_CI_VERSION=563

# stage
DOTENV_VAULT_STAGE="aRP8su2YV4jZu3w1HZ/SLaots0IwJDFw75TCpvXEFeNp7tw="
Expand Down
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Dec 29, 2024 6:03 AM UTC.
# Last generated Dec 30, 2024 6:09 AM UTC.

# Default

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Dec 29, 2024 6:03 AM UTC.
# Last generated Dec 30, 2024 6:09 AM UTC.

# Locals

Expand Down
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Generated data.
# <generated:start>

# Last generated Dec 29, 2024 6:03 AM UTC.
# Last generated Dec 30, 2024 6:09 AM UTC.

# Locals

Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Dec 29, 2024 6:03 AM UTC.
# Last generated Dec 30, 2024 6:09 AM UTC.

# Packages

Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @note This entire file will be updated automatically.
* @note Instead of editing here, please review `./settings.mjs`.
*
* Last generated using `./settings.mjs` Dec 29, 2024 6:03 AM UTC.
* Last generated using `./settings.mjs` Dec 30, 2024 6:09 AM UTC.
*/
{
"editor.formatOnType": false,
Expand Down
2 changes: 1 addition & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Dec 29, 2024 6:03 AM UTC.
# Last generated Dec 30, 2024 6:09 AM UTC.

# Locals

Expand Down
2 changes: 1 addition & 1 deletion dev/.files/vite/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export default async ({ mode, command, isSsrBuild: isSSRBuild }) => {
optimizeDeps: {
force: true, // Don’t use cache for optimized deps; recreate.
esbuildOptions: {
external: ['cloudflare:sockets'],
external: ['cloudflare:email', 'cloudflare:sockets'],
plugins: [await viteMDXESBuildConfig({ projDir })],
},
// Preact is required by prefresh plugin; {@see https://o5p.me/WmuefH}.
Expand Down
2 changes: 1 addition & 1 deletion dev/.files/vite/includes/rollup/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export default async ({ projDir, srcDir, distDir, a16sDir, appType, appEntries,
}, // {@see https://o5p.me/7YF2NU}.
},
external: [
/^(?:node:|cloudflare:).*$/iu,
...(['lib'].includes(appType) ? [/^(?![./~#]|file:|data:|virtual:).*$/iu] : []),
...peerDepKeys.map((pkgName) => new RegExp('^' + $str.escRegExp(pkgName) + '(?:$|[/?])', 'u')),
/^(?:cloudflare:).*$/iu,
],
output: {
interop: 'auto', // Matches TypeScript configuration.
Expand Down
2 changes: 1 addition & 1 deletion dev/.files/wrangler/settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default async () => {
defaultAccountId: brandAccountId,
defaultLogpush: brandSupportsLogpush,

compatibilityDate: '2024-03-02',
compatibilityDate: '2024-09-23',
compatibilityFlags: [],

defaultLocalIP: '0.0.0.0',
Expand Down
65 changes: 50 additions & 15 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.967",
"version": "1.0.968",
"license": "GPL-3.0-or-later",
"name": "@clevercanyon/utilities",
"description": "Utilities for JavaScript apps running in any environment.",
Expand Down
33 changes: 28 additions & 5 deletions src/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import '#@initialize.ts';

import { $str } from '#index.ts';

/**
* Defines types.
*/
export type Addr = { name: string; email: string };

/**
* Gets email from an addr.
*
Expand All @@ -14,12 +19,28 @@ import { $str } from '#index.ts';
*
* @param str String to consider.
*
* @returns Email from an addr; else empty string.
* @returns Email address; else empty string.
*/
export const fromAddr = (str: string): string => {
if (!str) return '';
if ($str.isEmail(str)) return str;
return parseAddr(str)?.email || '';
};

/**
* Parses an addr.
*
* - `username@hostname`.
* - `"Name" <username@hostname>`.
*
* @param str String to consider.
*
* @returns Addr parts; else undefined.
*/
export const parseAddr = (str: string): Addr | undefined => {
if (!str) return; // Empty string.

if ($str.isEmail(str) /* Email only. */) {
return { name: '', email: str };
}
const parts = str.split(/(?<=")\s(?=<)/u);
if (
2 === parts.length &&
Expand All @@ -34,7 +55,9 @@ export const fromAddr = (str: string): string => {
'>' === parts[1][parts[1].length - 1] && // Closing bracket.
$str.isEmail(parts[1].slice(1, -1)) // `<email>` validation.
) {
return parts[1].slice(1, -1).toLowerCase();
return {
name: parts[0].slice(1, -1),
email: parts[1].slice(1, -1).toLowerCase(),
};
}
return ''; // Not an addr.
};
30 changes: 15 additions & 15 deletions src/str.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,20 @@ export const escFTSQuery = (str: string, options?: EscFTSQueryOptions): string =
* Email utilities.
*/

/**
* Tests if a string is an addr.
*
* - `username@hostname`.
* - `"Name" <username@hostname>`.
*
* @param str String to consider.
*
* @returns True if string is an addr.
*/
export const isAddr = (str: string): boolean => {
return $email.parseAddr(str) ? true : false;
};

/**
* Tests if a string is an email address.
*
Expand All @@ -983,25 +997,11 @@ export const isEmail = (str: string): boolean => {
parts[1].length > 255 || // Hostname.
parts[1].split('.').some((part) => part.length > 63)
)
return false; // Not an email.
return false; // Not an email address.

return emailRegExp.test(str);
};

/**
* Tests if a string is an addr.
*
* - `username@hostname`.
* - `"Name" <username@hostname>`.
*
* @param str String to consider.
*
* @returns True if string is an addr.
*/
export const isAddr = (str: string): boolean => {
return $email.fromAddr(str) ? true : false;
};

/* ---
* IP utilities.
*/
Expand Down
Loading

0 comments on commit 8007879

Please sign in to comment.