Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

maska

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

maska - npm Package Compare versions

Comparing version 1.1.6 to 1.2.0

4

dist/es6/maska.esm.js
/*!
* maska v1.1.6
* maska v1.2.0
* (c) 2019-2020 Alexander Shabunevich
* Released under the MIT License.
*/
function t(t,a,s,r=!0){return e(a).length>1?function(t){const a=e(t).sort((t,e)=>t.length-e.length);return function(t,e,s,r=!0){let o=0;for(;o<a.length;){const e=a[o];o++;const i=a[o];if(!(i&&n(t,i,s,!0).length>e.length))return n(t,e,s,r)}return""}}(a)(t,a,s,r):n(t,a,s,r)}function e(t){try{return JSON.parse(t)}catch{return[t]}}function n(t,e,n,s=!0){let r=0,o=0,i="",u="";for(;r<e.length&&o<t.length;){let u=e[r];const l=t[o],c=n[u];if(c&&c.pattern)c.pattern.test(l)&&(i+=a(l,c),r++),o++;else if(c&&c.repeat){const t=n[e[r-1]];t&&!t.pattern.test(l)?r++:r--}else c&&c.escape&&(r++,u=e[r]),s&&(i+=u),l===u&&o++,r++}for(;s&&r<e.length;){const t=e[r];if(n[t]){u="";break}u+=t,r++}return i+u}function a(t,e){return e.uppercase?t.toLocaleUpperCase():e.lowercase?t.toLocaleLowerCase():t}var s={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:!0},a:{pattern:/[a-zA-Z]/,lowercase:!0},"!":{escape:!0},"*":{repeat:!0}};function r(t){return t instanceof HTMLInputElement?t:t.querySelector("input")||t}function o(t){return"[object String]"===Object.prototype.toString.call(t)}class i{constructor(t,e={}){if(!t)throw new Error("Maska: no element for mask");if(e.tokens)for(const t in e.tokens)e.tokens[t]={...e.tokens[t]},e.tokens[t].pattern&&o(e.tokens[t].pattern)&&(e.tokens[t].pattern=new RegExp(e.tokens[t].pattern));this._opts={mask:e.mask,tokens:{...s,...e.tokens}},this._el=o(t)?document.querySelectorAll(t):t.length?t:[t],this.init()}init(){for(let t=0;t<this._el.length;t++){const e=r(this._el[t]);!this._opts.mask||e.dataset.mask&&e.dataset.mask===this._opts.mask||(e.dataset.mask=this._opts.mask),this.updateValue(e),e.dataset.maskInited||(e.dataset.maskInited=!0,e.addEventListener("input",t=>this.updateValue(t.target)),e.addEventListener("beforeinput",t=>this.beforeInput(t)))}}destroy(){for(let t=0;t<this._el.length;t++){const e=r(this._el[t]);e.removeEventListener("input",t=>this.updateValue(t.target)),e.removeEventListener("beforeinput",t=>this.beforeInput(t)),delete e.dataset.mask,delete e.dataset.maskInited}}updateValue(e){const n=e.type.match(/^number$/i)&&e.validity.badInput;if(!e.value&&!n||!e.dataset.mask)return;const a=e.selectionEnd,s=e.value,r=s[a-1];e.value=t(e.value,e.dataset.mask,this._opts.tokens),function(t,e,n){for(;e&&e<t.value.length&&t.value.charAt(e-1)!==n;)e++;(t.type&&t.type.match(/^(text|search|password|tel|url)$/i)||!t.type)&&t===document.activeElement&&(t.setSelectionRange(e,e),setTimeout((function(){t.setSelectionRange(e,e)}),0))}(e,a,r),e.value!==s&&e.dispatchEvent(function(t){const e=document.createEvent("Event");return e.initEvent(t,!0,!0),e}("input"))}beforeInput(t){t.target.type.match(/^number$/i)&&t.data&&isNaN(t.target.value+t.data)&&t.preventDefault()}}function u(t,e){if(e.value)return e.value&&function(t){return!(o(t.value)&&t.value===t.oldValue||Array.isArray(t.value)&&JSON.stringify(t.value)===JSON.stringify(t.oldValue)||t.value&&t.value.mask&&t.oldValue&&t.oldValue.mask&&t.value.mask===t.oldValue.mask)}(e)?new i(t,function(t){const e={};return t.mask?(e.mask=Array.isArray(t.mask)?JSON.stringify(t.mask):t.mask,e.tokens=t.tokens?{...t.tokens}:{}):e.mask=Array.isArray(t)?JSON.stringify(t):t,e}(e.value)):void 0}function l(t){t.directive("maska",u)}function c(t,e){return new i(t,e)}"undefined"!=typeof window&&window.Vue&&window.Vue.use(l);export default l;export{c as create,t as mask,u as maska,s as tokens};
function t(t,a,s,r=!0){return e(a).length>1?function(t){const a=e(t).sort((t,e)=>t.length-e.length);return function(t,e,s,r=!0){let o=0;for(;o<a.length;){const e=a[o];o++;const u=a[o];if(!(u&&n(t,u,s,!0).length>e.length))return n(t,e,s,r)}return""}}(a)(t,a,s,r):n(t,a,s,r)}function e(t){try{return JSON.parse(t)}catch{return[t]}}function n(t,e,n,s=!0){let r=0,o=0,u="",i="";for(;r<e.length&&o<t.length;){let i=e[r];const l=t[o],c=n[i];if(c&&c.pattern)c.pattern.test(l)&&(u+=a(l,c),r++,s&&e[r]&&!n[e[r]]&&(u+=e[r],r++)),o++;else if(c&&c.repeat){const t=n[e[r-1]];t&&!t.pattern.test(l)?r++:r--}else c&&c.escape&&(r++,i=e[r]),s&&(u+=i),l===i&&o++,r++}for(;s&&r<e.length;){const t=e[r];if(n[t]){i="";break}i+=t,r++}return u+i}function a(t,e){return e.uppercase?t.toLocaleUpperCase():e.lowercase?t.toLocaleLowerCase():t}var s={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:!0},a:{pattern:/[a-zA-Z]/,lowercase:!0},"!":{escape:!0},"*":{repeat:!0}};function r(t){return t instanceof HTMLInputElement?t:t.querySelector("input")||t}function o(t){return"[object String]"===Object.prototype.toString.call(t)}class u{constructor(t,e={}){if(!t)throw new Error("Maska: no element for mask");if(e.tokens)for(const t in e.tokens)e.tokens[t]={...e.tokens[t]},e.tokens[t].pattern&&o(e.tokens[t].pattern)&&(e.tokens[t].pattern=new RegExp(e.tokens[t].pattern));this._opts={mask:e.mask,tokens:{...s,...e.tokens}},this._el=o(t)?document.querySelectorAll(t):t.length?t:[t],this.init()}init(){for(let t=0;t<this._el.length;t++){const e=r(this._el[t]);!this._opts.mask||e.dataset.mask&&e.dataset.mask===this._opts.mask||(e.dataset.mask=this._opts.mask),this.updateValue(e),e.dataset.maskInited||(e.dataset.maskInited=!0,e.addEventListener("input",t=>this.updateValue(t.target,t)),e.addEventListener("beforeinput",t=>this.beforeInput(t)))}}destroy(){for(let t=0;t<this._el.length;t++){const e=r(this._el[t]);e.removeEventListener("input",t=>this.updateValue(t.target,t)),e.removeEventListener("beforeinput",t=>this.beforeInput(t)),delete e.dataset.mask,delete e.dataset.maskInited}}updateValue(e,n){const a=e.type.match(/^number$/i)&&e.validity.badInput;if(!e.value&&!a||!e.dataset.mask)return;let s=e.selectionEnd;const r=e.value,o=r[s-1];e.value=t(e.value,e.dataset.mask,this._opts.tokens),n&&"insertText"===n.inputType&&s===r.length&&(s=e.value.length),function(t,e,n){for(;e&&e<t.value.length&&t.value.charAt(e-1)!==n;)e++;(t.type&&t.type.match(/^(text|search|password|tel|url)$/i)||!t.type)&&t===document.activeElement&&(t.setSelectionRange(e,e),setTimeout((function(){t.setSelectionRange(e,e)}),0))}(e,s,o),e.value!==r&&e.dispatchEvent(function(t,e=null){const n=document.createEvent("Event");return n.initEvent(t,!0,!0),e&&(n.inputType=e),n}("input",n&&n.inputType||null))}beforeInput(t){t.target.type.match(/^number$/i)&&t.data&&isNaN(t.target.value+t.data)&&t.preventDefault()}}function i(t,e){if(e.value)return e.value&&function(t){return!(o(t.value)&&t.value===t.oldValue||Array.isArray(t.value)&&JSON.stringify(t.value)===JSON.stringify(t.oldValue)||t.value&&t.value.mask&&t.oldValue&&t.oldValue.mask&&t.value.mask===t.oldValue.mask)}(e)?new u(t,function(t){const e={};return t.mask?(e.mask=Array.isArray(t.mask)?JSON.stringify(t.mask):t.mask,e.tokens=t.tokens?{...t.tokens}:{}):e.mask=Array.isArray(t)?JSON.stringify(t):t,e}(e.value)):void 0}function l(t){t.directive("maska",i)}function c(t,e){return new u(t,e)}"undefined"!=typeof window&&window.Vue&&window.Vue.use(l);export default l;export{c as create,t as mask,i as maska,s as tokens};
/*!
* maska v1.1.6
* maska v1.2.0
* (c) 2019-2020 Alexander Shabunevich
* Released under the MIT License.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Maska={})}(this,(function(e){"use strict";function t(e,t,s,r=!0){return n(t).length>1?function(e){const t=n(e).sort((e,t)=>e.length-t.length);return function(e,n,s,r=!0){let o=0;for(;o<t.length;){const n=t[o];o++;const i=t[o];if(!(i&&a(e,i,s,!0).length>n.length))return a(e,n,s,r)}return""}}(t)(e,t,s,r):a(e,t,s,r)}function n(e){try{return JSON.parse(e)}catch{return[e]}}function a(e,t,n,a=!0){let r=0,o=0,i="",u="";for(;r<t.length&&o<e.length;){let u=t[r];const l=e[o],c=n[u];if(c&&c.pattern)c.pattern.test(l)&&(i+=s(l,c),r++),o++;else if(c&&c.repeat){const e=n[t[r-1]];e&&!e.pattern.test(l)?r++:r--}else c&&c.escape&&(r++,u=t[r]),a&&(i+=u),l===u&&o++,r++}for(;a&&r<t.length;){const e=t[r];if(n[e]){u="";break}u+=e,r++}return i+u}function s(e,t){return t.uppercase?e.toLocaleUpperCase():t.lowercase?e.toLocaleLowerCase():e}var r={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:!0},a:{pattern:/[a-zA-Z]/,lowercase:!0},"!":{escape:!0},"*":{repeat:!0}};function o(e){return e instanceof HTMLInputElement?e:e.querySelector("input")||e}function i(e){return"[object String]"===Object.prototype.toString.call(e)}class u{constructor(e,t={}){if(!e)throw new Error("Maska: no element for mask");if(t.tokens)for(const e in t.tokens)t.tokens[e]={...t.tokens[e]},t.tokens[e].pattern&&i(t.tokens[e].pattern)&&(t.tokens[e].pattern=new RegExp(t.tokens[e].pattern));this._opts={mask:t.mask,tokens:{...r,...t.tokens}},this._el=i(e)?document.querySelectorAll(e):e.length?e:[e],this.init()}init(){for(let e=0;e<this._el.length;e++){const t=o(this._el[e]);!this._opts.mask||t.dataset.mask&&t.dataset.mask===this._opts.mask||(t.dataset.mask=this._opts.mask),this.updateValue(t),t.dataset.maskInited||(t.dataset.maskInited=!0,t.addEventListener("input",e=>this.updateValue(e.target)),t.addEventListener("beforeinput",e=>this.beforeInput(e)))}}destroy(){for(let e=0;e<this._el.length;e++){const t=o(this._el[e]);t.removeEventListener("input",e=>this.updateValue(e.target)),t.removeEventListener("beforeinput",e=>this.beforeInput(e)),delete t.dataset.mask,delete t.dataset.maskInited}}updateValue(e){const n=e.type.match(/^number$/i)&&e.validity.badInput;if(!e.value&&!n||!e.dataset.mask)return;const a=e.selectionEnd,s=e.value,r=s[a-1];e.value=t(e.value,e.dataset.mask,this._opts.tokens),function(e,t,n){for(;t&&t<e.value.length&&e.value.charAt(t-1)!==n;)t++;(e.type&&e.type.match(/^(text|search|password|tel|url)$/i)||!e.type)&&e===document.activeElement&&(e.setSelectionRange(t,t),setTimeout((function(){e.setSelectionRange(t,t)}),0))}(e,a,r),e.value!==s&&e.dispatchEvent(function(e){const t=document.createEvent("Event");return t.initEvent(e,!0,!0),t}("input"))}beforeInput(e){e.target.type.match(/^number$/i)&&e.data&&isNaN(e.target.value+e.data)&&e.preventDefault()}}function l(e,t){if(t.value)return t.value&&function(e){return!(i(e.value)&&e.value===e.oldValue||Array.isArray(e.value)&&JSON.stringify(e.value)===JSON.stringify(e.oldValue)||e.value&&e.value.mask&&e.oldValue&&e.oldValue.mask&&e.value.mask===e.oldValue.mask)}(t)?new u(e,function(e){const t={};return e.mask?(t.mask=Array.isArray(e.mask)?JSON.stringify(e.mask):e.mask,t.tokens=e.tokens?{...e.tokens}:{}):t.mask=Array.isArray(e)?JSON.stringify(e):e,t}(t.value)):void 0}function c(e){e.directive("maska",l)}"undefined"!=typeof window&&window.Vue&&window.Vue.use(c),e.create=function(e,t){return new u(e,t)},e.default=c,e.mask=t,e.maska=l,e.tokens=r,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Maska={})}(this,(function(e){"use strict";function t(e,t,s,r=!0){return n(t).length>1?function(e){const t=n(e).sort((e,t)=>e.length-t.length);return function(e,n,s,r=!0){let o=0;for(;o<t.length;){const n=t[o];o++;const i=t[o];if(!(i&&a(e,i,s,!0).length>n.length))return a(e,n,s,r)}return""}}(t)(e,t,s,r):a(e,t,s,r)}function n(e){try{return JSON.parse(e)}catch{return[e]}}function a(e,t,n,a=!0){let r=0,o=0,i="",u="";for(;r<t.length&&o<e.length;){let u=t[r];const l=e[o],c=n[u];if(c&&c.pattern)c.pattern.test(l)&&(i+=s(l,c),r++,a&&t[r]&&!n[t[r]]&&(i+=t[r],r++)),o++;else if(c&&c.repeat){const e=n[t[r-1]];e&&!e.pattern.test(l)?r++:r--}else c&&c.escape&&(r++,u=t[r]),a&&(i+=u),l===u&&o++,r++}for(;a&&r<t.length;){const e=t[r];if(n[e]){u="";break}u+=e,r++}return i+u}function s(e,t){return t.uppercase?e.toLocaleUpperCase():t.lowercase?e.toLocaleLowerCase():e}var r={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:!0},a:{pattern:/[a-zA-Z]/,lowercase:!0},"!":{escape:!0},"*":{repeat:!0}};function o(e){return e instanceof HTMLInputElement?e:e.querySelector("input")||e}function i(e){return"[object String]"===Object.prototype.toString.call(e)}class u{constructor(e,t={}){if(!e)throw new Error("Maska: no element for mask");if(t.tokens)for(const e in t.tokens)t.tokens[e]={...t.tokens[e]},t.tokens[e].pattern&&i(t.tokens[e].pattern)&&(t.tokens[e].pattern=new RegExp(t.tokens[e].pattern));this._opts={mask:t.mask,tokens:{...r,...t.tokens}},this._el=i(e)?document.querySelectorAll(e):e.length?e:[e],this.init()}init(){for(let e=0;e<this._el.length;e++){const t=o(this._el[e]);!this._opts.mask||t.dataset.mask&&t.dataset.mask===this._opts.mask||(t.dataset.mask=this._opts.mask),this.updateValue(t),t.dataset.maskInited||(t.dataset.maskInited=!0,t.addEventListener("input",e=>this.updateValue(e.target,e)),t.addEventListener("beforeinput",e=>this.beforeInput(e)))}}destroy(){for(let e=0;e<this._el.length;e++){const t=o(this._el[e]);t.removeEventListener("input",e=>this.updateValue(e.target,e)),t.removeEventListener("beforeinput",e=>this.beforeInput(e)),delete t.dataset.mask,delete t.dataset.maskInited}}updateValue(e,n){const a=e.type.match(/^number$/i)&&e.validity.badInput;if(!e.value&&!a||!e.dataset.mask)return;let s=e.selectionEnd;const r=e.value,o=r[s-1];e.value=t(e.value,e.dataset.mask,this._opts.tokens),n&&"insertText"===n.inputType&&s===r.length&&(s=e.value.length),function(e,t,n){for(;t&&t<e.value.length&&e.value.charAt(t-1)!==n;)t++;(e.type&&e.type.match(/^(text|search|password|tel|url)$/i)||!e.type)&&e===document.activeElement&&(e.setSelectionRange(t,t),setTimeout((function(){e.setSelectionRange(t,t)}),0))}(e,s,o),e.value!==r&&e.dispatchEvent(function(e,t=null){const n=document.createEvent("Event");return n.initEvent(e,!0,!0),t&&(n.inputType=t),n}("input",n&&n.inputType||null))}beforeInput(e){e.target.type.match(/^number$/i)&&e.data&&isNaN(e.target.value+e.data)&&e.preventDefault()}}function l(e,t){if(t.value)return t.value&&function(e){return!(i(e.value)&&e.value===e.oldValue||Array.isArray(e.value)&&JSON.stringify(e.value)===JSON.stringify(e.oldValue)||e.value&&e.value.mask&&e.oldValue&&e.oldValue.mask&&e.value.mask===e.oldValue.mask)}(t)?new u(e,function(e){const t={};return e.mask?(t.mask=Array.isArray(e.mask)?JSON.stringify(e.mask):e.mask,t.tokens=e.tokens?{...e.tokens}:{}):t.mask=Array.isArray(e)?JSON.stringify(e):e,t}(t.value)):void 0}function c(e){e.directive("maska",l)}"undefined"!=typeof window&&window.Vue&&window.Vue.use(c),e.create=function(e,t){return new u(e,t)},e.default=c,e.mask=t,e.maska=l,e.tokens=r,Object.defineProperty(e,"__esModule",{value:!0})}));
/*!
* maska v1.1.6
* maska v1.2.0
* (c) 2019-2020 Alexander Shabunevich
* Released under the MIT License.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Maska={})}(this,(function(e){"use strict";function t(e,t,s,r=!0){return n(t).length>1?function(e){const t=n(e).sort((e,t)=>e.length-t.length);return function(e,n,s,r=!0){let o=0;for(;o<t.length;){const n=t[o];o++;const i=t[o];if(!(i&&a(e,i,s,!0).length>n.length))return a(e,n,s,r)}return""}}(t)(e,t,s,r):a(e,t,s,r)}function n(e){try{return JSON.parse(e)}catch{return[e]}}function a(e,t,n,a=!0){let r=0,o=0,i="",u="";for(;r<t.length&&o<e.length;){let u=t[r];const l=e[o],c=n[u];if(c&&c.pattern)c.pattern.test(l)&&(i+=s(l,c),r++),o++;else if(c&&c.repeat){const e=n[t[r-1]];e&&!e.pattern.test(l)?r++:r--}else c&&c.escape&&(r++,u=t[r]),a&&(i+=u),l===u&&o++,r++}for(;a&&r<t.length;){const e=t[r];if(n[e]){u="";break}u+=e,r++}return i+u}function s(e,t){return t.uppercase?e.toLocaleUpperCase():t.lowercase?e.toLocaleLowerCase():e}var r={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:!0},a:{pattern:/[a-zA-Z]/,lowercase:!0},"!":{escape:!0},"*":{repeat:!0}};function o(e){return e instanceof HTMLInputElement?e:e.querySelector("input")||e}function i(e){return"[object String]"===Object.prototype.toString.call(e)}class u{constructor(e,t={}){if(!e)throw new Error("Maska: no element for mask");if(t.tokens)for(const e in t.tokens)t.tokens[e]={...t.tokens[e]},t.tokens[e].pattern&&i(t.tokens[e].pattern)&&(t.tokens[e].pattern=new RegExp(t.tokens[e].pattern));this._opts={mask:t.mask,tokens:{...r,...t.tokens}},this._el=i(e)?document.querySelectorAll(e):e.length?e:[e],this.init()}init(){for(let e=0;e<this._el.length;e++){const t=o(this._el[e]);!this._opts.mask||t.dataset.mask&&t.dataset.mask===this._opts.mask||(t.dataset.mask=this._opts.mask),this.updateValue(t),t.dataset.maskInited||(t.dataset.maskInited=!0,t.addEventListener("input",e=>this.updateValue(e.target)),t.addEventListener("beforeinput",e=>this.beforeInput(e)))}}destroy(){for(let e=0;e<this._el.length;e++){const t=o(this._el[e]);t.removeEventListener("input",e=>this.updateValue(e.target)),t.removeEventListener("beforeinput",e=>this.beforeInput(e)),delete t.dataset.mask,delete t.dataset.maskInited}}updateValue(e){const n=e.type.match(/^number$/i)&&e.validity.badInput;if(!e.value&&!n||!e.dataset.mask)return;const a=e.selectionEnd,s=e.value,r=s[a-1];e.value=t(e.value,e.dataset.mask,this._opts.tokens),function(e,t,n){for(;t&&t<e.value.length&&e.value.charAt(t-1)!==n;)t++;(e.type&&e.type.match(/^(text|search|password|tel|url)$/i)||!e.type)&&e===document.activeElement&&(e.setSelectionRange(t,t),setTimeout((function(){e.setSelectionRange(t,t)}),0))}(e,a,r),e.value!==s&&e.dispatchEvent(function(e){const t=document.createEvent("Event");return t.initEvent(e,!0,!0),t}("input"))}beforeInput(e){e.target.type.match(/^number$/i)&&e.data&&isNaN(e.target.value+e.data)&&e.preventDefault()}}function l(e,t){if(t.value)return t.value&&function(e){return!(i(e.value)&&e.value===e.oldValue||Array.isArray(e.value)&&JSON.stringify(e.value)===JSON.stringify(e.oldValue)||e.value&&e.value.mask&&e.oldValue&&e.oldValue.mask&&e.value.mask===e.oldValue.mask)}(t)?new u(e,function(e){const t={};return e.mask?(t.mask=Array.isArray(e.mask)?JSON.stringify(e.mask):e.mask,t.tokens=e.tokens?{...e.tokens}:{}):t.mask=Array.isArray(e)?JSON.stringify(e):e,t}(t.value)):void 0}function c(e){e.directive("maska",l)}"undefined"!=typeof window&&window.Vue&&window.Vue.use(c),e.create=function(e,t){return new u(e,t)},e.default=c,e.mask=t,e.maska=l,e.tokens=r,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Maska={})}(this,(function(e){"use strict";function t(e,t,s,r=!0){return n(t).length>1?function(e){const t=n(e).sort((e,t)=>e.length-t.length);return function(e,n,s,r=!0){let o=0;for(;o<t.length;){const n=t[o];o++;const i=t[o];if(!(i&&a(e,i,s,!0).length>n.length))return a(e,n,s,r)}return""}}(t)(e,t,s,r):a(e,t,s,r)}function n(e){try{return JSON.parse(e)}catch{return[e]}}function a(e,t,n,a=!0){let r=0,o=0,i="",u="";for(;r<t.length&&o<e.length;){let u=t[r];const l=e[o],c=n[u];if(c&&c.pattern)c.pattern.test(l)&&(i+=s(l,c),r++,a&&t[r]&&!n[t[r]]&&(i+=t[r],r++)),o++;else if(c&&c.repeat){const e=n[t[r-1]];e&&!e.pattern.test(l)?r++:r--}else c&&c.escape&&(r++,u=t[r]),a&&(i+=u),l===u&&o++,r++}for(;a&&r<t.length;){const e=t[r];if(n[e]){u="";break}u+=e,r++}return i+u}function s(e,t){return t.uppercase?e.toLocaleUpperCase():t.lowercase?e.toLocaleLowerCase():e}var r={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:!0},a:{pattern:/[a-zA-Z]/,lowercase:!0},"!":{escape:!0},"*":{repeat:!0}};function o(e){return e instanceof HTMLInputElement?e:e.querySelector("input")||e}function i(e){return"[object String]"===Object.prototype.toString.call(e)}class u{constructor(e,t={}){if(!e)throw new Error("Maska: no element for mask");if(t.tokens)for(const e in t.tokens)t.tokens[e]={...t.tokens[e]},t.tokens[e].pattern&&i(t.tokens[e].pattern)&&(t.tokens[e].pattern=new RegExp(t.tokens[e].pattern));this._opts={mask:t.mask,tokens:{...r,...t.tokens}},this._el=i(e)?document.querySelectorAll(e):e.length?e:[e],this.init()}init(){for(let e=0;e<this._el.length;e++){const t=o(this._el[e]);!this._opts.mask||t.dataset.mask&&t.dataset.mask===this._opts.mask||(t.dataset.mask=this._opts.mask),this.updateValue(t),t.dataset.maskInited||(t.dataset.maskInited=!0,t.addEventListener("input",e=>this.updateValue(e.target,e)),t.addEventListener("beforeinput",e=>this.beforeInput(e)))}}destroy(){for(let e=0;e<this._el.length;e++){const t=o(this._el[e]);t.removeEventListener("input",e=>this.updateValue(e.target,e)),t.removeEventListener("beforeinput",e=>this.beforeInput(e)),delete t.dataset.mask,delete t.dataset.maskInited}}updateValue(e,n){const a=e.type.match(/^number$/i)&&e.validity.badInput;if(!e.value&&!a||!e.dataset.mask)return;let s=e.selectionEnd;const r=e.value,o=r[s-1];e.value=t(e.value,e.dataset.mask,this._opts.tokens),n&&"insertText"===n.inputType&&s===r.length&&(s=e.value.length),function(e,t,n){for(;t&&t<e.value.length&&e.value.charAt(t-1)!==n;)t++;(e.type&&e.type.match(/^(text|search|password|tel|url)$/i)||!e.type)&&e===document.activeElement&&(e.setSelectionRange(t,t),setTimeout((function(){e.setSelectionRange(t,t)}),0))}(e,s,o),e.value!==r&&e.dispatchEvent(function(e,t=null){const n=document.createEvent("Event");return n.initEvent(e,!0,!0),t&&(n.inputType=t),n}("input",n&&n.inputType||null))}beforeInput(e){e.target.type.match(/^number$/i)&&e.data&&isNaN(e.target.value+e.data)&&e.preventDefault()}}function l(e,t){if(t.value)return t.value&&function(e){return!(i(e.value)&&e.value===e.oldValue||Array.isArray(e.value)&&JSON.stringify(e.value)===JSON.stringify(e.oldValue)||e.value&&e.value.mask&&e.oldValue&&e.oldValue.mask&&e.value.mask===e.oldValue.mask)}(t)?new u(e,function(e){const t={};return e.mask?(t.mask=Array.isArray(e.mask)?JSON.stringify(e.mask):e.mask,t.tokens=e.tokens?{...e.tokens}:{}):t.mask=Array.isArray(e)?JSON.stringify(e):e,t}(t.value)):void 0}function c(e){e.directive("maska",l)}"undefined"!=typeof window&&window.Vue&&window.Vue.use(c),e.create=function(e,t){return new u(e,t)},e.default=c,e.mask=t,e.maska=l,e.tokens=r,Object.defineProperty(e,"__esModule",{value:!0})}));
/*!
* maska v1.1.6
* maska v1.2.0
* (c) 2019-2020 Alexander Shabunevich
* Released under the MIT License.
*/
function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function n(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?r(Object(a),!0).forEach((function(t){n(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):r(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function o(e,t,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return i(t).length>1?u(t)(e,t,n,r):s(e,t,n,r)}function i(e){try{return JSON.parse(e)}catch(t){return[e]}}function u(e){var t=i(e).sort((function(e,t){return e.length-t.length}));return function(e,n,r){for(var a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=0;o<t.length;){var i=t[o];o++;var u=t[o];if(!(u&&s(e,u,r,!0).length>i.length))return s(e,i,r,a)}return""}}function s(e,t,n){for(var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],a=0,o=0,i="",u="";a<t.length&&o<e.length;){var s=t[a],c=e[o],f=n[s];if(f&&f.pattern)f.pattern.test(c)&&(i+=l(c,f),a++),o++;else if(f&&f.repeat){var p=n[t[a-1]];p&&!p.pattern.test(c)?a++:a--}else f&&f.escape&&(s=t[++a]),r&&(i+=s),c===s&&o++,a++}for(;r&&a<t.length;){var v=t[a];if(n[v]){u="";break}u+=v,a++}return i+u}function l(e,t){return t.uppercase?e.toLocaleUpperCase():t.lowercase?e.toLocaleLowerCase():e}var c={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:!0},a:{pattern:/[a-zA-Z]/,lowercase:!0},"!":{escape:!0},"*":{repeat:!0}};function f(e){return e instanceof HTMLInputElement?e:e.querySelector("input")||e}function p(e){return"[object String]"===Object.prototype.toString.call(e)}var v=function(){function n(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e(this,n),!t)throw new Error("Maska: no element for mask");if(r.tokens)for(var o in r.tokens)r.tokens[o]=a({},r.tokens[o]),r.tokens[o].pattern&&p(r.tokens[o].pattern)&&(r.tokens[o].pattern=new RegExp(r.tokens[o].pattern));this._opts={mask:r.mask,tokens:a(a({},c),r.tokens)},this._el=p(t)?document.querySelectorAll(t):t.length?t:[t],this.init()}var r,i,u;return r=n,(i=[{key:"init",value:function(){for(var e=this,t=0;t<this._el.length;t++){var n=f(this._el[t]);!this._opts.mask||n.dataset.mask&&n.dataset.mask===this._opts.mask||(n.dataset.mask=this._opts.mask),this.updateValue(n),n.dataset.maskInited||(n.dataset.maskInited=!0,n.addEventListener("input",(function(t){return e.updateValue(t.target)})),n.addEventListener("beforeinput",(function(t){return e.beforeInput(t)})))}}},{key:"destroy",value:function(){for(var e=this,t=0;t<this._el.length;t++){var n=f(this._el[t]);n.removeEventListener("input",(function(t){return e.updateValue(t.target)})),n.removeEventListener("beforeinput",(function(t){return e.beforeInput(t)})),delete n.dataset.mask,delete n.dataset.maskInited}}},{key:"updateValue",value:function(e){var t=e.type.match(/^number$/i)&&e.validity.badInput;if((e.value||t)&&e.dataset.mask){var n=e.selectionEnd,r=e.value,a=r[n-1];e.value=o(e.value,e.dataset.mask,this._opts.tokens),function(e,t,n){for(;t&&t<e.value.length&&e.value.charAt(t-1)!==n;)t++;(e.type&&e.type.match(/^(text|search|password|tel|url)$/i)||!e.type)&&e===document.activeElement&&(e.setSelectionRange(t,t),setTimeout((function(){e.setSelectionRange(t,t)}),0))}(e,n,a),e.value!==r&&e.dispatchEvent(function(e){var t=document.createEvent("Event");return t.initEvent(e,!0,!0),t}("input"))}}},{key:"beforeInput",value:function(e){e.target.type.match(/^number$/i)&&e.data&&isNaN(e.target.value+e.data)&&e.preventDefault()}}])&&t(r.prototype,i),u&&t(r,u),n}();function d(e,t){if(t.value)return t.value&&function(e){return!(p(e.value)&&e.value===e.oldValue||Array.isArray(e.value)&&JSON.stringify(e.value)===JSON.stringify(e.oldValue)||e.value&&e.value.mask&&e.oldValue&&e.oldValue.mask&&e.value.mask===e.oldValue.mask)}(t)?new v(e,function(e){var t={};return e.mask?(t.mask=Array.isArray(e.mask)?JSON.stringify(e.mask):e.mask,t.tokens=e.tokens?a({},e.tokens):{}):t.mask=Array.isArray(e)?JSON.stringify(e):e,t}(t.value)):void 0}function k(e){e.directive("maska",d)}function m(e,t){return new v(e,t)}"undefined"!=typeof window&&window.Vue&&window.Vue.use(k);export default k;export{m as create,o as mask,d as maska,c as tokens};
function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function n(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?r(Object(a),!0).forEach((function(t){n(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):r(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function o(e,t,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return i(t).length>1?u(t)(e,t,n,r):s(e,t,n,r)}function i(e){try{return JSON.parse(e)}catch(t){return[e]}}function u(e){var t=i(e).sort((function(e,t){return e.length-t.length}));return function(e,n,r){for(var a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=0;o<t.length;){var i=t[o];o++;var u=t[o];if(!(u&&s(e,u,r,!0).length>i.length))return s(e,i,r,a)}return""}}function s(e,t,n){for(var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],a=0,o=0,i="",u="";a<t.length&&o<e.length;){var s=t[a],c=e[o],p=n[s];if(p&&p.pattern)p.pattern.test(c)&&(i+=l(c,p),a++,r&&t[a]&&!n[t[a]]&&(i+=t[a],a++)),o++;else if(p&&p.repeat){var f=n[t[a-1]];f&&!f.pattern.test(c)?a++:a--}else p&&p.escape&&(s=t[++a]),r&&(i+=s),c===s&&o++,a++}for(;r&&a<t.length;){var v=t[a];if(n[v]){u="";break}u+=v,a++}return i+u}function l(e,t){return t.uppercase?e.toLocaleUpperCase():t.lowercase?e.toLocaleLowerCase():e}var c={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:!0},a:{pattern:/[a-zA-Z]/,lowercase:!0},"!":{escape:!0},"*":{repeat:!0}};function p(e){return e instanceof HTMLInputElement?e:e.querySelector("input")||e}function f(e){return"[object String]"===Object.prototype.toString.call(e)}var v=function(){function n(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e(this,n),!t)throw new Error("Maska: no element for mask");if(r.tokens)for(var o in r.tokens)r.tokens[o]=a({},r.tokens[o]),r.tokens[o].pattern&&f(r.tokens[o].pattern)&&(r.tokens[o].pattern=new RegExp(r.tokens[o].pattern));this._opts={mask:r.mask,tokens:a(a({},c),r.tokens)},this._el=f(t)?document.querySelectorAll(t):t.length?t:[t],this.init()}var r,i,u;return r=n,(i=[{key:"init",value:function(){for(var e=this,t=0;t<this._el.length;t++){var n=p(this._el[t]);!this._opts.mask||n.dataset.mask&&n.dataset.mask===this._opts.mask||(n.dataset.mask=this._opts.mask),this.updateValue(n),n.dataset.maskInited||(n.dataset.maskInited=!0,n.addEventListener("input",(function(t){return e.updateValue(t.target,t)})),n.addEventListener("beforeinput",(function(t){return e.beforeInput(t)})))}}},{key:"destroy",value:function(){for(var e=this,t=0;t<this._el.length;t++){var n=p(this._el[t]);n.removeEventListener("input",(function(t){return e.updateValue(t.target,t)})),n.removeEventListener("beforeinput",(function(t){return e.beforeInput(t)})),delete n.dataset.mask,delete n.dataset.maskInited}}},{key:"updateValue",value:function(e,t){var n=e.type.match(/^number$/i)&&e.validity.badInput;if((e.value||n)&&e.dataset.mask){var r=e.selectionEnd,a=e.value,i=a[r-1];e.value=o(e.value,e.dataset.mask,this._opts.tokens),t&&"insertText"===t.inputType&&r===a.length&&(r=e.value.length),function(e,t,n){for(;t&&t<e.value.length&&e.value.charAt(t-1)!==n;)t++;(e.type&&e.type.match(/^(text|search|password|tel|url)$/i)||!e.type)&&e===document.activeElement&&(e.setSelectionRange(t,t),setTimeout((function(){e.setSelectionRange(t,t)}),0))}(e,r,i),e.value!==a&&e.dispatchEvent(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=document.createEvent("Event");return n.initEvent(e,!0,!0),t&&(n.inputType=t),n}("input",t&&t.inputType||null))}}},{key:"beforeInput",value:function(e){e.target.type.match(/^number$/i)&&e.data&&isNaN(e.target.value+e.data)&&e.preventDefault()}}])&&t(r.prototype,i),u&&t(r,u),n}();function d(e,t){if(t.value)return t.value&&function(e){return!(f(e.value)&&e.value===e.oldValue||Array.isArray(e.value)&&JSON.stringify(e.value)===JSON.stringify(e.oldValue)||e.value&&e.value.mask&&e.oldValue&&e.oldValue.mask&&e.value.mask===e.oldValue.mask)}(t)?new v(e,function(e){var t={};return e.mask?(t.mask=Array.isArray(e.mask)?JSON.stringify(e.mask):e.mask,t.tokens=e.tokens?a({},e.tokens):{}):t.mask=Array.isArray(e)?JSON.stringify(e):e,t}(t.value)):void 0}function h(e){e.directive("maska",d)}function k(e,t){return new v(e,t)}"undefined"!=typeof window&&window.Vue&&window.Vue.use(h);export default h;export{k as create,o as mask,d as maska,c as tokens};
/*!
* maska v1.1.6
* maska v1.2.0
* (c) 2019-2020 Alexander Shabunevich
* Released under the MIT License.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Maska={})}(this,(function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(e,t,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return u(t).length>1?s(t)(e,t,n,r):l(e,t,n,r)}function u(e){try{return JSON.parse(e)}catch(t){return[e]}}function s(e){var t=u(e).sort((function(e,t){return e.length-t.length}));return function(e,n,r){for(var a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=0;o<t.length;){var i=t[o];o++;var u=t[o];if(!(u&&l(e,u,r,!0).length>i.length))return l(e,i,r,a)}return""}}function l(e,t,n){for(var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],a=0,o=0,i="",u="";a<t.length&&o<e.length;){var s=t[a],l=e[o],f=n[s];if(f&&f.pattern)f.pattern.test(l)&&(i+=c(l,f),a++),o++;else if(f&&f.repeat){var p=n[t[a-1]];p&&!p.pattern.test(l)?a++:a--}else f&&f.escape&&(s=t[++a]),r&&(i+=s),l===s&&o++,a++}for(;r&&a<t.length;){var v=t[a];if(n[v]){u="";break}u+=v,a++}return i+u}function c(e,t){return t.uppercase?e.toLocaleUpperCase():t.lowercase?e.toLocaleLowerCase():e}var f={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:!0},a:{pattern:/[a-zA-Z]/,lowercase:!0},"!":{escape:!0},"*":{repeat:!0}};function p(e){return e instanceof HTMLInputElement?e:e.querySelector("input")||e}function v(e){return"[object String]"===Object.prototype.toString.call(e)}var d=function(){function e(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t(this,e),!n)throw new Error("Maska: no element for mask");if(r.tokens)for(var a in r.tokens)r.tokens[a]=o({},r.tokens[a]),r.tokens[a].pattern&&v(r.tokens[a].pattern)&&(r.tokens[a].pattern=new RegExp(r.tokens[a].pattern));this._opts={mask:r.mask,tokens:o(o({},f),r.tokens)},this._el=v(n)?document.querySelectorAll(n):n.length?n:[n],this.init()}var r,a,u;return r=e,(a=[{key:"init",value:function(){for(var e=this,t=0;t<this._el.length;t++){var n=p(this._el[t]);!this._opts.mask||n.dataset.mask&&n.dataset.mask===this._opts.mask||(n.dataset.mask=this._opts.mask),this.updateValue(n),n.dataset.maskInited||(n.dataset.maskInited=!0,n.addEventListener("input",(function(t){return e.updateValue(t.target)})),n.addEventListener("beforeinput",(function(t){return e.beforeInput(t)})))}}},{key:"destroy",value:function(){for(var e=this,t=0;t<this._el.length;t++){var n=p(this._el[t]);n.removeEventListener("input",(function(t){return e.updateValue(t.target)})),n.removeEventListener("beforeinput",(function(t){return e.beforeInput(t)})),delete n.dataset.mask,delete n.dataset.maskInited}}},{key:"updateValue",value:function(e){var t=e.type.match(/^number$/i)&&e.validity.badInput;if((e.value||t)&&e.dataset.mask){var n=e.selectionEnd,r=e.value,a=r[n-1];e.value=i(e.value,e.dataset.mask,this._opts.tokens),function(e,t,n){for(;t&&t<e.value.length&&e.value.charAt(t-1)!==n;)t++;(e.type&&e.type.match(/^(text|search|password|tel|url)$/i)||!e.type)&&e===document.activeElement&&(e.setSelectionRange(t,t),setTimeout((function(){e.setSelectionRange(t,t)}),0))}(e,n,a),e.value!==r&&e.dispatchEvent(function(e){var t=document.createEvent("Event");return t.initEvent(e,!0,!0),t}("input"))}}},{key:"beforeInput",value:function(e){e.target.type.match(/^number$/i)&&e.data&&isNaN(e.target.value+e.data)&&e.preventDefault()}}])&&n(r.prototype,a),u&&n(r,u),e}();function k(e,t){if(t.value)return t.value&&function(e){return!(v(e.value)&&e.value===e.oldValue||Array.isArray(e.value)&&JSON.stringify(e.value)===JSON.stringify(e.oldValue)||e.value&&e.value.mask&&e.oldValue&&e.oldValue.mask&&e.value.mask===e.oldValue.mask)}(t)?new d(e,function(e){var t={};return e.mask?(t.mask=Array.isArray(e.mask)?JSON.stringify(e.mask):e.mask,t.tokens=e.tokens?o({},e.tokens):{}):t.mask=Array.isArray(e)?JSON.stringify(e):e,t}(t.value)):void 0}function m(e){e.directive("maska",k)}"undefined"!=typeof window&&window.Vue&&window.Vue.use(m),e.create=function(e,t){return new d(e,t)},e.default=m,e.mask=i,e.maska=k,e.tokens=f,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Maska={})}(this,(function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(e,t,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return u(t).length>1?s(t)(e,t,n,r):l(e,t,n,r)}function u(e){try{return JSON.parse(e)}catch(t){return[e]}}function s(e){var t=u(e).sort((function(e,t){return e.length-t.length}));return function(e,n,r){for(var a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=0;o<t.length;){var i=t[o];o++;var u=t[o];if(!(u&&l(e,u,r,!0).length>i.length))return l(e,i,r,a)}return""}}function l(e,t,n){for(var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],a=0,o=0,i="",u="";a<t.length&&o<e.length;){var s=t[a],l=e[o],f=n[s];if(f&&f.pattern)f.pattern.test(l)&&(i+=c(l,f),a++,r&&t[a]&&!n[t[a]]&&(i+=t[a],a++)),o++;else if(f&&f.repeat){var p=n[t[a-1]];p&&!p.pattern.test(l)?a++:a--}else f&&f.escape&&(s=t[++a]),r&&(i+=s),l===s&&o++,a++}for(;r&&a<t.length;){var v=t[a];if(n[v]){u="";break}u+=v,a++}return i+u}function c(e,t){return t.uppercase?e.toLocaleUpperCase():t.lowercase?e.toLocaleLowerCase():e}var f={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:!0},a:{pattern:/[a-zA-Z]/,lowercase:!0},"!":{escape:!0},"*":{repeat:!0}};function p(e){return e instanceof HTMLInputElement?e:e.querySelector("input")||e}function v(e){return"[object String]"===Object.prototype.toString.call(e)}var d=function(){function e(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t(this,e),!n)throw new Error("Maska: no element for mask");if(r.tokens)for(var a in r.tokens)r.tokens[a]=o({},r.tokens[a]),r.tokens[a].pattern&&v(r.tokens[a].pattern)&&(r.tokens[a].pattern=new RegExp(r.tokens[a].pattern));this._opts={mask:r.mask,tokens:o(o({},f),r.tokens)},this._el=v(n)?document.querySelectorAll(n):n.length?n:[n],this.init()}var r,a,u;return r=e,(a=[{key:"init",value:function(){for(var e=this,t=0;t<this._el.length;t++){var n=p(this._el[t]);!this._opts.mask||n.dataset.mask&&n.dataset.mask===this._opts.mask||(n.dataset.mask=this._opts.mask),this.updateValue(n),n.dataset.maskInited||(n.dataset.maskInited=!0,n.addEventListener("input",(function(t){return e.updateValue(t.target,t)})),n.addEventListener("beforeinput",(function(t){return e.beforeInput(t)})))}}},{key:"destroy",value:function(){for(var e=this,t=0;t<this._el.length;t++){var n=p(this._el[t]);n.removeEventListener("input",(function(t){return e.updateValue(t.target,t)})),n.removeEventListener("beforeinput",(function(t){return e.beforeInput(t)})),delete n.dataset.mask,delete n.dataset.maskInited}}},{key:"updateValue",value:function(e,t){var n=e.type.match(/^number$/i)&&e.validity.badInput;if((e.value||n)&&e.dataset.mask){var r=e.selectionEnd,a=e.value,o=a[r-1];e.value=i(e.value,e.dataset.mask,this._opts.tokens),t&&"insertText"===t.inputType&&r===a.length&&(r=e.value.length),function(e,t,n){for(;t&&t<e.value.length&&e.value.charAt(t-1)!==n;)t++;(e.type&&e.type.match(/^(text|search|password|tel|url)$/i)||!e.type)&&e===document.activeElement&&(e.setSelectionRange(t,t),setTimeout((function(){e.setSelectionRange(t,t)}),0))}(e,r,o),e.value!==a&&e.dispatchEvent(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=document.createEvent("Event");return n.initEvent(e,!0,!0),t&&(n.inputType=t),n}("input",t&&t.inputType||null))}}},{key:"beforeInput",value:function(e){e.target.type.match(/^number$/i)&&e.data&&isNaN(e.target.value+e.data)&&e.preventDefault()}}])&&n(r.prototype,a),u&&n(r,u),e}();function k(e,t){if(t.value)return t.value&&function(e){return!(v(e.value)&&e.value===e.oldValue||Array.isArray(e.value)&&JSON.stringify(e.value)===JSON.stringify(e.oldValue)||e.value&&e.value.mask&&e.oldValue&&e.oldValue.mask&&e.value.mask===e.oldValue.mask)}(t)?new d(e,function(e){var t={};return e.mask?(t.mask=Array.isArray(e.mask)?JSON.stringify(e.mask):e.mask,t.tokens=e.tokens?o({},e.tokens):{}):t.mask=Array.isArray(e)?JSON.stringify(e):e,t}(t.value)):void 0}function h(e){e.directive("maska",k)}"undefined"!=typeof window&&window.Vue&&window.Vue.use(h),e.create=function(e,t){return new d(e,t)},e.default=h,e.mask=i,e.maska=k,e.tokens=f,Object.defineProperty(e,"__esModule",{value:!0})}));
/*!
* maska v1.1.6
* maska v1.2.0
* (c) 2019-2020 Alexander Shabunevich
* Released under the MIT License.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Maska={})}(this,(function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(e,t,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return u(t).length>1?s(t)(e,t,n,r):l(e,t,n,r)}function u(e){try{return JSON.parse(e)}catch(t){return[e]}}function s(e){var t=u(e).sort((function(e,t){return e.length-t.length}));return function(e,n,r){for(var a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=0;o<t.length;){var i=t[o];o++;var u=t[o];if(!(u&&l(e,u,r,!0).length>i.length))return l(e,i,r,a)}return""}}function l(e,t,n){for(var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],a=0,o=0,i="",u="";a<t.length&&o<e.length;){var s=t[a],l=e[o],f=n[s];if(f&&f.pattern)f.pattern.test(l)&&(i+=c(l,f),a++),o++;else if(f&&f.repeat){var p=n[t[a-1]];p&&!p.pattern.test(l)?a++:a--}else f&&f.escape&&(s=t[++a]),r&&(i+=s),l===s&&o++,a++}for(;r&&a<t.length;){var v=t[a];if(n[v]){u="";break}u+=v,a++}return i+u}function c(e,t){return t.uppercase?e.toLocaleUpperCase():t.lowercase?e.toLocaleLowerCase():e}var f={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:!0},a:{pattern:/[a-zA-Z]/,lowercase:!0},"!":{escape:!0},"*":{repeat:!0}};function p(e){return e instanceof HTMLInputElement?e:e.querySelector("input")||e}function v(e){return"[object String]"===Object.prototype.toString.call(e)}var d=function(){function e(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t(this,e),!n)throw new Error("Maska: no element for mask");if(r.tokens)for(var a in r.tokens)r.tokens[a]=o({},r.tokens[a]),r.tokens[a].pattern&&v(r.tokens[a].pattern)&&(r.tokens[a].pattern=new RegExp(r.tokens[a].pattern));this._opts={mask:r.mask,tokens:o(o({},f),r.tokens)},this._el=v(n)?document.querySelectorAll(n):n.length?n:[n],this.init()}var r,a,u;return r=e,(a=[{key:"init",value:function(){for(var e=this,t=0;t<this._el.length;t++){var n=p(this._el[t]);!this._opts.mask||n.dataset.mask&&n.dataset.mask===this._opts.mask||(n.dataset.mask=this._opts.mask),this.updateValue(n),n.dataset.maskInited||(n.dataset.maskInited=!0,n.addEventListener("input",(function(t){return e.updateValue(t.target)})),n.addEventListener("beforeinput",(function(t){return e.beforeInput(t)})))}}},{key:"destroy",value:function(){for(var e=this,t=0;t<this._el.length;t++){var n=p(this._el[t]);n.removeEventListener("input",(function(t){return e.updateValue(t.target)})),n.removeEventListener("beforeinput",(function(t){return e.beforeInput(t)})),delete n.dataset.mask,delete n.dataset.maskInited}}},{key:"updateValue",value:function(e){var t=e.type.match(/^number$/i)&&e.validity.badInput;if((e.value||t)&&e.dataset.mask){var n=e.selectionEnd,r=e.value,a=r[n-1];e.value=i(e.value,e.dataset.mask,this._opts.tokens),function(e,t,n){for(;t&&t<e.value.length&&e.value.charAt(t-1)!==n;)t++;(e.type&&e.type.match(/^(text|search|password|tel|url)$/i)||!e.type)&&e===document.activeElement&&(e.setSelectionRange(t,t),setTimeout((function(){e.setSelectionRange(t,t)}),0))}(e,n,a),e.value!==r&&e.dispatchEvent(function(e){var t=document.createEvent("Event");return t.initEvent(e,!0,!0),t}("input"))}}},{key:"beforeInput",value:function(e){e.target.type.match(/^number$/i)&&e.data&&isNaN(e.target.value+e.data)&&e.preventDefault()}}])&&n(r.prototype,a),u&&n(r,u),e}();function k(e,t){if(t.value)return t.value&&function(e){return!(v(e.value)&&e.value===e.oldValue||Array.isArray(e.value)&&JSON.stringify(e.value)===JSON.stringify(e.oldValue)||e.value&&e.value.mask&&e.oldValue&&e.oldValue.mask&&e.value.mask===e.oldValue.mask)}(t)?new d(e,function(e){var t={};return e.mask?(t.mask=Array.isArray(e.mask)?JSON.stringify(e.mask):e.mask,t.tokens=e.tokens?o({},e.tokens):{}):t.mask=Array.isArray(e)?JSON.stringify(e):e,t}(t.value)):void 0}function m(e){e.directive("maska",k)}"undefined"!=typeof window&&window.Vue&&window.Vue.use(m),e.create=function(e,t){return new d(e,t)},e.default=m,e.mask=i,e.maska=k,e.tokens=f,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Maska={})}(this,(function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(e,t,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return u(t).length>1?s(t)(e,t,n,r):l(e,t,n,r)}function u(e){try{return JSON.parse(e)}catch(t){return[e]}}function s(e){var t=u(e).sort((function(e,t){return e.length-t.length}));return function(e,n,r){for(var a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=0;o<t.length;){var i=t[o];o++;var u=t[o];if(!(u&&l(e,u,r,!0).length>i.length))return l(e,i,r,a)}return""}}function l(e,t,n){for(var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],a=0,o=0,i="",u="";a<t.length&&o<e.length;){var s=t[a],l=e[o],f=n[s];if(f&&f.pattern)f.pattern.test(l)&&(i+=c(l,f),a++,r&&t[a]&&!n[t[a]]&&(i+=t[a],a++)),o++;else if(f&&f.repeat){var p=n[t[a-1]];p&&!p.pattern.test(l)?a++:a--}else f&&f.escape&&(s=t[++a]),r&&(i+=s),l===s&&o++,a++}for(;r&&a<t.length;){var v=t[a];if(n[v]){u="";break}u+=v,a++}return i+u}function c(e,t){return t.uppercase?e.toLocaleUpperCase():t.lowercase?e.toLocaleLowerCase():e}var f={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:!0},a:{pattern:/[a-zA-Z]/,lowercase:!0},"!":{escape:!0},"*":{repeat:!0}};function p(e){return e instanceof HTMLInputElement?e:e.querySelector("input")||e}function v(e){return"[object String]"===Object.prototype.toString.call(e)}var d=function(){function e(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t(this,e),!n)throw new Error("Maska: no element for mask");if(r.tokens)for(var a in r.tokens)r.tokens[a]=o({},r.tokens[a]),r.tokens[a].pattern&&v(r.tokens[a].pattern)&&(r.tokens[a].pattern=new RegExp(r.tokens[a].pattern));this._opts={mask:r.mask,tokens:o(o({},f),r.tokens)},this._el=v(n)?document.querySelectorAll(n):n.length?n:[n],this.init()}var r,a,u;return r=e,(a=[{key:"init",value:function(){for(var e=this,t=0;t<this._el.length;t++){var n=p(this._el[t]);!this._opts.mask||n.dataset.mask&&n.dataset.mask===this._opts.mask||(n.dataset.mask=this._opts.mask),this.updateValue(n),n.dataset.maskInited||(n.dataset.maskInited=!0,n.addEventListener("input",(function(t){return e.updateValue(t.target,t)})),n.addEventListener("beforeinput",(function(t){return e.beforeInput(t)})))}}},{key:"destroy",value:function(){for(var e=this,t=0;t<this._el.length;t++){var n=p(this._el[t]);n.removeEventListener("input",(function(t){return e.updateValue(t.target,t)})),n.removeEventListener("beforeinput",(function(t){return e.beforeInput(t)})),delete n.dataset.mask,delete n.dataset.maskInited}}},{key:"updateValue",value:function(e,t){var n=e.type.match(/^number$/i)&&e.validity.badInput;if((e.value||n)&&e.dataset.mask){var r=e.selectionEnd,a=e.value,o=a[r-1];e.value=i(e.value,e.dataset.mask,this._opts.tokens),t&&"insertText"===t.inputType&&r===a.length&&(r=e.value.length),function(e,t,n){for(;t&&t<e.value.length&&e.value.charAt(t-1)!==n;)t++;(e.type&&e.type.match(/^(text|search|password|tel|url)$/i)||!e.type)&&e===document.activeElement&&(e.setSelectionRange(t,t),setTimeout((function(){e.setSelectionRange(t,t)}),0))}(e,r,o),e.value!==a&&e.dispatchEvent(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=document.createEvent("Event");return n.initEvent(e,!0,!0),t&&(n.inputType=t),n}("input",t&&t.inputType||null))}}},{key:"beforeInput",value:function(e){e.target.type.match(/^number$/i)&&e.data&&isNaN(e.target.value+e.data)&&e.preventDefault()}}])&&n(r.prototype,a),u&&n(r,u),e}();function k(e,t){if(t.value)return t.value&&function(e){return!(v(e.value)&&e.value===e.oldValue||Array.isArray(e.value)&&JSON.stringify(e.value)===JSON.stringify(e.oldValue)||e.value&&e.value.mask&&e.oldValue&&e.oldValue.mask&&e.value.mask===e.oldValue.mask)}(t)?new d(e,function(e){var t={};return e.mask?(t.mask=Array.isArray(e.mask)?JSON.stringify(e.mask):e.mask,t.tokens=e.tokens?o({},e.tokens):{}):t.mask=Array.isArray(e)?JSON.stringify(e):e,t}(t.value)):void 0}function h(e){e.directive("maska",k)}"undefined"!=typeof window&&window.Vue&&window.Vue.use(h),e.create=function(e,t){return new d(e,t)},e.default=h,e.mask=i,e.maska=k,e.tokens=f,Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "maska",
"version": "1.1.6",
"version": "1.2.0",
"description": "Simple zero-dependency input mask for Vue.js and vanilla JS",

@@ -5,0 +5,0 @@ "keywords": [

@@ -47,2 +47,7 @@ export default function mask (value, mask, tokens, masked = true) {

im++
// check next char
if (masked && mask[im] && !tokens[mask[im]]) {
ret += mask[im]
im++
}
}

@@ -49,0 +54,0 @@ iv++

@@ -36,3 +36,3 @@ import mask from './mask'

el.dataset.maskInited = true
el.addEventListener('input', evt => this.updateValue(evt.target))
el.addEventListener('input', evt => this.updateValue(evt.target, evt))
el.addEventListener('beforeinput', evt => this.beforeInput(evt))

@@ -46,3 +46,3 @@ }

const el = findInputElement(this._el[i])
el.removeEventListener('input', evt => this.updateValue(evt.target))
el.removeEventListener('input', evt => this.updateValue(evt.target, evt))
el.removeEventListener('beforeinput', evt => this.beforeInput(evt))

@@ -54,13 +54,16 @@ delete el.dataset.mask

updateValue (el) {
updateValue (el, evt) {
const wrongNum = el.type.match(/^number$/i) && el.validity.badInput
if ((!el.value && !wrongNum) || !el.dataset.mask) return
const position = el.selectionEnd
let position = el.selectionEnd
const oldValue = el.value
const digit = oldValue[position - 1]
el.value = mask(el.value, el.dataset.mask, this._opts.tokens)
if (evt && evt.inputType === 'insertText' && position === oldValue.length) {
position = el.value.length
}
fixInputSelection(el, position, digit)
if (el.value !== oldValue) {
el.dispatchEvent(event('input'))
el.dispatchEvent(event('input', (evt && evt.inputType) || null))
}

@@ -67,0 +70,0 @@ }

/* global HTMLInputElement */
function event (name) {
function event (name, inputType = null) {
const event = document.createEvent('Event')
event.initEvent(name, true, true)
if (inputType) {
event.inputType = inputType
}

@@ -7,0 +10,0 @@ return event

@@ -17,3 +17,3 @@ import mask from './../src/mask'

test('1 #.#', () => {
expect(mask('1', '#.#', tokens)).toBe('1')
expect(mask('1', '#.#', tokens)).toBe('1.')
})

@@ -20,0 +20,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc