commit c30396812a5ab86f08bdd90e4a07e51e608c9625
parent 0ffcb45b2d59e7019a4b4aac94fe1d19877d88a4
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Fri, 4 Apr 2025 11:04:42 +0000
utils: add/edit utils
Diffstat:
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/utils/src/image.ts b/utils/src/image.ts
@@ -1,3 +1,5 @@
+import { type FilePath } from "$root";
+
export type MediaImageUploadResult = {
base_url: string;
file_hash: string;
@@ -5,3 +7,15 @@ export type MediaImageUploadResult = {
};
export const fmt_media_image_upload_result_url = (res: MediaImageUploadResult): string => `${res.base_url}/${res.file_hash}.${res.file_ext}`;
+
+export const parse_file_path = (file_path: string): FilePath | undefined => {
+ const file_path_spl = file_path.split(`/`);
+ const file_path_file = file_path_spl[file_path_spl.length - 1] || ``;
+ const [file_name, mime_type] = file_path_file.split(`.`);
+ if (!file_name || !mime_type) return undefined;
+ return {
+ file_path,
+ file_name,
+ mime_type
+ };
+};
+\ No newline at end of file
diff --git a/utils/src/lib.ts b/utils/src/lib.ts
@@ -1,3 +1,5 @@
+import { type CallbackPromise } from "./types";
+
export const ascii = {
bullet: '•',
dash: `—`,
@@ -28,7 +30,12 @@ export const str_trunc = (val: string, max_length: number = 28): string => {
return `${val.slice(0, max_length - 3)}...`;
};
-export const exe_iter = async (callback: () => Promise<void>, num: number = 1, delay: number = 400): Promise<void> => {
+export const str_capitalize_words = (val?: string): string => {
+ if (!val) return ``;
+ return val.split(` `).map(i => i ? `${i[0].toUpperCase()}${i.slice(1)}` : ``).filter(i => !!i).join(` `);
+};
+
+export const exe_iter = async (callback: CallbackPromise, num: number = 1, delay: number = 400): Promise<void> => {
try {
const iter_fn = (count: number) => {
if (count > 0) {