polish-utils
Version:
Lightweight library for extracting data and validating polish identification numbers such as PESEL or NIP
20 lines (19 loc) • 587 B
JavaScript
Object.defineProperty(exports, '__esModule', { value: !0 })
exports.NIP = class {
constructor(t) {
;(this.nip = t.replace(/[ \-]/gi, '')), (this.valid = this.validate())
}
get isValid() {
return this.valid
}
getIssuingTaxOfficeCode() {
return this.nip.substr(0, 3)
}
validate() {
if (!/^[0-9]{10}$/.test(this.nip)) return !1
const t = `${this.nip}`.split('').map((t) => +t),
e = t.splice(-1)[0]
return [6, 5, 7, 2, 3, 4, 5, 6, 7].reduce((e, i, s) => e + i * t[s], 0) % 11 === e
}
}