# stringmask-js

> mask strings in javascript

Latest version **1.0.2** (published 2019-12-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install stringmask-js
pnpm add stringmask-js
yarn add stringmask-js
bun add stringmask-js
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-12-12 |
| First published | 2019-12-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jaykon Willian de Oliveira |
| Maintainers | jaykon-w |

## Links

- npm: https://www.npmjs.com/package/stringmask-js
- Repository: https://github.com/jaykon-w/stringmask
- Homepage: https://github.com/jaykon-w/stringmask#readme
- Issues: https://github.com/jaykon-w/stringmask/issues
- npm.io page: https://npm.io/package/stringmask-js

## Recent versions

- 1.0.2 (latest) — 2019-12-12
- 1.0.1 — 2019-12-11
- 1.0.0 — 2019-12-11

## README

# Stringmask-js

[![https://nodei.co/npm/stringmask-js.png?downloads=true&downloadRank=true&stars=true](https://nodei.co/npm/stringmask-js.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/stringmask-js)

A tiny javascript library to mask strings

## Instalation

```
npm i stringmask-js -s
```

or

```
yarn add stringmask-js
```

### Examples

#### Phone number

```js
stringMask("(00) 0000-00000")("12726323132"); // (12) 7263-23132
```

#### Only numbers

```js
stringMask("0$")("12312312W"); // 12312312
```

#### Date

```js
stringMask("0000-00-00")("19981001"); // 1998-10-01
```

#### CPF

```js
stringMask("000.000.000-00")("12345678910"); // 123.456.789-10
```

### Special Characteres

- 0 - Numbers
- \$ - Any caractere (if is the last charactere it will repeat the previous Special Character forever)
- A - Alphanumerics
- S - Letters
- U - Letters (it will transform any letter to upper case)
- L - Letters (it will transform any letter to lower case)

#### Mask inputs with React

```jsx
const MaskedInput = (props) => {
  const { mask, cleaner, value: _, ...rest } = props;
  const [ value, setValue ] = useState(props.value);

  useEffect(() => {
    setValue(stringMask(mask, cleaner)(props.value));
  }, [props.value]);

  return <input {...rest} value={value} />
}

...

<MaskedInput
  name="phone"
  value={testValue}
  cleaner={/\D/g}
  mask="(00) 0000-00000"
  onChange={({target: {value}}) => setTestValue(value)}
/>
```

---
_Source: https://npm.io/package/stringmask-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
