Skip to content

Instantly share code, notes, and snippets.

@houssenedao
Created January 24, 2022 12:57
Show Gist options
  • Save houssenedao/342c3779898673ba65fb5b19bff69f35 to your computer and use it in GitHub Desktop.
Save houssenedao/342c3779898673ba65fb5b19bff69f35 to your computer and use it in GitHub Desktop.
Retrieve merchant name
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