CaioQuirinoMedeiros / react-native-mask-input

🎭:iphone: A simple and effective Text Input with mask for ReactNative on iOS and Android. Includes obfuscation characters feature.
https://www.npmjs.com/package/react-native-mask-input
MIT License
309 stars 31 forks source link

Feature Request - export MaskItem and MaskType types #9

Closed thenriquedb closed 2 years ago

thenriquedb commented 2 years ago

An interesting feature would be to export some of the built-in types from the library so that they can be used to type the component's built-in methods.

In this example I had to redeclare the types again inside the component file so I could use them in my getMask function

type MaskItem = string | RegExp | [RegExp];
type MaskType = Array<MaskItem> | ((value?: string) => Array<MaskItem>);

function getMask(): MaskType {
    const masks: Record<Mask, MaskType> = {
      cpf: Masks.BRL_CPF,
      cnpj: Masks.BRL_CNPJ,
      money: Masks.BRL_CURRENCY,
      datetime: Masks.DATE_DDMMYYYY,
      'credit-card': Masks.CREDIT_CARD,
      'cel-phone': Masks.BRL_PHONE,
      'zip-code': Masks.ZIP_CODE,
      'only-numbers': [/^[0-9]*$/],
    };

    return masks[type] || '';
  }

My custom component use:

  <InputMask
     value={value}
     type="cpf"
     size="sm"
     placeholder="CPF"
     onChangeText={setValue}
   />
CaioQuirinoMedeiros commented 2 years ago

Thanks @thenriquedb! I'll do that

CaioQuirinoMedeiros commented 2 years ago

released on v1.0.5