jb-payment-input
Version:
payment input web component
3 lines (2 loc) • 4.23 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("jb-input")):"function"==typeof define&&define.amd?define(["exports","jb-input"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).JBPaymentInput={},t.JBInput)}(this,(function(t,e){"use strict";function n(t,e,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(t):i?i.value:e.get(t)}function i(t,e,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(t,n):r?r.value=n:e.set(t,n),n}"function"==typeof SuppressedError&&SuppressedError;function r(t){if("string"!=typeof t)return"";return t.replace(/[۰-۹]/g,(function(t){return String.fromCharCode(t.charCodeAt(0)-1728)}))}const s={validator:({value:t})=>16==t.length,message:"لطفا شماره کارت را کامل وارد کنید"},a={validator:({value:t})=>26==t.length,message:"لطفا شماره شبا را کامل وارد کنید"},o={validator:/(IR[0-9]{0,2})([0-9]{0,4})([0-9]{0,4})([0-9]{0,4})([0-9]{0,4})([0-9]{0,4})([0-9]{0,2})/g,message:"لطفا شماره شبا را صحیح وارد کنید"},u=["CARD","SHABA"];var p,l,h,c,f,d,g,m,y,b,w;class C extends e.JBInputWebComponent{get paymentInputType(){return n(this,l,"f")}set paymentInputType(t){u.includes(t)&&i(this,l,t||"CARD","f")}get separatorString(){return n(this,h,"f")}set separatorString(t){i(this,h,t,"f"),i(this,c,RegExp(n(this,h,"f").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\s/g,"\\s"),"g"),"f");const e=this.standardValue(this.value,"SET_VALUE");this.elements.input.value=e.displayValue}constructor(){super(),p.add(this),l.set(this,this.getAttribute("input-type")||"CARD"),h.set(this," "),c.set(this,/\s/g),n(this,p,"m",f).call(this)}static get observedAttributes(){return[...e.JBInputWebComponent.observedAttributes,"input-type","separator"]}attributeChangedCallback(t,e,i){["input-type","separator"].includes(t)?n(this,p,"m",d).call(this,t,i):this.onAttributeChange(t,i)}}l=new WeakMap,h=new WeakMap,c=new WeakMap,p=new WeakSet,f=function(){const t=document.createElement("template");t.innerHTML="<style>.jb-input-web-component {\n --jb-input-input-direction: ltr;\n}</style>",this.shadowRoot.appendChild(t.content.cloneNode(!0)),this.validation.addValidationListGetter(n(this,p,"m",w).bind(this)),n(this,p,"m",b).call(this),this.addStandardValueCallback(n(this,p,"m",y).bind(this))},d=function(t,e){switch(t){case"input-type":this.paymentInputType=e;break;case"separator":this.separatorString=e}},g=function(t){if("CARD"==n(this,l,"f")){let e=r(n(this,p,"m",m).call(this,t)).replace(/[^0-9]/g,"");return e=e.substring(0,16),e}if("SHABA"==n(this,l,"f")){const e=/(?<ir>(IR|ir|Ir|I|i)?)(?<other>.{0,})/g.exec(t);if(e&&e.groups){let t=r(n(this,p,"m",m).call(this,e.groups.other)).replace(/[^0-9]/g,"");t=t.substring(0,24);let i="";if(e.groups.ir)i=e.groups.ir.toUpperCase();else{if(!(t.length>0))return"";i="IR"}if(1==i.length){if(!(t.length>0))return i;i="IR"}return i+t}return""}return t},m=function(t){return t.replace(n(this,c,"f"),"")},y=function(t){let e="",i="";if(console.log({inputType:n(this,l,"f")}),"CARD"==n(this,l,"f")){i=n(this,p,"m",g).call(this,t);const r=RegExp(`(.*)(${n(this,c,"f").source})$`,"g");e=i.replace(/([0-9]{4})/g,`$1${n(this,h,"f")}`).replace(r,"$1")}if("SHABA"==n(this,l,"f")){i=n(this,p,"m",g).call(this,t);const r=/(IR[0-9]{0,2})([0-9]{0,4})([0-9]{0,4})([0-9]{0,4})([0-9]{0,4})([0-9]{0,4})([0-9]{0,2})/g.exec(i);e=r&&r.length>0?r.slice(1).filter((t=>""!==t)).join(n(this,h,"f")):i}return{value:i,displayValue:e}},b=function(){},w=function(){return"CARD"==n(this,l,"f")?[s]:[a,o]};!customElements.get("jb-payment-input")&&window.customElements.define("jb-payment-input",C),t.JBPaymentInputWebComponent=C,t.PaymentInputTypeList=u}));
//# sourceMappingURL=jb-payment-input.umd.js.map