Socket
Socket
Sign inDemoInstall

@tadashi/mask

Package Overview
Dependencies
0
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.2.0

src/index.mjs

79

dist/index.js

@@ -13,6 +13,8 @@ (function (global, factory) {

var instances = new Map();
var GUID = 0;
var GUID = Symbol('GUID');
var EVENT = Symbol('EVENT');
var Mask = function Mask(input, mask) {
if ( mask === void 0 ) mask = false;
if ( mask === void 0 ) mask = '';

@@ -23,49 +25,45 @@ if (input instanceof HTMLInputElement === false) {

// Check if element was initialized and return your instance
var initialized = Mask.data(input);
if (initialized instanceof Mask) {
return initialized
// Check if element has an instance
var instance = Mask.data(input);
if (instance instanceof Mask) {
return instance
}
this.input = input;
this.mask = input.dataset.mask || mask;
// Storage current instance
var id = ++GUID;
this.input.GUID = id;
instances.set(id, this);
// Check if has mask
if (this.mask.length === 0) {
throw new Error('The mask can not be empty')
}
this.mask = input.dataset.mask || mask;
this.maskArr = this.mask.split('');
this.event = 'input';
this.input.addEventListener(this.event, this);
// Listener
this[EVENT] = 'input';
this.input.addEventListener(this[EVENT], this);
// Storage instance
this.input[GUID] = (Math.random()) + "_" + (Date.now());
instances.set(this.input[GUID], this);
};
Mask.data = function data (input) {
var id = input && input.GUID;
return instances.has(id) && instances.get(id)
return instances.has(input[GUID]) && instances.get(input[GUID])
};
Mask.prototype.masking = function masking (event) {
var this$1 = this;
Mask.masking = function masking (_value, _mask) {
var value = String(_value).replace(/[^0-9a-zA-Z]/g, '');
var mask = String(_mask);
var input = event ? event.target : this.input;
var iArr = input.value.split('');
var iTotal = iArr.length;
var mTotal = this.maskArr.length;
var res = [];
var cc = 0;
for (var i = 0; i < mTotal; i++) {
var char = this$1.maskArr[i];
if (iTotal > cc) {
for (var i = 0; i < mask.length; i++) {
var char = mask.charAt(i);
if (value.length > cc) {
if (map.has(char)) {
if (map.get(char).test(iArr[cc])) {
res.push(iArr[cc++]);
if (map.get(char).test(value.charAt(cc))) {
res.push(value.charAt(cc++));
} else {
break
}
} else if (char === iArr[cc]) {
res.push(char);
cc++;
} else {

@@ -76,11 +74,18 @@ res.push(char);

}
input.value = res.join('');
return res.join('')
};
Mask.prototype.masking = function masking (event) {
/* istanbul ignore next */
if (event && event.inputType === 'deleteContentBackward') {
return false
}
this.input.value = Mask.masking(this.input.value, this.mask);
};
Mask.prototype.destroy = function destroy () {
this.input.removeEventListener(this.event, this);
var id = this.input.GUID;
if (instances.has(id)) {
instances.delete(id);
Reflect.deleteProperty(this, 'GUID');
this.input.removeEventListener(this[EVENT], this);
if (instances.has(this.input[GUID])) {
instances.delete(this.input[GUID]);
}

@@ -87,0 +92,0 @@ };

{
"name": "@tadashi/mask",
"version": "1.1.1",
"version": "1.2.0",
"description": "The simple and tiny script for input mask",

@@ -23,7 +23,6 @@ "keywords": [

"scripts": {
"report": "nyc report --reporter=text-lcov | coveralls",
"pretest": "xo",
"test": "BABEL_ENV=ava ava",
"rollup": "BABEL_ENV=rollup rollup -c",
"report": "nyc report --reporter=html",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"pretest": "xo",
"test": "BABEL_ENV=ava nyc ava",
"prebuild": "npm test",

@@ -78,10 +77,9 @@ "build": "npm run rollup",

"babel-preset-es2015": "6.24.1",
"coveralls": "3.0.0",
"jsdom": "11.8.0",
"nyc": "11.6.0",
"rollup": "0.58.0",
"jsdom": "12.0.0",
"nyc": "12.0.2",
"rollup": "0.64.1",
"rollup-plugin-buble": "0.19.2",
"simulant": "0.2.2",
"xo": "0.20.3"
"xo": "0.22.0"
}
}

@@ -30,20 +30,24 @@ # Mask

```html
<!DOCTYPE html>
<html>
<head></head>
<body>
<input id="telefone" type="text" data-mask="(99) 9-9999-9999">
<script src="./app.js" type="module"></script>
</body>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>Example</title>
</head>
<body>
<input id="telefone" type="text" data-mask="(99) 9-9999-9999">
<script type="module">
import Mask from './node_modules/@tadashi/mask/src/index.mjs'
const el = document.getElementById('telefone')
const mask = new Mask(el)
</script>
</body>
</html>
```
```js
import Mask from './node_modules/@tadashi/mask/src/index.js'
const el = document.getElementById(id)
const mask = new Mask(el)
```
## License
MIT © [Thiago Lagden](http://lagden.in)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc