Source

number/formatCreditCardSecurityCode.js

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var credit_card_type_1 = __importDefault(require("credit-card-type"));
var DEFAULT_LENGTH = 3;
/**
 * Limit the length of credit card security code
 *
 * @param value
 * @category number
 * @module formatCreditCardSecurityCode
 */
var formatCreditCardSecurityCode = function (value, cardNumber, separator) {
    if (separator === void 0) { separator = ' '; }
    var regexp = new RegExp(separator, 'g');
    var trimmedValue = cardNumber.replace(regexp, '').trim();
    var types = (0, credit_card_type_1.default)(trimmedValue);
    if (types.length === 1) {
        var matchedType = types[0];
        return value.substring(0, matchedType.code.size);
    }
    if (value.length > DEFAULT_LENGTH)
        return value.substring(0, DEFAULT_LENGTH);
    return value;
};
exports.default = formatCreditCardSecurityCode;