Update deno.json to run tests on all files in the lib directory, enhance README with requirements section, add new campaign entries to campaign inventory, and implement normalization function for BeatSaver input with corresponding tests.
This commit is contained in:
@@ -87,10 +87,15 @@ export async function fetchBeatSaverByHash(
|
||||
return mapBeatSaverResponseToMeta(data);
|
||||
}
|
||||
|
||||
/** Strip Twitch-style `!bsr` prefix when pasting a map key (e.g. `!bsr 43a47` → `43a47`). */
|
||||
export function normalizeBeatSaverLookupInput(input: string): string {
|
||||
return input.trim().replace(/^!bsr\s*/i, "").trim();
|
||||
}
|
||||
|
||||
export async function resolveBeatSaverMeta(
|
||||
input: string,
|
||||
): Promise<BeatSaverMapMeta | null> {
|
||||
const s = input.trim();
|
||||
const s = normalizeBeatSaverLookupInput(input);
|
||||
if (!s) return null;
|
||||
if (/^[a-f0-9]{40}$/i.test(s)) {
|
||||
return await fetchBeatSaverByHash(s);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { normalizeBeatSaverLookupInput } from "./beatsaver.ts";
|
||||
|
||||
Deno.test("normalizeBeatSaverLookupInput strips !bsr prefix with space", () => {
|
||||
assertEquals(normalizeBeatSaverLookupInput("!bsr 43a47"), "43a47");
|
||||
});
|
||||
|
||||
Deno.test("normalizeBeatSaverLookupInput strips !BSR and trims", () => {
|
||||
assertEquals(normalizeBeatSaverLookupInput(" !BSR abc12 "), "abc12");
|
||||
});
|
||||
|
||||
Deno.test("normalizeBeatSaverLookupInput strips !bsr without space before key", () => {
|
||||
assertEquals(normalizeBeatSaverLookupInput("!bsr43a47"), "43a47");
|
||||
});
|
||||
|
||||
Deno.test("normalizeBeatSaverLookupInput leaves hash unchanged", () => {
|
||||
const h = "a".repeat(40);
|
||||
assertEquals(normalizeBeatSaverLookupInput(h), h);
|
||||
});
|
||||
Reference in New Issue
Block a user