Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement