From a0a660d881ac23fdcda73c6180afd8d01b615163 Mon Sep 17 00:00:00 2001 From: Matt Cowley Date: Wed, 11 Dec 2024 18:24:04 +0000 Subject: [PATCH] Replace Class enum with key-value relationship (#86) Replace Class enum with object --- package-lock.json | 4 +- package.json | 2 +- src/ambassadors/classification.ts | 44 +++++++---------- src/ambassadors/core.ts | 80 +++++++++++++++---------------- 4 files changed, 60 insertions(+), 70 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8304928..541dc9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@alveusgg/data", - "version": "0.46.0", + "version": "0.47.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@alveusgg/data", - "version": "0.46.0", + "version": "0.47.0", "license": "SEE LICENSE IN LICENSE.md", "devDependencies": { "@typescript-eslint/eslint-plugin": "^6.2.0", diff --git a/package.json b/package.json index 25321bf..451b4f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@alveusgg/data", - "version": "0.46.0", + "version": "0.47.0", "private": true, "license": "SEE LICENSE IN LICENSE.md", "repository": { diff --git a/src/ambassadors/classification.ts b/src/ambassadors/classification.ts index 5c10cfb..0396165 100644 --- a/src/ambassadors/classification.ts +++ b/src/ambassadors/classification.ts @@ -1,14 +1,3 @@ -export enum Class { - Mammalia, - Aves, - Reptilia, - Amphibia, - Arachnida, - Diplopoda, - Insecta, - Malacostraca, -} - const classificationOrder = [ "Mammals", "Birds", @@ -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; + +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 ( diff --git a/src/ambassadors/core.ts b/src/ambassadors/core.ts index 7fb4979..a4133d4 100644 --- a/src/ambassadors/core.ts +++ b/src/ambassadors/core.ts @@ -1,7 +1,7 @@ import type { IUCNStatus } from "../iucn"; import type { EnclosureKey } from "../enclosures"; import type { PartialDateString, Nullable } from "../types"; -import { Class } from "./classification"; +import type { Class } from "./classification"; import lifespans, { type Lifespan } from "./lifespans"; export type Ambassadors = typeof ambassadors; @@ -42,7 +42,7 @@ const ambassadors = { name: "Stompy", alternate: [], commands: ["stompy"], - class: Class.Aves, + class: "aves", species: "Emu", scientific: "Dromaius novaehollandiae", sex: "Male", @@ -94,7 +94,7 @@ const ambassadors = { name: "Georgie", alternate: [], commands: ["georgie"], - class: Class.Amphibia, + class: "amphibia", species: "African Bullfrog", scientific: "Pyxicephalus adspersus", sex: "Male", @@ -135,7 +135,7 @@ const ambassadors = { name: "Tico", alternate: [], commands: ["tico"], - class: Class.Aves, + class: "aves", species: "Blue and Gold Macaw", scientific: "Ara ararauna", sex: "Female", @@ -167,7 +167,7 @@ const ambassadors = { name: "Miley", alternate: ["Miele"], commands: ["miley", "miele"], - class: Class.Aves, + class: "aves", species: "Catalina Macaw", scientific: "Ara ararauna x Ara macao", sex: "Female", @@ -196,7 +196,7 @@ const ambassadors = { name: "Mia", alternate: [], commands: ["mia"], - class: Class.Aves, + class: "aves", species: "African Grey", scientific: "Psittacus erithacus", sex: "Female", @@ -231,7 +231,7 @@ const ambassadors = { name: "Siren", alternate: [], commands: ["siren"], - class: Class.Aves, + class: "aves", species: "Blue-fronted Amazon", scientific: "Amazona aestiva", sex: "Female", @@ -269,7 +269,7 @@ const ambassadors = { name: "Abbott", alternate: [], commands: ["abbott"], - class: Class.Aves, + class: "aves", species: "American Crow", scientific: "Corvus brachyrhynchos", sex: "Male", @@ -300,7 +300,7 @@ const ambassadors = { name: "Coconut", alternate: [], commands: ["coconut"], - class: Class.Aves, + class: "aves", species: "American Crow", scientific: "Corvus brachyrhynchos", sex: "Male", @@ -329,7 +329,7 @@ const ambassadors = { name: "Oliver", alternate: [], commands: ["oliver"], - class: Class.Aves, + class: "aves", species: "Olive Egger Chicken", scientific: "Gallus gallus domesticus", sex: "Male", @@ -357,7 +357,7 @@ const ambassadors = { name: "Nugget", alternate: [], commands: ["nugget"], - class: Class.Aves, + class: "aves", species: "Ameraucana Chicken", scientific: "Gallus gallus domesticus", sex: "Female", @@ -386,7 +386,7 @@ const ambassadors = { name: "Henrique", alternate: [], commands: ["henrique"], - class: Class.Aves, + class: "aves", species: "Half Dark Brahma, Half Saipan Chicken", scientific: "Gallus gallus domesticus", sex: "Female", @@ -414,7 +414,7 @@ const ambassadors = { name: "Winnie (The Moo)", alternate: [], commands: ["winnie"], - class: Class.Mammalia, + class: "mammalia", species: "Red Angus Beef Cow", scientific: "Bos (primigenius) taurus", sex: "Female", @@ -447,7 +447,7 @@ const ambassadors = { name: "Noodle", alternate: [], commands: ["noodle"], - class: Class.Reptilia, + class: "reptilia", species: "Coastal Carpet Python", scientific: "Morelia spilota mcdowelli", sex: "Female", @@ -482,7 +482,7 @@ const ambassadors = { name: "Patchy", alternate: [], commands: ["patchy"], - class: Class.Reptilia, + class: "reptilia", species: "Ball Python", scientific: "Python regius", sex: "Female", @@ -511,7 +511,7 @@ const ambassadors = { name: "Fenn", alternate: [], commands: ["fenn"], - class: Class.Mammalia, + class: "mammalia", species: "American Red Fox", scientific: "Vulpes vulpes fulva", sex: "Male", @@ -548,7 +548,7 @@ const ambassadors = { name: "Reed", alternate: [], commands: ["reed"], - class: Class.Mammalia, + class: "mammalia", species: "American Red Fox", scientific: "Vulpes vulpes fulva", sex: "Male", @@ -584,7 +584,7 @@ const ambassadors = { name: "Serrano", alternate: [], commands: ["serrano"], - class: Class.Mammalia, + class: "mammalia", species: "Domestic Donkey", scientific: "Equus africanus asinus", sex: "Male", @@ -617,7 +617,7 @@ const ambassadors = { name: "Jalapeño", alternate: [], commands: ["jalapeno", "jalapeño"], - class: Class.Mammalia, + class: "mammalia", species: "Domestic Donkey", scientific: "Equus africanus asinus", sex: "Male", @@ -648,7 +648,7 @@ const ambassadors = { name: "Snork", alternate: [], commands: ["snork"], - class: Class.Mammalia, + class: "mammalia", species: "Chinchilla", scientific: "Chinchilla lanigera", sex: "Female", @@ -677,7 +677,7 @@ const ambassadors = { name: "Moomin", alternate: [], commands: ["moomin"], - class: Class.Mammalia, + class: "mammalia", species: "Chinchilla", scientific: "Chinchilla lanigera", sex: "Male", @@ -709,7 +709,7 @@ const ambassadors = { name: "Momo", alternate: [], commands: ["momo"], - class: Class.Mammalia, + class: "mammalia", species: "Black Tufted Marmoset", scientific: "Callithrix penicillata", sex: "Male", @@ -740,7 +740,7 @@ const ambassadors = { name: "Appa", alternate: [], commands: ["appa"], - class: Class.Mammalia, + class: "mammalia", species: "Common Marmoset", scientific: "Callithrix jacchus", sex: "Male", @@ -771,7 +771,7 @@ const ambassadors = { name: "Push Pop", alternate: ["Poppy"], commands: ["pushpop", "poppy"], - class: Class.Reptilia, + class: "reptilia", species: "Sulcata Tortoise", scientific: "Centrochelys sulcata", sex: null, // Unknown, assumed female @@ -806,7 +806,7 @@ const ambassadors = { name: "Toaster Strudel", alternate: [], commands: ["toast", "toaster"], - class: Class.Reptilia, + class: "reptilia", species: "Blue-tongued Skink", scientific: "Tiliqua scincoides intermedia", sex: "Male", @@ -835,7 +835,7 @@ const ambassadors = { name: "Hank Mr. McTrain", alternate: ["Hank The Tank Choo Choo Mr. McTrain", "Mr. Conductor Man"], commands: ["hank"], - class: Class.Diplopoda, + class: "diplopoda", species: "Smokey Ghost Millipede", scientific: "Narceus gordanus", sex: "Male", @@ -867,7 +867,7 @@ const ambassadors = { name: "Barbara / Baked Bean", alternate: [], commands: ["barbara", "bakedbean"], - class: Class.Insecta, + class: "insecta", species: "Madagascar Hissing Cockroaches", scientific: "Gromphadorhina portentosa", sex: null, @@ -896,7 +896,7 @@ const ambassadors = { name: "Marty", alternate: [], commands: ["marty"], - class: Class.Malacostraca, + class: "malacostraca", species: "Zebra Isopods", scientific: "Armadillidium maculatum", sex: null, @@ -924,7 +924,7 @@ const ambassadors = { name: "BB", alternate: ["Bonus Bug"], commands: ["bb", "bonusbug"], - class: Class.Malacostraca, + class: "malacostraca", species: "Spanish Orange Isopods", scientific: "Porcellio scaber", sex: null, @@ -953,7 +953,7 @@ const ambassadors = { name: "Tortellini", alternate: [], commands: ["tortellini"], - class: Class.Arachnida, + class: "arachnida", species: "Emperor Scorpion", scientific: "Pandinus imperator", sex: "Male", @@ -982,7 +982,7 @@ const ambassadors = { name: "Puppy", alternate: [], commands: ["puppy"], - class: Class.Arachnida, + class: "arachnida", species: "Emperor Scorpion", scientific: "Pandinus imperator", sex: "Male", @@ -1011,7 +1011,7 @@ const ambassadors = { name: "Awa", alternate: [], commands: ["awa"], - class: Class.Mammalia, + class: "mammalia", species: "Wolf Hybrid", scientific: "Canis lupus x Canis familiaris", sex: "Female", @@ -1040,7 +1040,7 @@ const ambassadors = { name: "Chips Ahoy", alternate: [], commands: ["chips", "chipsahoy"], - class: Class.Mammalia, + class: "mammalia", species: "Domestic Rat", scientific: "Rattus norvegicus f. domestica", sex: "Female", @@ -1069,7 +1069,7 @@ const ambassadors = { name: "Polly", alternate: [], commands: ["polly"], - class: Class.Aves, + class: "aves", species: "Bantam Silkie Chicken", scientific: "Gallus gallus domesticus", sex: "Female", @@ -1099,7 +1099,7 @@ const ambassadors = { name: "Orion", alternate: [], commands: ["orion"], - class: Class.Aves, + class: "aves", species: "Prairie/Peregrine Falcon", scientific: "Falco mexicanus x Falco peregrinus", sex: "Male", @@ -1128,7 +1128,7 @@ const ambassadors = { name: "Pickles", alternate: [], commands: ["pickles"], - class: Class.Arachnida, + class: "arachnida", species: "Vinegaroon", scientific: "Mastigoproctus tohono", sex: "Female", @@ -1157,7 +1157,7 @@ const ambassadors = { name: "Henrietta", alternate: [], commands: ["henrietta"], - class: Class.Aves, + class: "aves", species: "Jersey Giant Chicken", scientific: "Gallus gallus domesticus", sex: "Female", @@ -1186,7 +1186,7 @@ const ambassadors = { name: "Ducky", alternate: [], commands: ["ducky"], - class: Class.Malacostraca, + class: "malacostraca", species: "Rubber Ducky Isopods", scientific: "Cubaris sp.", sex: null, @@ -1215,7 +1215,7 @@ const ambassadors = { name: "Nilla Wafer", alternate: [], commands: ["nilla", "nillawafer"], - class: Class.Mammalia, + class: "mammalia", species: "Domestic Rat", scientific: "Rattus norvegicus f. domestica", sex: "Female", @@ -1244,7 +1244,7 @@ const ambassadors = { name: "Timber", alternate: [], commands: ["timber"], - class: Class.Mammalia, + class: "mammalia", species: "Wolf Hybrid", scientific: "Canis lupus x Canis familiaris", sex: "Male",