CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/share/util.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { basename } from "path";
7
export { getExtension, containingPath } from "@cocalc/util/misc";
8
9
export function isUUID(s: string): boolean {
10
// todo: add full check.
11
return typeof s == "string" && s.length == 36;
12
}
13
14
export function isSha1Hash(s: string): boolean {
15
return typeof s == "string" && s.length == 40;
16
// todo: could add full check (i.e., each character is in 0-e)
17
}
18
19
export function trunc(s: string, n: number): string {
20
return s.length > n ? s.slice(0, n - 1) + "…" : s;
21
}
22
23
export function getTitle({
24
path,
25
relativePath,
26
}: {
27
path: string;
28
relativePath: string;
29
}): string {
30
const b = basename(relativePath);
31
return b ? b : basename(path);
32
}
33
34