Files
docmost/apps/client/src/lib/utils.ts
T
Philipinho f2a193ac8d Allow creation of space
* other fixes and cleanups
2024-06-24 20:06:57 +01:00

28 lines
700 B
TypeScript

export function formatMemberCount(memberCount: number): string {
if (memberCount === 1) {
return "1 member";
} else {
return `${memberCount} members`;
}
}
export function extractPageSlugId(input: string): string {
if (!input) {
return undefined;
}
const parts = input.split("-");
return parts.length > 1 ? parts[parts.length - 1] : input;
}
export const computeSpaceSlug = (name: string) => {
const alphanumericName = name.replace(/[^a-zA-Z0-9\s]/g, "");
if (alphanumericName.includes(" ")) {
return alphanumericName
.split(" ")
.map((word) => word.charAt(0).toUpperCase())
.join("");
} else {
return alphanumericName.toLowerCase();
}
};