# tinymask

> A js mask simple like killing zombies =).

Latest version **1.0.2** (published 2017-05-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install tinymask
pnpm add tinymask
yarn add tinymask
bun add tinymask
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2017-05-23 |
| First published | 2017-05-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ben-hur Santos Ott |
| Maintainers | benhurott |
| Keywords | mask, js, simple, vanilla |

## Links

- npm: https://www.npmjs.com/package/tinymask
- Repository: https://github.com/benhurott/tinymask
- Homepage: https://github.com/benhurott/tinymask#readme
- Issues: https://github.com/benhurott/tinymask/issues
- npm.io page: https://npm.io/package/tinymask

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.2 (latest) — 2017-05-23
- 1.0.1 — 2017-05-23
- 1.0.0 — 2017-05-23

## README

# tinymask
A js mask simple like killing zombies =).

## Usage
Install it from npm using `npm install --save tinymask`

```js
var TinyMask = require('tinymask')
var maskInstance = TinyMask('9999-9999');

var result = maskInstance.mask('12345678');

console.log(result); //1234-5678
```

By default, we use this translation:

* `9` -> Accept numbers
* `A` -> Accept alpha
* `S` -> Accept alphanumerics
* `*` -> Accept all

### Options
You can pass options for the mask. We use the defaults:

```js
var maskInstance = TinyMask('9999-9999', {
	translation: {
		'9': function (val) {
			return val.replace(/[^0-9]+/g, '');
		},
		'A': function (val) {
			return val.replace(/[^a-zA-Z]+/g, '');
		},
		'S': function (val) {
			return val.replace(/[^a-zA-Z0-9]+/g, '');
		},
		'*': function (val) {
			return val;
		}
	},
	invalidValues: [null, undefined, '']
});
```

**translation (Object | optional)**

You can add or override any of the translation keys. Ex:

```js
var maskInstance = TinyMask('9999-9999', {
	translation: {
		// in this case, we add new # translation that allow
		// blank spaces.
		'#': function (val) {
			if (val === ' ') {
				return val;
			}

			return null;
		},
		// here we override the * translation to accept only
		// some characters instead all characters.
		'*': function (val) {
			if (['*', '!', '?'].indexOf(val) >= 0) {
				return val;
			}
			return null;
		}
	}
});
```

**invalidValues (Array | optional)**

You can set ignored value. If any translation result on one of this values, that will be ignored.

```js
var maskInstance = TinyMask('9999-9999', {
	// in this case, all null, undefined, empty string or blanck spaces returned from translation will be ignored.
	invalidValues: [null, undefined, '', ' ']
});
```

## Release Notes

## 1.0.2
* Fixing editing after complete mask.

## 1.0.1
* Fixing fixed masks.

### 1.0.0
* Releasing the first version of the mask.

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