https://github.com/brunobertolini/remask
A lightweight, dependency free and framework agnostic multi-mask lib, with Typescript support.
https://github.com/brunobertolini/remask
input-mask mask
Last synced: over 1 year ago
JSON representation
A lightweight, dependency free and framework agnostic multi-mask lib, with Typescript support.
- Host: GitHub
- URL: https://github.com/brunobertolini/remask
- Owner: brunobertolini
- License: mit
- Created: 2019-02-04T20:00:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-07T14:09:50.000Z (almost 3 years ago)
- Last Synced: 2024-10-29T22:33:28.838Z (over 1 year ago)
- Topics: input-mask, mask
- Language: TypeScript
- Homepage: https://codesandbox.io/s/5k4960xmyn
- Size: 660 KB
- Stars: 154
- Watchers: 2
- Forks: 9
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: license
Awesome Lists containing this project
README
[](https://github.com/brunobertolini/remask/actions/workflows/ci.yml)
> A lightweight, dependency free and framework agnostic multi-mask lib, with Typescript support.
## Install
```
yarn add remask
```
## Usage
```js
import { mask } from 'remask'
const value = 'ABC1C83'
const pattern = 'AAA - 9S99'
mask(value, pattern)
// ABC - 1C83
```
Pattern can be a pattern array, so remask choose one pattern based on pattern/value length match
```js
const patterns = ['999.999.999-99', '99.999.999/9999-99']
mask('12345678901', patterns) // gets firts pattern (999.999.999-99)
// => 123.456.789-01
mask('12345678000106', patterns) // gets second pattern (99.999.999/9999-99)
// => 12.345.678/0001-06
```
and you can use `unmask` function to remove any mask pattern:
```js
unmask('12.345.678/0001-06')
// => 12345678000106
```
### Currency
In currency mask, Remask use [Intl.NumberFormater](https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) to mask and unmask values, so you need pass [locale](https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_negotiation) and currency params.
```js
import { currency } from 'remask'
currency.mask({ locale: 'pt-BR', currency: 'BRL', value: 123456.78 })
// => R$ 123.456,78
currency.unmask({ locale: 'pt-BR', currency: 'BRL', value: 'R$ 123.456,78' })
// => 123456.78
```
## License
MIT © [Bruno Bertolini](http://brunobertolini.com)