Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

projectIdentity.ts

28 lines925 Bytes

1import { PROJECT_ICON_COLORS } from "./projectIconColors";
2import type { ProjectIconColor } from "@t3tools/contracts";
3import { projectMonogram } from "@t3tools/shared/projectMonogram";
4​
5export interface ProjectIdentity {
6 readonly monogram: string;
7 readonly color: ProjectIconColor;
8}
9​
10function normalizeProjectName(projectName: string): string {
11 return projectName.normalize("NFKC").trim();
13​
14function projectColor(projectName: string): ProjectIconColor {
15 const seed = normalizeProjectName(projectName).toLocaleLowerCase("en-US") || "project";
16 let index = 0;
17 for (const glyph of seed) {
18 index = (index * 31 + (glyph.codePointAt(0) ?? 0)) % PROJECT_ICON_COLORS.length;
19 }
20 return PROJECT_ICON_COLORS[index]?.value ?? "blue";
22​
23export function deriveProjectIdentity(projectName: string): ProjectIdentity {
24 return {
25 monogram: projectMonogram(projectName),
26 color: projectColor(projectName),
27 };