aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deno/base/config.ts6
-rw-r--r--deno/base/deno.json2
-rw-r--r--deno/base/lib.ts24
-rw-r--r--deno/mail-relay/aws/fetch.ts8
-rw-r--r--deno/mail-relay/mail.ts4
5 files changed, 34 insertions, 10 deletions
diff --git a/deno/base/config.ts b/deno/base/config.ts
index a5f5d86..96cc869 100644
--- a/deno/base/config.ts
+++ b/deno/base/config.ts
@@ -1,4 +1,4 @@
-import { camelCaseToKebabCase } from "./lib.ts";
+import { StringUtils } from "./lib.ts";
export interface ConfigDefinitionItem {
readonly description: string;
@@ -29,7 +29,9 @@ export class ConfigProvider<K extends string> {
for (const [key, def] of Object.entries(definition as ConfigDefinition)) {
map[key] = {
...def,
- env: `${this.#prefix}-${camelCaseToKebabCase(key as string)}`
+ env: `${this.#prefix}-${
+ StringUtils.camelCaseToKebabCase(key as string)
+ }`
.replaceAll("-", "_")
.toUpperCase(),
};
diff --git a/deno/base/deno.json b/deno/base/deno.json
index 52baaa5..582f0f6 100644
--- a/deno/base/deno.json
+++ b/deno/base/deno.json
@@ -4,6 +4,6 @@
"exports": {
".": "./lib.ts",
"./config": "./config.ts",
- "./cron": "./cron.ts",
+ "./cron": "./cron.ts"
}
}
diff --git a/deno/base/lib.ts b/deno/base/lib.ts
index a5e4a6a..3c69e0a 100644
--- a/deno/base/lib.ts
+++ b/deno/base/lib.ts
@@ -1,10 +1,30 @@
-export function camelCaseToKebabCase(str: string): string {
+function camelCaseToKebabCase(str: string): string {
return str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
}
-export function toFileNameString(date: Date, dateOnly?: boolean): string {
+function prependNonEmpty<T>(
+ object: T,
+ prefix: string = " ",
+): string {
+ if (object == null) return "";
+ const string = typeof object === "string" ? object : String(object);
+ return string.length === 0 ? "" : prefix + string;
+}
+
+export const StringUtils = Object.freeze({
+ camelCaseToKebabCase,
+ prependNonEmpty,
+});
+
+function toFileNameString(date: Date, dateOnly?: boolean): string {
const str = date.toISOString();
return dateOnly === true
? str.slice(0, str.indexOf("T"))
: str.replaceAll(/:|\./g, "-");
}
+
+export const DateUtils = Object.freeze(
+ {
+ toFileNameString,
+ } as const,
+);
diff --git a/deno/mail-relay/aws/fetch.ts b/deno/mail-relay/aws/fetch.ts
index da8609f..34948d4 100644
--- a/deno/mail-relay/aws/fetch.ts
+++ b/deno/mail-relay/aws/fetch.ts
@@ -8,7 +8,7 @@ import {
S3ClientConfig,
} from "@aws-sdk/client-s3";
-import { toFileNameString } from "@crupest/base";
+import { DateUtils } from "@crupest/base";
import { Mail } from "../mail.ts";
@@ -98,7 +98,9 @@ export class AwsMailFetcher {
rawMail = await res.Body.transformToString();
} catch (cause) {
if (cause instanceof NoSuchBucket) {
- console.error(`S3 mail key ${s3Key} not found. Perhaps already consumed?`)
+ console.error(
+ `S3 mail key ${s3Key} not found. Perhaps already consumed?`,
+ );
return;
}
throw cause;
@@ -109,7 +111,7 @@ export class AwsMailFetcher {
const { date } = new Mail(rawMail).parsed;
const dateString = date != null
- ? toFileNameString(date, true)
+ ? DateUtils.toFileNameString(date, true)
: "invalid-date";
const newPath = `${this.#archivePrefix}${dateString}/${s3Key}`;
diff --git a/deno/mail-relay/mail.ts b/deno/mail-relay/mail.ts
index 94944b0..9cc591c 100644
--- a/deno/mail-relay/mail.ts
+++ b/deno/mail-relay/mail.ts
@@ -62,8 +62,8 @@ export class MailDeliverResult {
lines.push(`${prefix} smtpMessage: ${this.smtpMessage}`);
}
for (const [name, result] of this.recipients.entries()) {
- const { kind, message, cause } = result;
- lines.push(`${prefix} (${name}): ${kind} ${message} ${cause}`);
+ const { kind, message } = result;
+ lines.push(`${prefix} (${name}): ${kind} ${message}`);
}
return lines.join("\n");
}