UNPKG

polish-utils

Version:

Lightweight library for extracting data and validating polish identification numbers such as PESEL or NIP

19 lines (18 loc) 522 B
class i { constructor(i) { ;(this.nip = i.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 i = `${this.nip}`.split('').map((i) => +i), t = i.splice(-1)[0] return [6, 5, 7, 2, 3, 4, 5, 6, 7].reduce((t, s, e) => t + s * i[e], 0) % 11 === t } } export { i as NIP }