jb-national-input
Version:
national input web component
46 lines (45 loc) • 1.93 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
let t = require("jb-input"), n = require("jb-core"), e = require("jb-core/i18n");
const i = new e.JBDictionary({
fa: { invalidValue: "کد ملی وارد شده نامعتبر است" },
en: { invalidValue: "The entered national code is invalid" }
});
var a = class extends t.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.#n(), this.addStandardValueCallback(this.#e.bind(this));
}
#e(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
};
}
#n() {
this.elements.input.addEventListener("beforeinput", this.#i.bind(this));
}
#i(t) {
const n = t.data;
/[\u06F0-\u06F90-9]{1,10}/g.test(n ?? "") || "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, n, e) => t + +n * (10 - e), 0) % 11;
return a < 2 ? i === a : i + a === 11;
}(t),
message: i.get(e.i18n, "invalidValue"),
stateType: "badInput"
}];
}
};
customElements.get("jb-national-input") || window.customElements.define("jb-national-input", a), exports.JBNationalInputWebComponent = a;
//# sourceMappingURL=jb-national-input.cjs.js.map