remask
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

.github/workflows/ci.yml

Remask Logo

A lightweight, dependency free and framework agnostic multi-mask lib, with Typescript support.

Install

yarn add remask

Usage

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

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:

unmask('12.345.678/0001-06')
// => 12345678000106

Currency

In currency mask, Remask use Intl.NumberFormater to mask and unmask values, so you need pass locale and currency params.

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

Package Sidebar

Install

npm i remask

Weekly Downloads

2,179

Version

1.2.2

License

MIT

Unpacked Size

17.1 kB

Total Files

10

Last publish

Collaborators

  • brunobertolini