1.0.5 • Published 4 years ago

msk v1.0.5

Weekly downloads
1,292
License
MIT
Repository
github
Last release
4 years ago

msk Build Status

Small library to mask strings

Install

$ npm install msk

Usage

const msk = require("msk");

msk("552122222222", "+99 (99) 9999-9999")
// "+55 (21) 2222-2222"

msk.fit("22231-0004131", "99999-999")
// "22231-000"

API

msk(str, mask)

Returns a formatted string based on the mask prodived

str

Type: string

A string to apply the mask.

mask

Type: string

A mask is formed based on the following symbols:

SymbolAccepts
9Numbers ([0-9])
ALetters ([A-ú])
SAlphanumeric chars ([A-ú0-9])
*Anything
other charSpecified char

msk.fit(str, mask)

Returns a formatted string removing the exceeding characters.

Examples

msk("552122222222", "+99 (99) 9999-9999")
// "+55 (21) 2222-2222"
msk("V6G1C9", "A9A 9A9")
// "V6G 1C9"
msk("I love msk", "*-****-***")
// "I-love-msk"
msk.fit("22231-0004131", "99999-999")
// "22231-000"

License

MIT © VTEX