diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-06-21 23:00:56 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-06-21 23:00:56 +0800 |
commit | d0ccb5d6183cf4b7188258cdb605c727b499d284 (patch) | |
tree | 2039a8c88fced4a0ed3188b9c01c29c22d050627 /deno/base | |
parent | 89c414326a195d71d1f993af661f94798101e065 (diff) | |
download | crupest-d0ccb5d6183cf4b7188258cdb605c727b499d284.tar.gz crupest-d0ccb5d6183cf4b7188258cdb605c727b499d284.tar.bz2 crupest-d0ccb5d6183cf4b7188258cdb605c727b499d284.zip |
Diffstat (limited to 'deno/base')
-rw-r--r-- | deno/base/config.ts | 6 | ||||
-rw-r--r-- | deno/base/deno.json | 2 | ||||
-rw-r--r-- | deno/base/lib.ts | 24 |
3 files changed, 27 insertions, 5 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, +); |