UNPKG

persian-mobile-input

Version:

A TypeScript React input component that converts Persian and Arabic numerals to English numerals

3 lines (2 loc) 1.39 kB
import{jsx as e}from"react/jsx-runtime";import{forwardRef as r,useState as t}from"react";var n=function(){return n=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e},n.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var o=r(function(r,o){var a=r.value,i=r.onChange,p=r.className,l=function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(t[n[o]]=e[n[o]])}return t}(r,["value","onChange","className"]),u=t(a||""),s=u[0],c=u[1],f={"۰":"0","۱":"1","۲":"2","۳":"3","۴":"4","۵":"5","۶":"6","۷":"7","۸":"8","۹":"9"},v={"٠":"0","١":"1","٢":"2","٣":"3","٤":"4","٥":"5","٦":"6","٧":"7","٨":"8","٩":"9"};return e("input",n({type:"tel",value:void 0!==a?a:s,onChange:function(e){var r=e.target.value.split("").filter(function(e){return/[۰-۹٠-٩0-9]/.test(e)}).join(""),t=r.split("").map(function(e){return f[e]||v[e]||e}).join("");void 0!==a||i||c(t),i&&(e.target.value=t,i(e))},className:p,ref:o},l))});o.displayName="PersianMobileInput";export{o as default}; //# sourceMappingURL=index.esm.js.map