dd-spell-scry/src/Spell.ts

32 lines
562 B
TypeScript
Raw Normal View History

2023-07-01 14:03:45 +00:00
export type Spell = {
name: string;
cost: number;
color: string;
category: string;
description: string;
reserveMagic?: boolean;
cantripMagic?: boolean;
}
export const spellSort = (a: Spell, b: Spell) => {
let compareValue = 0;
if (!a) {
return -1;
} else if (!b) {
return 1;
}
compareValue = a.color.localeCompare(b.color);
if (compareValue == 0) {
compareValue = a.category.localeCompare(b.category);
if (compareValue == 0) {
compareValue = a.name.localeCompare(b.name);
}
}
return compareValue;
};