import { getCardTypeByValue } from './types';
export const formatCardNumber = (cardNumber, cardTypes = []) => {
    const cardType = getCardTypeByValue(cardNumber, cardTypes);
    if (!cardType)
        return (cardNumber.match(/\d+/g) || []).join('');
    const format = cardType === null || cardType === void 0 ? void 0 : cardType.format;
    if (format && format.global) {
        return (cardNumber.match(format) || []).join(' ');
    }
    if (format) {
        const execResult = format.exec(cardNumber.split(' ').join(''));
        if (execResult) {
            return execResult
                .splice(1, 3)
                .filter((x) => x)
                .join(' ');
        }
    }
    return cardNumber;
};
