UNPKG

jb-national-input

Version:
54 lines (53 loc) 2.32 kB
(function(t, e) { "object" == typeof exports && "undefined" != typeof module ? e(exports, require("jb-input"), require("jb-core"), require("jb-core/i18n")) : "function" == typeof define && define.amd ? define([ "exports", "jb-input", "jb-core", "jb-core/i18n" ], e) : e((t = "undefined" != typeof globalThis ? globalThis : t || self).JBNationalInput = {}, t.JBInput, t.JBCore, t.JBCoreI18N); })(this, function(t, e, n, i) { Object.defineProperty(t, Symbol.toStringTag, { value: "Module" }); const a = new i.JBDictionary({ fa: { invalidValue: "کد ملی وارد شده نامعتبر است" }, en: { invalidValue: "The entered national code is invalid" } }); var o = class extends e.JBInputWebComponent { constructor() { super(), this.initMobileInputWebComponent(); } initMobileInputWebComponent() { const t = document.createElement("template"); t.innerHTML = "<style>:host{--input-direction:var(--jb-national-input-input-direction,ltr)}</style><style>.jb-input-web-component{--jb-input-input-direction:var(--input-direction)}</style>", this.shadowRoot.appendChild(t.content.cloneNode(!0)), this.validation.addValidationListGetter(this.#t.bind(this)), this.#e(), this.addStandardValueCallback(this.#n.bind(this)); } #n(t) { let e = "", i = ""; const a = /(?<nationalId>[\u06F0-\u06F90-9]{1,10})/g.exec(t); return e = a?.groups ? a.groups.nationalId : "", i = (0, n.faToEnDigits)(e), { value: i, displayValue: e }; } #e() { this.elements.input.addEventListener("beforeinput", this.#i.bind(this)); } #i(t) { const e = t.data; /[\u06F0-\u06F90-9]{1,10}/g.test(e ?? "") || "deleteContentBackward" == t.inputType || t.preventDefault(); } #t() { return [{ validator: ({ value: t }) => function(t) { if (0 === t.length) return !0; const e = (0, n.faToEnDigits)(t); if (!/^\d{10}$/.test(e)) return !1; const i = +e[9], a = e.split("").slice(0, 9).reduce((t, e, n) => t + +e * (10 - n), 0) % 11; return a < 2 ? i === a : i + a === 11; }(t), message: a.get(i.i18n, "invalidValue"), stateType: "badInput" }]; } }; customElements.get("jb-national-input") || window.customElements.define("jb-national-input", o), t.JBNationalInputWebComponent = o; }); //# sourceMappingURL=jb-national-input.umd.js.map