RonaldJerez / vue-input-facade

A lightweight and dependency free input masking library created specific for Vue
https://ronaldjerez.github.io/vue-input-facade/latest/
183 stars 27 forks source link

export formatter function to use it with strings #88

Closed zhiga90 closed 8 months ago

zhiga90 commented 9 months ago

Let's say there is an input for entering information and a mask for input. So, after entering and saving information, it is advisable to store it without a mask, but output it with a mask.

Let's say you need a phone input for authorization. For convenience, Input with a mask. But value without a mask to send to the backend. Then somewhere on the page you need to display this phone number, which was received from backed. With the same mask. It would be great to have masks in the same file in the project and use the same mask for both input and just a string. And use one library

// InputPhone.vue
import mask from 'masks'
<input-facade :mask="mask" />

//UserCard.vue
import { format } from 'vue-input-facade
import mask from 'masks'
{{ format(mask, phone) }}
zhiga90 commented 9 months ago

I believe that it is already available now, but I don’t understand how

RonaldJerez commented 8 months ago

@zhiga90 If you are using vue 2.x you can use a filter for static text. https://ronaldjerez.github.io/vue-input-facade/latest/#filter

In both v2.x and the beta version 3, we export the masker function, which you can use programmatically to mask data.

import { masker } from `vue-input-facade`

// masker(phone, mask)
masker('12345', '####')