Created
January 24, 2022 12:57
-
-
Save houssenedao/342c3779898673ba65fb5b19bff69f35 to your computer and use it in GitHub Desktop.
Retrieve merchant name
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
function findMerchant(description: string): string | undefined { | |
const Merchants = { | |
Facebook: "fcbk,facebook,fb,facebk", | |
Netflix: "netflix,nl", | |
Tinder: "tinder,gotinder", | |
Amazon: "amzn,amazon", | |
Glovo: "glovo" | |
}; | |
const merchantsKeys = Object.keys(Merchants); | |
for (const merchant of merchantsKeys) { | |
const regexBase = new RegExp( | |
Merchants[merchant].split(",").join("|"), | |
"gi" | |
); | |
if (!description.match(regexBase)) { | |
continue; | |
} | |
// console.log(description, regexBase); | |
return merchant; | |
} | |
} | |
console.log(findMerchant("AMZN 24JAN ABNRBD7JX Barcelona ES")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment