Created
September 27, 2019 12:13
-
-
Save rpdiss/04a37ffde5156ceaf3e1ac5c981ee4b7 to your computer and use it in GitHub Desktop.
Revisions
-
rpdiss revised this gist
Sep 27, 2019 . No changes.There are no files selected for viewing
-
rpdiss created this gist
Sep 27, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ export const maskCreditCard = async (creditCard: string, start: number, end: number, mask = `*`): Promise<string> => { const pattern = `(?<=[0-9]{${start}})(?:.*:?)(?=[0-9]{${end}})`; const regExp = new RegExp(pattern, 'g'); const startRes = creditCard.substr(0, start); const endRes = creditCard.substr(creditCard.length - end); const maskMatch = '4505290686046367'.match(regExp); return maskMatch ? `${startRes}${maskMatch[0].replace(/[a-zA-Z0-9]/g, mask)}${endRes}` : creditCard.replace(/[a-zA-Z0-9]/g, mask); };