char-slop/berry

multipurpose self-modifiable agentic harness

git clone https://git.t4t.associates/char-slop/berry

Charlotte Sominitial commite6df845

main
673 B16 linesraw
1/** file or fence → grammar, as sorcery's */
2
3import languages from "./languages.json" with { type: "json" };
4
5const filenames = new Map(Object.entries(languages.filenames));
6const aliases = new Map(Object.entries(languages.aliases));
7
8/** By file name, then by extension. */
9export function detectLanguage(path: string): string | null {
10  const name = path.split(/[/\\]/).at(-1)!.toLowerCase();
11  return filenames.get(name) ?? aliases.get(name) ?? aliases.get(name.split(".").at(-1)!) ?? null;
12}
13
14/** A name such as a markdown fence's: `ts`, `typescript`, `sh`. */
15export const languageNamed = (name: string): string | null =>
16  aliases.get(name.toLowerCase()) ?? null;