Created
December 29, 2022 10:14
-
-
Save barthap/54f6b8ccc39f6ab1fbc66c9b36d11845 to your computer and use it in GitHub Desktop.
Typescript-refactored famous Polish Railways PKP isPies implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery | |
declare let $: any; | |
enum DogOptions { | |
DOG = 17, | |
ASSISTANT_DOG = 18, | |
GUIDE_DOG = 19, | |
}; | |
/** | |
* Type guard checking if given {@link option} is one of {@link DogOptions} | |
*/ | |
function optionIsDogOption(option: number): option is DogOptions { | |
const allDogOptions = Object.values(DogOptions).filter(it => typeof it === "number") as number[]; | |
return allDogOptions.includes(option) | |
} | |
/** | |
* PKP-backwards-compatible function to check if dog is selected | |
*/ | |
function czyWybranoPsa() { | |
return $(".bilet-dodatkowy") | |
.map((_: any, elem: any) => $(elem).val() as number) | |
.any(optionIsDogOption); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment