"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.formatValues = void 0;
var _getCardConfig2 = require("./getCardConfig");
var _getCardType = require("./getCardType");
var _formatExpire = require("../../../helpers/formatExpire");
const PARSER = [/[^\d]/g, ''];
const formatValues = function () {
  let values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  let cards = arguments.length > 1 ? arguments[1] : undefined;
  let _values$card = values.card,
    card = _values$card === void 0 ? '' : _values$card,
    _values$CVV = values.CVV,
    CVV = _values$CVV === void 0 ? '' : _values$CVV,
    _values$expire = values.expire,
    expire = _values$expire === void 0 ? '' : _values$expire,
    _values$name = values.name,
    name = _values$name === void 0 ? '' : _values$name;
  card = card.replace(...PARSER);
  CVV = CVV.replace(...PARSER);
  expire = (0, _formatExpire.formatExpire)(expire);
  name = name.toUpperCase();
  const _getCardConfig = (0, _getCardConfig2.getCardConfig)(card),
    _getCardConfig$placeh = _getCardConfig.placeholder,
    placeholder = _getCardConfig$placeh === void 0 ? {} : _getCardConfig$placeh;
  const cardArray = card ? [...card] : [];
  card = [...placeholder.card].map(function () {
    let char = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
    return char === ' ' ? char : cardArray.length >= 0 ? cardArray.shift() : '';
  }).join('').trimEnd();
  return {
    card,
    CVV,
    expire,
    name,
    type: (0, _getCardType.getCardType)(card, cards)
  };
};
exports.formatValues = formatValues;
//# sourceMappingURL=formatValues.js.map