UNPKG

maskfy

Version:

A Javascript library without a dependency of jQuery, Zepto, and etc ... Very simple to install and use. With only 1kb (gzip) code, it's also well accepted on mobile devices

1 lines 1.29 kB
var e={d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{Ww:()=>r,hk:()=>s,nj:()=>n});const s={Mask:"999.999.999.999",Reverse:!1,Keybind:{A:/[A-Za-z]/,9:/\d/,"?":/./},Prefix:"",Suffix:""},n=(e={})=>({mask:s.Mask,reverse:s.Reverse,prefix:s.Prefix,suffix:s.Suffix,...e,keybind:{...s.Keybind,...e.keybind}}),r=(e,t={})=>{const s=n(t),{mask:i,reverse:g,prefix:h,suffix:l,keybind:a}=s,f=String(e),p=h&&f.startsWith(h)?f.replace(new RegExp(`^${h}`),""):f,o=l&&new RegExp(`(${l})(.?)$`).test(l)?p.replace(new RegExp(`(${l})(.?)$`),"$2"):p,u=o.replace(/\s/g,"").split(""),k=i.split(""),c=[...k],x=[...u],b=[];g&&(c.reverse(),x.reverse());let y=0,d=0;if(c.forEach(((e,t)=>{const s=c[t-y],n=x[t+d],r=a[s];n&&(r?.test(s)?r?.test(n)?b.push(n):y++:(b.push(s),n!==s&&d--))})),y&&u.length>=b.length+y&&k.length===u.length&&!h&&!l){const e=o.substring(o.length-y,o.length),t=i.substring(i.length-y,i.length),s=r(e,{mask:t});b.push(s)}if(g&&b.reverse(),h&&b.length&&b.unshift(h),l&&b.length&&b.push(l),x.length+y>c.length&&g){const e=k.length-u.length;return u.join("").substring(0,u.length-e)}return b.join("")},i=t.hk,g=t.Ww,h=t.nj;export{i as MaskfyDefault,g as maskfy,h as maskfySettings};