forked from different-ai/file-organizer-2000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
32 lines (28 loc) · 917 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export function formatToSafeName(format: string) {
return format.replace(/[\\/:"]/g, "");
}
export function cleanPath(path: string) {
const trimmedPath = path.trim();
// cleanup path remove leading and trailing slashes
const pathWithoutLeadingAndTrailingSlashes = trimmedPath.replace(
/^\/+|\/+$/g,
""
);
return pathWithoutLeadingAndTrailingSlashes;
}
export const logMessage = (...args: any[]) => {
if (process.env.NODE_ENV === "production") {
return;
}
console.log(...args);
};
export function sanitizeTag(tag: string): string {
// Remove any leading '#' symbols
let sanitized = tag.replace(/^#+/, "");
// Replace spaces and special characters with underscores
sanitized = sanitized.replace(/[^\w\-]+/g, "_");
// Remove any leading or trailing underscores
sanitized = sanitized.replace(/^_+|_+$/g, "");
// Ensure the tag starts with a '#'
return "#" + sanitized;
}