Skip to content

Commit

Permalink
Replace Class enum with key-value relationship (#86)
Browse files Browse the repository at this point in the history
Replace Class enum with object
  • Loading branch information
MattIPv4 authored Dec 11, 2024
1 parent c6d032d commit a0a660d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 70 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alveusgg/data",
"version": "0.46.0",
"version": "0.47.0",
"private": true,
"license": "SEE LICENSE IN LICENSE.md",
"repository": {
Expand Down
44 changes: 17 additions & 27 deletions src/ambassadors/classification.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
export enum Class {
Mammalia,
Aves,
Reptilia,
Amphibia,
Arachnida,
Diplopoda,
Insecta,
Malacostraca,
}

const classificationOrder = [
"Mammals",
"Birds",
Expand All @@ -18,22 +7,23 @@ const classificationOrder = [

export type Classification = (typeof classificationOrder)[number];

export const getClassification = (c: Class): Classification => {
switch (c) {
case Class.Mammalia:
return "Mammals";
case Class.Aves:
return "Birds";
case Class.Reptilia:
case Class.Amphibia:
return "Reptiles & Amphibians";
case Class.Arachnida:
case Class.Diplopoda:
case Class.Insecta:
case Class.Malacostraca:
return "Invertebrates";
}
};
const classes = {
mammalia: "Mammals",
aves: "Birds",
reptilia: "Reptiles & Amphibians",
amphibia: "Reptiles & Amphibians",
arachnida: "Invertebrates",
diplopoda: "Invertebrates",
insecta: "Invertebrates",
malacostraca: "Invertebrates",
} as const satisfies Record<string, Classification>;

export type Class = keyof typeof classes;

export const isClass = (str: string): str is Class =>
Object.keys(classes).includes(str);

export const getClassification = (c: Class): Classification => classes[c];

export const sortAmbassadorClassification = (a: Class, b: Class): number => {
return (
Expand Down
Loading

0 comments on commit a0a660d

Please sign in to comment.