# All files / elements/forms/TextField utils.js

100% Statements 26/26
100% Branches 14/14
100% Functions 4/4
100% Lines 26/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    6011x
    11x

    11x

    11x

    11x

    11x

    11x
    133x
    6x

    127x
    3x

    124x
    124x
    620x
    21x

    124x
    124x

    11x
    23x
    3x

    20x
    20x
    100x
    20x

    20x
    20x

     const cleaveMap = new Map();
    cleaveMap.set('phone', {
      delimiter: '-',
      phone: true,
      phoneRegionCode: 'US',
    });
    cleaveMap.set('currency', {
      numeral: true,
      numeralThousandsGroupStyle: 'thousand',
      prefix: '$',
    });
    cleaveMap.set('integer', {
      numeral: true,
      numeralDecimalScale: 0,
      numeralThousandsGroupStyle: 'thousand',
    });
    cleaveMap.set('numeric', {
      numeral: true,
      numeralThousandsGroupStyle: 'thousand',
    });
    cleaveMap.set('postalCode', {
      blocks: [5, 4],
      delimiter: '-',
      delimiterLazyShow: true,
      numericOnly: true,
    });

    export const isCleaveInput = props => {
      if (props.email || props.password) {
        return false;
      }
      if (props.formatterOptions) {
        return true;
      }
      let foundKey = false;
      const checkKeys = (value, key) => {
        if (props[key] && !foundKey) {
          foundKey = true;
        }
      };

      cleaveMap.forEach(checkKeys);
      return foundKey;
    };

    export const cleaveOption = props => {
      if (props.formatterOptions) {
        return props.formatterOptions;
      }
      let options = null;
      const setOptionWhenFound = (value, key) => {
        if (props[key]) {
          options = value;
        }
      };

      cleaveMap.forEach(setOptionWhenFound);
      return options;
    };