UNPKG

scriptguard-library

Version:

A secure and customizable text input field library for React.

3 lines (2 loc) 782 B
import{jsx as e}from"react/jsx-runtime";import{useState as t,useRef as a,useEffect as r}from"react";var n=function(e){return e.replace(/[<>/'"\\]/g,"")},i=function(i){var o=i.value,l=void 0===o?"":o,u=i.onChange,c=i.allowedChars,v=void 0===c?/^[a-zA-Z0-9\s]*$/:c,d=i.maxLength,s=void 0===d?255:d,f=i.sanitize,p=void 0===f?n:f,m=i.placeholder,h=void 0===m?"Enter text...":m,g=i.className,x=void 0===g?"":g,C=i.id,j=t(l),z=j[0],N=j[1],b=a(null);r((function(){N(l)}),[l]);return e("input",{ref:b,type:"text",value:z,onChange:function(e){var t=e.target.value;t=t.split("").filter((function(e){return v.test(e)})).join(""),(t=p(t).slice(0,s))!==z&&(N(t),null==u||u(t))},placeholder:h,className:x,id:C,"aria-label":h})};export{i as SecureTextInput}; //# sourceMappingURL=index.esm.js.map