Changes
This commit is contained in:
@@ -1,8 +1,23 @@
|
||||
import Color from "color";
|
||||
import type {Team} from "./types/team.js";
|
||||
import type {ListPage, PageList} from "./types/page.ts";
|
||||
|
||||
export const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
|
||||
|
||||
export const nameRegex = new RegExp("(?!.*\/).+(?=\\.md)");
|
||||
|
||||
export function mapToMap(pages: PageList): Map<string, ListPage[]> {
|
||||
const map = new Map();
|
||||
for (const page of pages) {
|
||||
let folder = page.path.substring(0, page.path.indexOf(nameRegex.exec(page.path)[0]));
|
||||
if (!map.has(folder)) {
|
||||
map.set(folder, []);
|
||||
}
|
||||
map.get(folder).push(page);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
export function colorFromTeam(team: Team): string {
|
||||
switch (team.color) {
|
||||
case "1":
|
||||
@@ -47,3 +62,14 @@ export function lighten(color: string) {
|
||||
export function brightness(color: string) {
|
||||
return Color(color).isLight()
|
||||
}
|
||||
|
||||
export function base64ToBytes(base64: string) {
|
||||
const binString = atob(base64);
|
||||
// @ts-ignore
|
||||
return Uint8Array.from(binString, (m) => m.codePointAt(0));
|
||||
}
|
||||
|
||||
export function bytesToBase64(bytes: Uint8Array) {
|
||||
const binString = String.fromCodePoint(...bytes);
|
||||
return btoa(binString);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user