mirror of
https://github.com/docmost/docmost.git
synced 2025-11-13 04:22:37 +10:00
* fix current slider value * WIP * changes to extension attributes * update command title
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
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();
|
|
}
|
|
};
|
|
|
|
export const formatBytes = (
|
|
bytes: number,
|
|
decimalPlaces: number = 2,
|
|
): string => {
|
|
if (bytes === 0) return "0.0 KB";
|
|
|
|
const unitSize = 1024;
|
|
const precision = decimalPlaces < 0 ? 0 : decimalPlaces;
|
|
const units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
|
|
const kilobytes = bytes / unitSize;
|
|
|
|
const unitIndex = Math.floor(Math.log(kilobytes) / Math.log(unitSize));
|
|
const adjustedUnitIndex = Math.max(unitIndex, 0);
|
|
const adjustedSize = kilobytes / Math.pow(unitSize, adjustedUnitIndex);
|
|
|
|
return `${adjustedSize.toFixed(precision)} ${units[adjustedUnitIndex]}`;
|
|
};
|