Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. export const maskCreditCard = async (creditCard: string, start: number, end: number, mask = `*`): Promise<string> => {
  2. const pattern = `(?<=[0-9]{${start}})(?:.*:?)(?=[0-9]{${end}})`;
  3. const regExp = new RegExp(pattern, 'g');
  4. const startRes = creditCard.substr(0, start);
  5. const endRes = creditCard.substr(creditCard.length - end);
  6. const maskMatch = '4505290686046367'.match(regExp);
  7. return maskMatch ? `${startRes}${maskMatch[0].replace(/[a-zA-Z0-9]/g, mask)}${endRes}` : creditCard.replace(/[a-zA-Z0-9]/g, mask);
  8. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement