UNPKG

primereact

Version:

PrimeReact is an open source UI library for React featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime

2 lines (1 loc) 1.59 kB
import{DomHandler as t}from"primereact/utils";function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function r(t){if(Array.isArray(t))return e(t)}function n(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function a(t,r){if(t){if("string"==typeof t)return e(t,r);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,r):void 0}}function i(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o={DEFAULT_MASKS:{pint:/[\d]/,int:/[\d\-]/,pnum:/[\d\.]/,money:/[\d\.\s,]/,num:/[\d\-\.]/,hex:/[0-9a-f]/i,email:/[a-z0-9_\.\-@]/i,alpha:/[a-z_]/i,alphanum:/[a-z0-9_]/i},getRegex:function(t){return o.DEFAULT_MASKS[t]?o.DEFAULT_MASKS[t]:t},onBeforeInput:function(e,r,n){!n&&t.isAndroid()&&this.validateKey(e,e.data,r)},onKeyPress:function(e,r,n){n||t.isAndroid()||e.ctrlKey||e.altKey||e.metaKey||this.validateKey(e,e.key,r)},onPaste:function(t,e,o){if(!o){var u,l=this.getRegex(e),f=t.clipboardData.getData("text");(u=f,r(u)||n(u)||a(u)||i()).forEach((function(e){if(!l.test(e))return t.preventDefault(),!1}))}},validateKey:function(t,e,r){null!=e&&(e.length<=2&&(this.getRegex(r).test(e)||t.preventDefault()))},validate:function(t,e){var r=t.target.value,n=!0,a=this.getRegex(e);return r&&!a.test(r)&&(n=!1),n}};export{o as KeyFilter};