mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-04 04:05:58 -05:00
38 lines
932 B
TypeScript
38 lines
932 B
TypeScript
import type { AnyWeapon } from "~/features/build-analyzer/analyzer-types";
|
|
import { weaponAltNames } from "~/modules/in-game-lists/weapon-alt-names";
|
|
import { abilities } from "./abilities";
|
|
import type { Ability } from "./types";
|
|
|
|
export function isAbility(value: string): value is Ability {
|
|
return Boolean(abilities.some((a) => a.name === value));
|
|
}
|
|
|
|
const normalizeTerm = (term: string): string => {
|
|
return term.trim().toLocaleLowerCase();
|
|
};
|
|
|
|
export function filterWeapon({
|
|
weapon,
|
|
weaponName,
|
|
searchTerm,
|
|
}: {
|
|
weapon: AnyWeapon;
|
|
weaponName: string;
|
|
searchTerm: string;
|
|
}): boolean {
|
|
const normalizedSearchTerm = normalizeTerm(searchTerm);
|
|
const normalizedWeaponName = normalizeTerm(weaponName);
|
|
|
|
if (normalizedWeaponName.includes(normalizedSearchTerm)) {
|
|
return true;
|
|
}
|
|
|
|
if (weapon.type === "MAIN") {
|
|
return (
|
|
weaponAltNames.get(weapon.id)?.includes(normalizedSearchTerm) ?? false
|
|
);
|
|
}
|
|
|
|
return false;
|
|
}
|