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 2.1.4 to 2.1.5

6

dist/maska.js

@@ -1,2 +0,2 @@

/*! maska v2.1.4 | (c) Alexander Shabunevich | Released under the MIT license */
/*! maska v2.1.5 | (c) Alexander Shabunevich | Released under the MIT license */
var b = Object.defineProperty;

@@ -158,3 +158,3 @@ var L = (n, t, s) => t in n ? b(n, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[t] = s;

const e = this.items.get(t);
this.options.preProcess != null && (s = this.options.preProcess(s)), s = e.masked(s), this.options.postProcess != null && (s = this.options.postProcess(s)), t.value = s, t.dataset.maskaValue = s;
this.options.preProcess != null && (s = this.options.preProcess(s)), s = e.masked(s);
const a = {

@@ -165,3 +165,3 @@ masked: e.masked(s),

};
this.options.onMaska != null && (Array.isArray(this.options.onMaska) ? this.options.onMaska.forEach((i) => i(a)) : this.options.onMaska(a)), t.dispatchEvent(new CustomEvent("maska", { detail: a })), t.dispatchEvent(new CustomEvent("input", { detail: a }));
this.options.postProcess != null && (s = this.options.postProcess(s)), t.value = s, t.dataset.maskaValue = s, this.options.onMaska != null && (Array.isArray(this.options.onMaska) ? this.options.onMaska.forEach((i) => i(a)) : this.options.onMaska(a)), t.dispatchEvent(new CustomEvent("maska", { detail: a })), t.dispatchEvent(new CustomEvent("input", { detail: a }));
}

@@ -168,0 +168,0 @@ }

@@ -1,2 +0,2 @@

/*! maska v2.1.4 | (c) Alexander Shabunevich | Released under the MIT license */
(function(l,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(l=typeof globalThis<"u"?globalThis:l||self,c(l.Maska={}))})(this,function(l){"use strict";var I=Object.defineProperty;var x=(l,c,d)=>c in l?I(l,c,{enumerable:!0,configurable:!0,writable:!0,value:d}):l[c]=d;var g=(l,c,d)=>(x(l,typeof c!="symbol"?c+"":c,d),d);const c={"#":{pattern:/[0-9]/},"@":{pattern:/[a-zA-Z]/},"*":{pattern:/[a-zA-Z0-9]/}};class d{constructor(t={}){g(this,"opts",{});g(this,"memo",new Map);var e;const s={...t};if(s.tokens!=null){s.tokens=s.tokensReplace?{...s.tokens}:{...c,...s.tokens};for(const a of Object.values(s.tokens))typeof a.pattern=="string"&&(a.pattern=new RegExp(a.pattern))}else s.tokens=c;Array.isArray(s.mask)&&(s.mask.length>1?s.mask.sort((a,i)=>a.length-i.length):s.mask=(e=s.mask[0])!=null?e:""),s.mask===""&&(s.mask=null),this.opts=s}masked(t){return this.process(t,this.findMask(t))}unmasked(t){return this.process(t,this.findMask(t),!1)}isEager(){return this.opts.eager===!0}isReversed(){return this.opts.reversed===!0}completed(t){const s=this.findMask(t);if(this.opts.mask==null||s==null)return!1;const e=this.process(t,s).length;return typeof this.opts.mask=="string"?e>=this.opts.mask.length:typeof this.opts.mask=="function"?e>=s.length:this.opts.mask.filter(a=>e>=a.length).length===this.opts.mask.length}findMask(t){var a,i;const s=this.opts.mask;if(s==null)return null;if(typeof s=="string")return s;if(typeof s=="function")return s(t);const e=this.process(t,(a=s.slice(-1).pop())!=null?a:"",!1);return(i=s.find(f=>this.process(t,f,!1).length>=e.length))!=null?i:""}escapeMask(t){const s=[],e=[];return t.split("").forEach((a,i)=>{a==="!"&&t[i-1]!=="!"?e.push(i-e.length):s.push(a)}),{mask:s.join(""),escaped:e}}process(t,s,e=!0){var C;if(s==null)return t;const a=`value=${t},mask=${s},masked=${e?1:0}`;if(this.memo.has(a))return this.memo.get(a);const{mask:i,escaped:f}=this.escapeMask(s),h=[],u=this.opts.tokens!=null?this.opts.tokens:{},r=this.isReversed()?-1:1,E=this.isReversed()?"unshift":"push",y=this.isReversed()?0:i.length-1,L=this.isReversed()?()=>o>-1&&p>-1:()=>o<i.length&&p<t.length,J=m=>!this.isReversed()&&m<=y||this.isReversed()&&m>=y;let R,M=-1,o=this.isReversed()?i.length-1:0,p=this.isReversed()?t.length-1:0;for(;L();){const m=i.charAt(o),k=u[m],v=(k==null?void 0:k.transform)!=null?k.transform(t.charAt(p)):t.charAt(p);if(!f.includes(o)&&k!=null){if(v.match(k.pattern)!=null)h[E](v),k.repeated?(M===-1?M=o:o===y&&o!==M&&(o=M-r),y===M&&(o-=r)):k.multiple&&(o-=r),o+=r;else if(k.multiple){const N=((C=h[p-r])==null?void 0:C.match(k.pattern))!=null,P=i.charAt(o+r);N&&P!==""&&u[P]==null?(o+=r,p-=r):h[E]("")}else v===R?R=void 0:k.optional&&(o+=r,p-=r);p+=r}else e&&!this.isEager()&&h[E](m),v===m&&!this.isEager()?p+=r:R=m,this.isEager()||(o+=r);if(this.isEager())for(;J(o)&&(u[i.charAt(o)]==null||f.includes(o));)e?h[E](i.charAt(o)):i.charAt(o)===t.charAt(p)&&(p+=r),o+=r}return this.memo.set(a,h.join("")),this.memo.get(a)}}const T=n=>JSON.parse(n.replaceAll("'",'"')),w=(n,t={})=>{const s={...t};return n.dataset.maska!=null&&n.dataset.maska!==""&&(s.mask=V(n.dataset.maska)),n.dataset.maskaEager!=null&&(s.eager=A(n.dataset.maskaEager)),n.dataset.maskaReversed!=null&&(s.reversed=A(n.dataset.maskaReversed)),n.dataset.maskaTokensReplace!=null&&(s.tokensReplace=A(n.dataset.maskaTokensReplace)),n.dataset.maskaTokens!=null&&(s.tokens=W(n.dataset.maskaTokens)),s},A=n=>n!==""?Boolean(JSON.parse(n)):!0,V=n=>n.startsWith("[")&&n.endsWith("]")?T(n):n,W=n=>{if(n.startsWith("{")&&n.endsWith("}"))return T(n);const t={};return n.split("|").forEach(s=>{const e=s.split(":");t[e[0]]={pattern:new RegExp(e[1]),optional:e[2]==="optional",multiple:e[2]==="multiple",repeated:e[2]==="repeated"}}),t};class O{constructor(t,s={}){g(this,"items",new Map);g(this,"beforeinputEvent",t=>{const s=t.target,e=this.items.get(s);e.isEager()&&"inputType"in t&&t.inputType.startsWith("delete")&&e.unmasked(s.value).length<=1&&this.setMaskedValue(s,"")});g(this,"inputEvent",t=>{if(t instanceof CustomEvent&&t.type==="input"&&t.detail!=null&&typeof t.detail=="object"&&"masked"in t.detail)return;const s=t.target,e=this.items.get(s),a=s.value,i=s.selectionStart,f=s.selectionEnd;let h=a;if(e.isEager()){const u=e.unmasked(a),r=e.masked(u);u===""&&"data"in t&&t.data!=null?h=t.data:(r.startsWith(a)||e.completed(u))&&(h=u)}if(this.setMaskedValue(s,h),"inputType"in t&&(t.inputType.startsWith("delete")||i!=null&&i<a.length))try{s.setSelectionRange(i,f)}catch{}});this.options=s,typeof t=="string"?this.init(Array.from(document.querySelectorAll(t)),this.getMaskOpts(s)):this.init("length"in t?Array.from(t):[t],this.getMaskOpts(s))}destroy(){for(const t of this.items.keys())t.removeEventListener("input",this.inputEvent),t.removeEventListener("beforeinput",this.beforeinputEvent);this.items.clear()}needUpdate(t,s){const e=this.items.get(t),a=new d(w(t,this.getMaskOpts(s)));return JSON.stringify(e.opts)!==JSON.stringify(a.opts)}getMaskOpts(t){const{onMaska:s,preProcess:e,postProcess:a,...i}=t;return i}init(t,s){for(const e of t){const a=new d(w(e,s));this.items.set(e,a),e.value!==""&&this.setMaskedValue(e,e.value),e.addEventListener("input",this.inputEvent),e.addEventListener("beforeinput",this.beforeinputEvent)}}setMaskedValue(t,s){const e=this.items.get(t);this.options.preProcess!=null&&(s=this.options.preProcess(s)),s=e.masked(s),this.options.postProcess!=null&&(s=this.options.postProcess(s)),t.value=s,t.dataset.maskaValue=s;const a={masked:e.masked(s),unmasked:e.unmasked(s),completed:e.completed(s)};this.options.onMaska!=null&&(Array.isArray(this.options.onMaska)?this.options.onMaska.forEach(i=>i(a)):this.options.onMaska(a)),t.dispatchEvent(new CustomEvent("maska",{detail:a})),t.dispatchEvent(new CustomEvent("input",{detail:a}))}}const S=new WeakMap,b=n=>{const t=n.dataset.maskaValue;(t==null&&n.value!==""||t!=null&&t!==n.value)&&n.dispatchEvent(new CustomEvent("input"))},j=(n,t)=>{const s=n instanceof HTMLInputElement?n:n.querySelector("input"),e={...t.arg};if(s==null)return;const a=S.get(s);if(a!=null){if(b(s),!a.needUpdate(s,e))return;a.destroy()}if(t.value!=null){const i=t.value,f=h=>{i.masked=h.masked,i.unmasked=h.unmasked,i.completed=h.completed};e.onMaska=e.onMaska==null?f:Array.isArray(e.onMaska)?[...e.onMaska,f]:[e.onMaska,f]}S.set(s,new O(s,e)),setTimeout(()=>{b(s)})};l.Mask=d,l.MaskInput=O,l.tokens=c,l.vMaska=j,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
/*! maska v2.1.5 | (c) Alexander Shabunevich | Released under the MIT license */
(function(l,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(l=typeof globalThis<"u"?globalThis:l||self,c(l.Maska={}))})(this,function(l){"use strict";var I=Object.defineProperty;var x=(l,c,d)=>c in l?I(l,c,{enumerable:!0,configurable:!0,writable:!0,value:d}):l[c]=d;var g=(l,c,d)=>(x(l,typeof c!="symbol"?c+"":c,d),d);const c={"#":{pattern:/[0-9]/},"@":{pattern:/[a-zA-Z]/},"*":{pattern:/[a-zA-Z0-9]/}};class d{constructor(t={}){g(this,"opts",{});g(this,"memo",new Map);var e;const s={...t};if(s.tokens!=null){s.tokens=s.tokensReplace?{...s.tokens}:{...c,...s.tokens};for(const a of Object.values(s.tokens))typeof a.pattern=="string"&&(a.pattern=new RegExp(a.pattern))}else s.tokens=c;Array.isArray(s.mask)&&(s.mask.length>1?s.mask.sort((a,i)=>a.length-i.length):s.mask=(e=s.mask[0])!=null?e:""),s.mask===""&&(s.mask=null),this.opts=s}masked(t){return this.process(t,this.findMask(t))}unmasked(t){return this.process(t,this.findMask(t),!1)}isEager(){return this.opts.eager===!0}isReversed(){return this.opts.reversed===!0}completed(t){const s=this.findMask(t);if(this.opts.mask==null||s==null)return!1;const e=this.process(t,s).length;return typeof this.opts.mask=="string"?e>=this.opts.mask.length:typeof this.opts.mask=="function"?e>=s.length:this.opts.mask.filter(a=>e>=a.length).length===this.opts.mask.length}findMask(t){var a,i;const s=this.opts.mask;if(s==null)return null;if(typeof s=="string")return s;if(typeof s=="function")return s(t);const e=this.process(t,(a=s.slice(-1).pop())!=null?a:"",!1);return(i=s.find(f=>this.process(t,f,!1).length>=e.length))!=null?i:""}escapeMask(t){const s=[],e=[];return t.split("").forEach((a,i)=>{a==="!"&&t[i-1]!=="!"?e.push(i-e.length):s.push(a)}),{mask:s.join(""),escaped:e}}process(t,s,e=!0){var C;if(s==null)return t;const a=`value=${t},mask=${s},masked=${e?1:0}`;if(this.memo.has(a))return this.memo.get(a);const{mask:i,escaped:f}=this.escapeMask(s),h=[],u=this.opts.tokens!=null?this.opts.tokens:{},r=this.isReversed()?-1:1,E=this.isReversed()?"unshift":"push",y=this.isReversed()?0:i.length-1,L=this.isReversed()?()=>o>-1&&p>-1:()=>o<i.length&&p<t.length,J=m=>!this.isReversed()&&m<=y||this.isReversed()&&m>=y;let R,M=-1,o=this.isReversed()?i.length-1:0,p=this.isReversed()?t.length-1:0;for(;L();){const m=i.charAt(o),k=u[m],v=(k==null?void 0:k.transform)!=null?k.transform(t.charAt(p)):t.charAt(p);if(!f.includes(o)&&k!=null){if(v.match(k.pattern)!=null)h[E](v),k.repeated?(M===-1?M=o:o===y&&o!==M&&(o=M-r),y===M&&(o-=r)):k.multiple&&(o-=r),o+=r;else if(k.multiple){const N=((C=h[p-r])==null?void 0:C.match(k.pattern))!=null,P=i.charAt(o+r);N&&P!==""&&u[P]==null?(o+=r,p-=r):h[E]("")}else v===R?R=void 0:k.optional&&(o+=r,p-=r);p+=r}else e&&!this.isEager()&&h[E](m),v===m&&!this.isEager()?p+=r:R=m,this.isEager()||(o+=r);if(this.isEager())for(;J(o)&&(u[i.charAt(o)]==null||f.includes(o));)e?h[E](i.charAt(o)):i.charAt(o)===t.charAt(p)&&(p+=r),o+=r}return this.memo.set(a,h.join("")),this.memo.get(a)}}const T=n=>JSON.parse(n.replaceAll("'",'"')),w=(n,t={})=>{const s={...t};return n.dataset.maska!=null&&n.dataset.maska!==""&&(s.mask=V(n.dataset.maska)),n.dataset.maskaEager!=null&&(s.eager=A(n.dataset.maskaEager)),n.dataset.maskaReversed!=null&&(s.reversed=A(n.dataset.maskaReversed)),n.dataset.maskaTokensReplace!=null&&(s.tokensReplace=A(n.dataset.maskaTokensReplace)),n.dataset.maskaTokens!=null&&(s.tokens=W(n.dataset.maskaTokens)),s},A=n=>n!==""?Boolean(JSON.parse(n)):!0,V=n=>n.startsWith("[")&&n.endsWith("]")?T(n):n,W=n=>{if(n.startsWith("{")&&n.endsWith("}"))return T(n);const t={};return n.split("|").forEach(s=>{const e=s.split(":");t[e[0]]={pattern:new RegExp(e[1]),optional:e[2]==="optional",multiple:e[2]==="multiple",repeated:e[2]==="repeated"}}),t};class O{constructor(t,s={}){g(this,"items",new Map);g(this,"beforeinputEvent",t=>{const s=t.target,e=this.items.get(s);e.isEager()&&"inputType"in t&&t.inputType.startsWith("delete")&&e.unmasked(s.value).length<=1&&this.setMaskedValue(s,"")});g(this,"inputEvent",t=>{if(t instanceof CustomEvent&&t.type==="input"&&t.detail!=null&&typeof t.detail=="object"&&"masked"in t.detail)return;const s=t.target,e=this.items.get(s),a=s.value,i=s.selectionStart,f=s.selectionEnd;let h=a;if(e.isEager()){const u=e.unmasked(a),r=e.masked(u);u===""&&"data"in t&&t.data!=null?h=t.data:(r.startsWith(a)||e.completed(u))&&(h=u)}if(this.setMaskedValue(s,h),"inputType"in t&&(t.inputType.startsWith("delete")||i!=null&&i<a.length))try{s.setSelectionRange(i,f)}catch{}});this.options=s,typeof t=="string"?this.init(Array.from(document.querySelectorAll(t)),this.getMaskOpts(s)):this.init("length"in t?Array.from(t):[t],this.getMaskOpts(s))}destroy(){for(const t of this.items.keys())t.removeEventListener("input",this.inputEvent),t.removeEventListener("beforeinput",this.beforeinputEvent);this.items.clear()}needUpdate(t,s){const e=this.items.get(t),a=new d(w(t,this.getMaskOpts(s)));return JSON.stringify(e.opts)!==JSON.stringify(a.opts)}getMaskOpts(t){const{onMaska:s,preProcess:e,postProcess:a,...i}=t;return i}init(t,s){for(const e of t){const a=new d(w(e,s));this.items.set(e,a),e.value!==""&&this.setMaskedValue(e,e.value),e.addEventListener("input",this.inputEvent),e.addEventListener("beforeinput",this.beforeinputEvent)}}setMaskedValue(t,s){const e=this.items.get(t);this.options.preProcess!=null&&(s=this.options.preProcess(s)),s=e.masked(s);const a={masked:e.masked(s),unmasked:e.unmasked(s),completed:e.completed(s)};this.options.postProcess!=null&&(s=this.options.postProcess(s)),t.value=s,t.dataset.maskaValue=s,this.options.onMaska!=null&&(Array.isArray(this.options.onMaska)?this.options.onMaska.forEach(i=>i(a)):this.options.onMaska(a)),t.dispatchEvent(new CustomEvent("maska",{detail:a})),t.dispatchEvent(new CustomEvent("input",{detail:a}))}}const S=new WeakMap,b=n=>{const t=n.dataset.maskaValue;(t==null&&n.value!==""||t!=null&&t!==n.value)&&n.dispatchEvent(new CustomEvent("input"))},j=(n,t)=>{const s=n instanceof HTMLInputElement?n:n.querySelector("input"),e={...t.arg};if(s==null)return;const a=S.get(s);if(a!=null){if(b(s),!a.needUpdate(s,e))return;a.destroy()}if(t.value!=null){const i=t.value,f=h=>{i.masked=h.masked,i.unmasked=h.unmasked,i.completed=h.completed};e.onMaska=e.onMaska==null?f:Array.isArray(e.onMaska)?[...e.onMaska,f]:[e.onMaska,f]}S.set(s,new O(s,e)),setTimeout(()=>{b(s)})};l.Mask=d,l.MaskInput=O,l.tokens=c,l.vMaska=j,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
{
"name": "maska",
"version": "2.1.4",
"version": "2.1.5",
"description": "Simple zero-dependency input mask for Vue 2/3 or Vanilla JS",

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

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