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 | 3f5c388e8bc41b1b6d219743b125ef541efeed96 (patch) | |
tree | b16853c32d2dabfc1af7b1fb04dd019c69e8d680 /deno/base/lib.ts | |
parent | 888650202daeed5c5b423013df9a629d36c3d007 (diff) | |
download | crupest-3f5c388e8bc41b1b6d219743b125ef541efeed96.tar.gz crupest-3f5c388e8bc41b1b6d219743b125ef541efeed96.tar.bz2 crupest-3f5c388e8bc41b1b6d219743b125ef541efeed96.zip |
mail: organize utils in namespace-like object. no logging cause.
Diffstat (limited to 'deno/base/lib.ts')
-rw-r--r-- | deno/base/lib.ts | 24 |
1 files changed, 22 insertions, 2 deletions
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, +); |