Skip to content

Instantly share code, notes, and snippets.

@barthap
Created December 29, 2022 10:14
Show Gist options
  • Save barthap/54f6b8ccc39f6ab1fbc66c9b36d11845 to your computer and use it in GitHub Desktop.
Save barthap/54f6b8ccc39f6ab1fbc66c9b36d11845 to your computer and use it in GitHub Desktop.
Typescript-refactored famous Polish Railways PKP isPies implementation
// 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