Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vtex/msk
Small library to mask strings
https://github.com/vtex/msk
srv-my-account xp-post-purchase
Last synced: about 1 month ago
JSON representation
Small library to mask strings
- Host: GitHub
- URL: https://github.com/vtex/msk
- Owner: vtex
- Created: 2017-07-05T21:59:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T13:23:21.000Z (over 1 year ago)
- Last Synced: 2024-11-21T08:13:51.439Z (about 1 month ago)
- Topics: srv-my-account, xp-post-purchase
- Language: JavaScript
- Size: 453 KB
- Stars: 23
- Watchers: 157
- Forks: 3
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# msk [![Build Status](https://travis-ci.org/vtex/msk.svg?branch=master)](https://travis-ci.org/vtex/msk)
> Small library to mask strings
## Install
```sh
$ npm install msk
```## Usage
```js
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:
Symbol | Accepts
---|---
`9` | Numbers (`[0-9]`)
`A` | Letters (`[A-ú]`)
`S` | Alphanumeric chars (`[A-ú0-9]`)
`*` | Anything
other char | Specified char### msk.fit(str, mask)
Returns a formatted string removing the exceeding characters.
## Examples
```js
msk("552122222222", "+99 (99) 9999-9999")
// "+55 (21) 2222-2222"
``````js
msk("V6G1C9", "A9A 9A9")
// "V6G 1C9"
``````js
msk("I love msk", "*-****-***")
// "I-love-msk"
``````js
msk.fit("22231-0004131", "99999-999")
// "22231-000"
```## License
MIT © [VTEX](https://www.vtex.com)