summaryrefslogtreecommitdiff
path: root/src/utils/strings.ts
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-01 17:27:18 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-01 17:27:18 +1100
commitff7324e7bfc1e01c8502e24a38e0729d87e63564 (patch)
tree3af12a838f191dad413c6ff7096dd83d9ee8daa5 /src/utils/strings.ts
parentlauncher: hide todo action if tod not installed (diff)
downloadcaelestia-shell-ff7324e7bfc1e01c8502e24a38e0729d87e63564.tar.gz
caelestia-shell-ff7324e7bfc1e01c8502e24a38e0729d87e63564.tar.bz2
caelestia-shell-ff7324e7bfc1e01c8502e24a38e0729d87e63564.zip
calendar: cache calendars
Diffstat (limited to 'src/utils/strings.ts')
-rw-r--r--src/utils/strings.ts10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/utils/strings.ts b/src/utils/strings.ts
index c2bf71a..4aaa916 100644
--- a/src/utils/strings.ts
+++ b/src/utils/strings.ts
@@ -1,7 +1,13 @@
export const ellipsize = (str: string, len: number) => (str.length > len ? `${str.slice(0, len - 1)}…` : str);
-export const basename = (path: string) => {
+export const basename = (path: string, stripExt = true) => {
const lastSlash = path.lastIndexOf("/");
const lastDot = path.lastIndexOf(".");
- return path.slice(lastSlash + 1, lastDot > lastSlash ? lastDot : undefined);
+ return path.slice(lastSlash + 1, stripExt && lastDot > lastSlash ? lastDot : undefined);
+};
+
+export const pathToFileName = (path: string, ext?: string) => {
+ const start = /[a-z]+:\/\//.test(path) ? 0 : path.indexOf("/") + 1;
+ const dir = path.slice(start, path.lastIndexOf("/")).replaceAll("/", "-");
+ return `${dir}-${basename(path, ext !== undefined)}${ext ? `.${ext}` : ""}`;
};