stdnum 1.10.0 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/no/fodselsnummer.js +2 -2
- package/lib/esm/no/fodselsnummer.js +2 -2
- package/package.json +5 -2
- package/src/ad/index.ts +1 -0
- package/src/ad/nrt.spec.ts +36 -0
- package/src/ad/nrt.ts +87 -0
- package/src/al/index.ts +1 -0
- package/src/al/nipt.spec.ts +43 -0
- package/src/al/nipt.ts +111 -0
- package/src/ar/cbu.spec.ts +28 -0
- package/src/ar/cbu.ts +96 -0
- package/src/ar/cuit.spec.ts +28 -0
- package/src/ar/cuit.ts +102 -0
- package/src/ar/dni.spec.ts +22 -0
- package/src/ar/dni.ts +72 -0
- package/src/ar/index.ts +3 -0
- package/src/at/businessid.spec.ts +34 -0
- package/src/at/businessid.ts +73 -0
- package/src/at/index.ts +4 -0
- package/src/at/tin.spec.ts +173 -0
- package/src/at/tin.ts +140 -0
- package/src/at/uid.spec.ts +44 -0
- package/src/at/uid.ts +84 -0
- package/src/at/vnr.spec.ts +38 -0
- package/src/at/vnr.ts +84 -0
- package/src/au/abn.spec.ts +28 -0
- package/src/au/abn.ts +78 -0
- package/src/au/acn.spec.ts +34 -0
- package/src/au/acn.ts +76 -0
- package/src/au/index.ts +3 -0
- package/src/au/tfn.spec.ts +28 -0
- package/src/au/tfn.ts +79 -0
- package/src/az/index.ts +2 -0
- package/src/az/pin.spec.ts +16 -0
- package/src/az/pin.ts +61 -0
- package/src/az/tin.spec.ts +28 -0
- package/src/az/tin.ts +64 -0
- package/src/ba/index.ts +1 -0
- package/src/ba/jmbg.spec.ts +28 -0
- package/src/ba/jmbg.ts +85 -0
- package/src/be/bis.spec.ts +184 -0
- package/src/be/bis.ts +85 -0
- package/src/be/index.ts +4 -0
- package/src/be/insz.spec.ts +51 -0
- package/src/be/insz.ts +55 -0
- package/src/be/nn.spec.ts +117 -0
- package/src/be/nn.ts +77 -0
- package/src/be/personIdentifierHelpers.spec.ts +254 -0
- package/src/be/personIdentifierHelpers.ts +130 -0
- package/src/be/vat.spec.ts +46 -0
- package/src/be/vat.ts +84 -0
- package/src/bg/egn.spec.ts +28 -0
- package/src/bg/egn.ts +75 -0
- package/src/bg/index.ts +3 -0
- package/src/bg/pnf.spec.ts +28 -0
- package/src/bg/pnf.ts +73 -0
- package/src/bg/vat.spec.ts +34 -0
- package/src/bg/vat.ts +120 -0
- package/src/br/cnpj.spec.ts +34 -0
- package/src/br/cnpj.ts +89 -0
- package/src/br/cpf.spec.ts +34 -0
- package/src/br/cpf.ts +87 -0
- package/src/br/index.ts +2 -0
- package/src/by/index.ts +1 -0
- package/src/by/unp.spec.ts +34 -0
- package/src/by/unp.ts +108 -0
- package/src/bz/index.ts +1 -0
- package/src/bz/tin.spec.ts +28 -0
- package/src/bz/tin.ts +67 -0
- package/src/ca/bn.spec.ts +40 -0
- package/src/ca/bn.ts +88 -0
- package/src/ca/gst.spec.ts +34 -0
- package/src/ca/gst.ts +70 -0
- package/src/ca/index.ts +5 -0
- package/src/ca/pst.spec.ts +28 -0
- package/src/ca/pst.ts +71 -0
- package/src/ca/qst.spec.ts +47 -0
- package/src/ca/qst.ts +88 -0
- package/src/ca/sin.spec.ts +34 -0
- package/src/ca/sin.ts +72 -0
- package/src/ch/index.ts +3 -0
- package/src/ch/ssn.spec.ts +50 -0
- package/src/ch/ssn.ts +74 -0
- package/src/ch/uid.spec.ts +34 -0
- package/src/ch/uid.ts +82 -0
- package/src/ch/vat.spec.ts +28 -0
- package/src/ch/vat.ts +83 -0
- package/src/cl/index.ts +2 -0
- package/src/cl/run.ts +13 -0
- package/src/cl/rut.spec.ts +50 -0
- package/src/cl/rut.ts +97 -0
- package/src/cn/index.ts +2 -0
- package/src/cn/ric.spec.ts +34 -0
- package/src/cn/ric.ts +86 -0
- package/src/cn/uscc.spec.ts +34 -0
- package/src/cn/uscc.ts +110 -0
- package/src/co/index.ts +1 -0
- package/src/co/nit.spec.ts +40 -0
- package/src/co/nit.ts +85 -0
- package/src/cr/cpf.spec.ts +34 -0
- package/src/cr/cpf.ts +93 -0
- package/src/cr/cpj.spec.ts +28 -0
- package/src/cr/cpj.ts +111 -0
- package/src/cr/cr.spec.ts +28 -0
- package/src/cr/cr.ts +75 -0
- package/src/cr/index.ts +3 -0
- package/src/cu/index.ts +1 -0
- package/src/cu/ni.spec.ts +34 -0
- package/src/cu/ni.ts +74 -0
- package/src/cy/index.ts +1 -0
- package/src/cy/vat.spec.ts +28 -0
- package/src/cy/vat.ts +98 -0
- package/src/cz/dic.spec.ts +28 -0
- package/src/cz/dic.ts +127 -0
- package/src/cz/index.ts +2 -0
- package/src/cz/rc.spec.ts +44 -0
- package/src/cz/rc.ts +95 -0
- package/src/de/idnr.spec.ts +34 -0
- package/src/de/idnr.ts +91 -0
- package/src/de/index.ts +6 -0
- package/src/de/passport.spec.ts +31 -0
- package/src/de/passport.ts +86 -0
- package/src/de/pwnr.spec.ts +62 -0
- package/src/de/pwnr.ts +190 -0
- package/src/de/stnr.spec.ts +85 -0
- package/src/de/stnr.ts +193 -0
- package/src/de/svnr.spec.ts +56 -0
- package/src/de/svnr.ts +158 -0
- package/src/de/vat.spec.ts +28 -0
- package/src/de/vat.ts +74 -0
- package/src/dk/cpr.spec.ts +34 -0
- package/src/dk/cpr.ts +129 -0
- package/src/dk/cvr.spec.ts +28 -0
- package/src/dk/cvr.ts +81 -0
- package/src/dk/index.ts +2 -0
- package/src/do/cedula.spec.ts +34 -0
- package/src/do/cedula.ts +67 -0
- package/src/do/index.ts +3 -0
- package/src/do/ncf.spec.ts +34 -0
- package/src/do/ncf.ts +133 -0
- package/src/do/rnc.spec.ts +40 -0
- package/src/do/rnc.ts +74 -0
- package/src/dz/index.ts +1 -0
- package/src/dz/nif.spec.ts +39 -0
- package/src/dz/nif.ts +80 -0
- package/src/ec/ci.spec.ts +28 -0
- package/src/ec/ci.ts +92 -0
- package/src/ec/index.ts +2 -0
- package/src/ec/ruc.spec.ts +37 -0
- package/src/ec/ruc.ts +117 -0
- package/src/ee/ik.spec.ts +28 -0
- package/src/ee/ik.ts +114 -0
- package/src/ee/index.ts +3 -0
- package/src/ee/kmkr.spec.ts +28 -0
- package/src/ee/kmkr.ts +76 -0
- package/src/ee/registrikood.spec.ts +28 -0
- package/src/ee/registrikood.ts +80 -0
- package/src/eg/index.ts +1 -0
- package/src/eg/tn.spec.ts +44 -0
- package/src/eg/tn.ts +96 -0
- package/src/es/cif.spec.ts +43 -0
- package/src/es/cif.ts +84 -0
- package/src/es/dni.spec.ts +28 -0
- package/src/es/dni.ts +83 -0
- package/src/es/index.ts +5 -0
- package/src/es/nie.spec.ts +28 -0
- package/src/es/nie.ts +79 -0
- package/src/es/nif.spec.ts +52 -0
- package/src/es/nif.ts +95 -0
- package/src/es/nss.spec.ts +28 -0
- package/src/es/nss.ts +132 -0
- package/src/exceptions.ts +66 -0
- package/src/fi/alv.spec.ts +28 -0
- package/src/fi/alv.ts +76 -0
- package/src/fi/hetu.spec.ts +37 -0
- package/src/fi/hetu.ts +108 -0
- package/src/fi/index.ts +3 -0
- package/src/fi/ytunnus.spec.ts +28 -0
- package/src/fi/ytunnus.ts +49 -0
- package/src/fo/index.ts +1 -0
- package/src/fo/vn.spec.ts +34 -0
- package/src/fo/vn.ts +71 -0
- package/src/fr/index.ts +5 -0
- package/src/fr/nif.spec.ts +34 -0
- package/src/fr/nif.ts +82 -0
- package/src/fr/nir.spec.ts +36 -0
- package/src/fr/nir.ts +98 -0
- package/src/fr/siren.spec.ts +28 -0
- package/src/fr/siren.ts +68 -0
- package/src/fr/siret.spec.ts +38 -0
- package/src/fr/siret.ts +79 -0
- package/src/fr/tva.spec.ts +40 -0
- package/src/fr/tva.ts +125 -0
- package/src/gb/index.ts +3 -0
- package/src/gb/nino-prefixes.ts +245 -0
- package/src/gb/nino.spec.ts +80 -0
- package/src/gb/nino.ts +80 -0
- package/src/gb/utr.spec.ts +28 -0
- package/src/gb/utr.ts +76 -0
- package/src/gb/vat.spec.ts +40 -0
- package/src/gb/vat.ts +112 -0
- package/src/gen/ean.spec.ts +34 -0
- package/src/gen/ean.ts +71 -0
- package/src/gen/index.ts +1 -0
- package/src/gh/index.ts +1 -0
- package/src/gh/tin.spec.ts +42 -0
- package/src/gh/tin.ts +93 -0
- package/src/gn/index.ts +1 -0
- package/src/gn/nifp.spec.ts +40 -0
- package/src/gn/nifp.ts +72 -0
- package/src/gr/amka.spec.ts +28 -0
- package/src/gr/amka.ts +76 -0
- package/src/gr/index.ts +2 -0
- package/src/gr/vat.spec.ts +34 -0
- package/src/gr/vat.ts +84 -0
- package/src/gt/cui.spec.ts +34 -0
- package/src/gt/cui.ts +110 -0
- package/src/gt/index.ts +2 -0
- package/src/gt/nit.spec.ts +34 -0
- package/src/gt/nit.ts +86 -0
- package/src/hk/hkid.spec.ts +52 -0
- package/src/hk/hkid.ts +90 -0
- package/src/hk/index.ts +1 -0
- package/src/hr/index.ts +1 -0
- package/src/hr/oib.spec.ts +28 -0
- package/src/hr/oib.ts +67 -0
- package/src/hu/anum.spec.ts +28 -0
- package/src/hu/anum.ts +71 -0
- package/src/hu/index.ts +1 -0
- package/src/id/index.ts +1 -0
- package/src/id/npwp.spec.ts +34 -0
- package/src/id/npwp.ts +116 -0
- package/src/ie/index.ts +2 -0
- package/src/ie/pps.spec.ts +58 -0
- package/src/ie/pps.ts +81 -0
- package/src/ie/vat.spec.ts +40 -0
- package/src/ie/vat.ts +99 -0
- package/src/il/hp.spec.ts +38 -0
- package/src/il/hp.ts +75 -0
- package/src/il/idnr.spec.ts +28 -0
- package/src/il/idnr.ts +70 -0
- package/src/il/index.ts +2 -0
- package/src/in/aadhaar.spec.ts +40 -0
- package/src/in/aadhaar.ts +85 -0
- package/src/in/epic.spec.ts +34 -0
- package/src/in/epic.ts +85 -0
- package/src/in/gstin.spec.ts +34 -0
- package/src/in/gstin.ts +156 -0
- package/src/in/index.ts +4 -0
- package/src/in/pan.spec.ts +40 -0
- package/src/in/pan.ts +93 -0
- package/src/index.ts +404 -0
- package/src/is/index.ts +2 -0
- package/src/is/kennitala.spec.ts +46 -0
- package/src/is/kennitala.ts +80 -0
- package/src/is/vsk.spec.ts +22 -0
- package/src/is/vsk.ts +60 -0
- package/src/it/aic.spec.ts +40 -0
- package/src/it/aic.ts +97 -0
- package/src/it/codicefiscale.spec.ts +28 -0
- package/src/it/codicefiscale.ts +167 -0
- package/src/it/index.ts +3 -0
- package/src/it/iva.spec.ts +28 -0
- package/src/it/iva.ts +65 -0
- package/src/jp/cn.spec.ts +28 -0
- package/src/jp/cn.ts +77 -0
- package/src/jp/index.ts +1 -0
- package/src/ke/index.ts +1 -0
- package/src/ke/pin.spec.ts +34 -0
- package/src/ke/pin.ts +77 -0
- package/src/kr/brn.spec.ts +28 -0
- package/src/kr/brn.ts +91 -0
- package/src/kr/index.ts +2 -0
- package/src/kr/rrn.spec.ts +34 -0
- package/src/kr/rrn.ts +104 -0
- package/src/li/index.ts +1 -0
- package/src/li/peid.spec.ts +22 -0
- package/src/li/peid.ts +71 -0
- package/src/lt/asmens.spec.ts +28 -0
- package/src/lt/asmens.ts +73 -0
- package/src/lt/index.ts +2 -0
- package/src/lt/pvm.spec.ts +34 -0
- package/src/lt/pvm.ts +75 -0
- package/src/lu/index.ts +1 -0
- package/src/lu/tva.spec.ts +28 -0
- package/src/lu/tva.ts +70 -0
- package/src/lv/index.ts +1 -0
- package/src/lv/pvn.spec.ts +44 -0
- package/src/lv/pvn.ts +102 -0
- package/src/ma/ice.spec.ts +39 -0
- package/src/ma/ice.ts +72 -0
- package/src/ma/ice9.spec.ts +28 -0
- package/src/ma/ice9.ts +62 -0
- package/src/ma/index.ts +2 -0
- package/src/mc/index.ts +1 -0
- package/src/mc/tva.spec.ts +28 -0
- package/src/mc/tva.ts +67 -0
- package/src/md/idno.spec.ts +28 -0
- package/src/md/idno.ts +78 -0
- package/src/md/index.ts +1 -0
- package/src/me/index.ts +2 -0
- package/src/me/jmbg.ts +17 -0
- package/src/me/pib.spec.ts +158 -0
- package/src/me/pib.ts +77 -0
- package/src/mk/edb.spec.ts +50 -0
- package/src/mk/edb.ts +88 -0
- package/src/mk/index.ts +2 -0
- package/src/mk/jmbg.ts +17 -0
- package/src/mt/index.ts +1 -0
- package/src/mt/vat.spec.ts +28 -0
- package/src/mt/vat.ts +69 -0
- package/src/mu/index.ts +1 -0
- package/src/mu/nid.spec.ts +34 -0
- package/src/mu/nid.ts +89 -0
- package/src/mx/banks.ts +658 -0
- package/src/mx/clabe.spec.ts +68 -0
- package/src/mx/clabe.ts +105 -0
- package/src/mx/curp.spec.ts +28 -0
- package/src/mx/curp.ts +261 -0
- package/src/mx/index.ts +3 -0
- package/src/mx/rfc.spec.ts +69 -0
- package/src/mx/rfc.ts +193 -0
- package/src/my/index.ts +1 -0
- package/src/my/nric.spec.ts +40 -0
- package/src/my/nric.ts +91 -0
- package/src/nl/bsn.spec.ts +68 -0
- package/src/nl/bsn.ts +81 -0
- package/src/nl/btw.spec.ts +40 -0
- package/src/nl/btw.ts +95 -0
- package/src/nl/index.ts +3 -0
- package/src/nl/onderwijsnummer.spec.ts +34 -0
- package/src/nl/onderwijsnummer.ts +77 -0
- package/src/no/fodselsnummer.spec.ts +56 -0
- package/src/no/fodselsnummer.ts +118 -0
- package/src/no/index.ts +4 -0
- package/src/no/kontonr.spec.ts +34 -0
- package/src/no/kontonr.ts +84 -0
- package/src/no/mva.spec.ts +28 -0
- package/src/no/mva.ts +80 -0
- package/src/no/orgnr.spec.ts +28 -0
- package/src/no/orgnr.ts +75 -0
- package/src/nz/bank.spec.ts +28 -0
- package/src/nz/bank.ts +238 -0
- package/src/nz/index.ts +2 -0
- package/src/nz/ird.spec.ts +34 -0
- package/src/nz/ird.ts +102 -0
- package/src/pe/ce.spec.ts +46 -0
- package/src/pe/ce.ts +61 -0
- package/src/pe/cui.spec.ts +28 -0
- package/src/pe/cui.ts +85 -0
- package/src/pe/index.ts +3 -0
- package/src/pe/ruc.spec.ts +46 -0
- package/src/pe/ruc.ts +84 -0
- package/src/pk/cnic.spec.ts +34 -0
- package/src/pk/cnic.ts +97 -0
- package/src/pk/index.ts +2 -0
- package/src/pk/ntn.spec.ts +22 -0
- package/src/pk/ntn.ts +65 -0
- package/src/pl/index.ts +3 -0
- package/src/pl/nip.spec.ts +34 -0
- package/src/pl/nip.ts +74 -0
- package/src/pl/pesel.spec.ts +34 -0
- package/src/pl/pesel.ts +97 -0
- package/src/pl/regon.spec.ts +52 -0
- package/src/pl/regon.ts +88 -0
- package/src/pt/cc.spec.ts +43 -0
- package/src/pt/cc.ts +74 -0
- package/src/pt/index.ts +3 -0
- package/src/pt/nif.spec.ts +28 -0
- package/src/pt/nif.ts +78 -0
- package/src/pt/nipc.ts +27 -0
- package/src/py/cedula.spec.ts +46 -0
- package/src/py/cedula.ts +73 -0
- package/src/py/index.ts +2 -0
- package/src/py/ruc.spec.ts +40 -0
- package/src/py/ruc.ts +93 -0
- package/src/ro/cif.spec.ts +40 -0
- package/src/ro/cif.ts +62 -0
- package/src/ro/cnp.spec.ts +50 -0
- package/src/ro/cnp.ts +158 -0
- package/src/ro/cui.spec.ts +28 -0
- package/src/ro/cui.ts +83 -0
- package/src/ro/index.ts +4 -0
- package/src/ro/onrc.spec.ts +28 -0
- package/src/ro/onrc.ts +109 -0
- package/src/rs/index.ts +2 -0
- package/src/rs/jmbg.ts +16 -0
- package/src/rs/pib.spec.ts +28 -0
- package/src/rs/pib.ts +69 -0
- package/src/ru/index.ts +1 -0
- package/src/ru/inn.spec.ts +32 -0
- package/src/ru/inn.ts +106 -0
- package/src/se/index.ts +3 -0
- package/src/se/orgnr.spec.ts +28 -0
- package/src/se/orgnr.ts +68 -0
- package/src/se/personnummer.spec.ts +45 -0
- package/src/se/personnummer.ts +143 -0
- package/src/se/vat.spec.ts +28 -0
- package/src/se/vat.ts +73 -0
- package/src/sg/index.ts +1 -0
- package/src/sg/uen.spec.ts +46 -0
- package/src/sg/uen.ts +209 -0
- package/src/si/ddv.spec.ts +28 -0
- package/src/si/ddv.ts +76 -0
- package/src/si/emso.spec.ts +15 -0
- package/src/si/emso.ts +27 -0
- package/src/si/index.ts +3 -0
- package/src/si/jmbg.ts +20 -0
- package/src/sk/dph.spec.ts +28 -0
- package/src/sk/dph.ts +71 -0
- package/src/sk/index.ts +2 -0
- package/src/sk/rc.ts +12 -0
- package/src/sm/coe.spec.ts +34 -0
- package/src/sm/coe.ts +80 -0
- package/src/sm/index.ts +1 -0
- package/src/sv/index.ts +1 -0
- package/src/sv/nit.spec.ts +34 -0
- package/src/sv/nit.ts +117 -0
- package/src/th/idnr.spec.ts +41 -0
- package/src/th/idnr.ts +80 -0
- package/src/th/index.ts +3 -0
- package/src/th/moa.spec.ts +62 -0
- package/src/th/moa.ts +85 -0
- package/src/th/tin.spec.ts +77 -0
- package/src/th/tin.ts +56 -0
- package/src/tn/index.ts +1 -0
- package/src/tn/mf.spec.ts +37 -0
- package/src/tn/mf.ts +169 -0
- package/src/tr/index.ts +2 -0
- package/src/tr/tckimlik.spec.ts +40 -0
- package/src/tr/tckimlik.ts +87 -0
- package/src/tr/vkn.spec.ts +28 -0
- package/src/tr/vkn.ts +87 -0
- package/src/tw/ban.spec.ts +28 -0
- package/src/tw/ban.ts +67 -0
- package/src/tw/index.ts +5 -0
- package/src/tw/natid.spec.ts +28 -0
- package/src/tw/natid.ts +105 -0
- package/src/tw/tax_code.spec.ts +34 -0
- package/src/tw/tax_code.ts +98 -0
- package/src/tw/ubn.spec.ts +28 -0
- package/src/tw/ubn.ts +80 -0
- package/src/tw/ui.spec.ts +38 -0
- package/src/tw/ui.ts +107 -0
- package/src/types.ts +82 -0
- package/src/ua/edrpou.spec.ts +28 -0
- package/src/ua/edrpou.ts +88 -0
- package/src/ua/index.ts +2 -0
- package/src/ua/rntrc.spec.ts +28 -0
- package/src/ua/rntrc.ts +77 -0
- package/src/us/ein.spec.ts +28 -0
- package/src/us/ein.ts +179 -0
- package/src/us/index.ts +2 -0
- package/src/us/ssn.spec.ts +28 -0
- package/src/us/ssn.ts +117 -0
- package/src/util/checksum.spec.ts +70 -0
- package/src/util/checksum.ts +258 -0
- package/src/util/index.ts +13 -0
- package/src/util/isValidDate.spec.ts +49 -0
- package/src/util/isValidDate.ts +87 -0
- package/src/util/iso7064.spec.ts +17 -0
- package/src/util/iso7064.ts +8 -0
- package/src/util/pymod.ts +8 -0
- package/src/util/strings/char.ts +18 -0
- package/src/util/strings/clean.spec.ts +15 -0
- package/src/util/strings/clean.ts +305 -0
- package/src/util/strings/format.ts +18 -0
- package/src/util/strings/index.ts +5 -0
- package/src/util/strings/reverseString.ts +3 -0
- package/src/util/strings/splitAt.spec.ts +15 -0
- package/src/util/strings/splitAt.ts +16 -0
- package/src/uy/cedula.spec.ts +28 -0
- package/src/uy/cedula.ts +74 -0
- package/src/uy/index.ts +3 -0
- package/src/uy/nie.spec.ts +28 -0
- package/src/uy/nie.ts +84 -0
- package/src/uy/rut.spec.ts +34 -0
- package/src/uy/rut.ts +99 -0
- package/src/ve/index.ts +1 -0
- package/src/ve/rif.spec.ts +38 -0
- package/src/ve/rif.ts +92 -0
- package/src/vn/index.ts +1 -0
- package/src/vn/mst.spec.ts +40 -0
- package/src/vn/mst.ts +100 -0
- package/src/za/idnr.spec.ts +28 -0
- package/src/za/idnr.ts +84 -0
- package/src/za/index.ts +2 -0
- package/src/za/tin.spec.ts +28 -0
- package/src/za/tin.ts +75 -0
package/src/mx/rfc.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC (Registro Federal de Contribuyentes, Mexican tax number).
|
|
3
|
+
*
|
|
4
|
+
* This number is used to identify individuals and companies for tax purposes.
|
|
5
|
+
*
|
|
6
|
+
* The company number is 12 digits where the first 3 letters or digits are
|
|
7
|
+
* derived from the name of the company, the following 6 contain the date of
|
|
8
|
+
* incorporation, followed by 3 check digits.
|
|
9
|
+
*
|
|
10
|
+
* Personal numbers consist of 13 digits where the first 4 characters from the
|
|
11
|
+
* person's name, followed by their birth date and 3 check digits.
|
|
12
|
+
*
|
|
13
|
+
* The first two check digits are calculated based on the person's or company's
|
|
14
|
+
* full name. The last check digit is calculated over all the preceding digits
|
|
15
|
+
* in the number. However, it seems a lot of numbers (estimated at around 1.5%
|
|
16
|
+
* of all numbers) are in use with invalid check digits so this test is disabled
|
|
17
|
+
* by default.
|
|
18
|
+
*
|
|
19
|
+
* More information:
|
|
20
|
+
*
|
|
21
|
+
* https://www.infomex.org.mx/jspsi/documentos/2005/seguimiento/06101/0610100162005_065.doc
|
|
22
|
+
* https://es.wikipedia.org/wiki/Registro_Federal_de_Contribuyentes_(M%C3%A9xico)
|
|
23
|
+
*
|
|
24
|
+
* An online validation service is available at:
|
|
25
|
+
*
|
|
26
|
+
* https://portalsat.plataforma.sat.gob.mx/ConsultaRFC/
|
|
27
|
+
*
|
|
28
|
+
* VAT PERSON/ENTITY
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import * as exceptions from '../exceptions';
|
|
32
|
+
import { isValidDateCompactYYMMDD, strings, weightedSum } from '../util';
|
|
33
|
+
import { Validator, ValidateReturn } from '../types';
|
|
34
|
+
|
|
35
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
36
|
+
return strings.cleanUnicode(input, '-_ ');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const nameBlacklist = new Set([
|
|
40
|
+
'BUEI',
|
|
41
|
+
'BUEY',
|
|
42
|
+
'CACA',
|
|
43
|
+
'CACO',
|
|
44
|
+
'CAGA',
|
|
45
|
+
'CAGO',
|
|
46
|
+
'CAKA',
|
|
47
|
+
'CAKO',
|
|
48
|
+
'COGE',
|
|
49
|
+
'COJA',
|
|
50
|
+
'COJE',
|
|
51
|
+
'COJI',
|
|
52
|
+
'COJO',
|
|
53
|
+
'CULO',
|
|
54
|
+
'FETO',
|
|
55
|
+
'GUEY',
|
|
56
|
+
'JOTO',
|
|
57
|
+
'KACA',
|
|
58
|
+
'KACO',
|
|
59
|
+
'KAGA',
|
|
60
|
+
'KAGO',
|
|
61
|
+
'KAKA',
|
|
62
|
+
'KOGE',
|
|
63
|
+
'KOJO',
|
|
64
|
+
'KULO',
|
|
65
|
+
'MAME',
|
|
66
|
+
'MAMO',
|
|
67
|
+
'MEAR',
|
|
68
|
+
'MEAS',
|
|
69
|
+
'MEON',
|
|
70
|
+
'MION',
|
|
71
|
+
'MOCO',
|
|
72
|
+
'MULA',
|
|
73
|
+
'PEDA',
|
|
74
|
+
'PEDO',
|
|
75
|
+
'PENE',
|
|
76
|
+
'PUTA',
|
|
77
|
+
'PUTO',
|
|
78
|
+
'QULO',
|
|
79
|
+
'RATA',
|
|
80
|
+
'RUIN',
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
const checkAlphabet = '0123456789ABCDEFGHIJKLMN&OPQRSTUVWXYZ Ñ';
|
|
84
|
+
// const checkAlphabetDict: Record<string, number> = checkAlphabet
|
|
85
|
+
// .split('')
|
|
86
|
+
// .reduce((acc, c, idx) => ({ ...acc, [c]: idx }), {});
|
|
87
|
+
|
|
88
|
+
const impl: Validator = {
|
|
89
|
+
name: 'Mexican Tax Number',
|
|
90
|
+
localName: 'Registro Federal de Contribuyentes',
|
|
91
|
+
abbreviation: 'RFC',
|
|
92
|
+
compact(input: string): string {
|
|
93
|
+
const [value, err] = clean(input);
|
|
94
|
+
|
|
95
|
+
if (err) {
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return value.toLocaleUpperCase();
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
format(input: string): string {
|
|
103
|
+
const [value] = clean(input);
|
|
104
|
+
|
|
105
|
+
if (value.length === 12) {
|
|
106
|
+
return strings.splitAt(value, 3, 9).join(' ');
|
|
107
|
+
}
|
|
108
|
+
if (value.length === 13) {
|
|
109
|
+
return strings.splitAt(value, 4, 10).join(' ');
|
|
110
|
+
}
|
|
111
|
+
return strings.splitAt(value, 4).join(' ');
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Check if the number is a valid RFC number.
|
|
116
|
+
* This checks the length, formatting and other contraints. It does not check
|
|
117
|
+
* for control letter.
|
|
118
|
+
*/
|
|
119
|
+
validate(input: string): ValidateReturn {
|
|
120
|
+
const [value, error] = clean(input);
|
|
121
|
+
|
|
122
|
+
if (error) {
|
|
123
|
+
return { isValid: false, error };
|
|
124
|
+
}
|
|
125
|
+
if (value.length === 10 || value.length === 13) {
|
|
126
|
+
if (!/^[A-Z&Ñ]{4}[0-9]{6}([0-9A-Z]{3})?$/.test(value)) {
|
|
127
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
128
|
+
}
|
|
129
|
+
if (nameBlacklist.has(value.substr(0, 4))) {
|
|
130
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
131
|
+
}
|
|
132
|
+
if (!isValidDateCompactYYMMDD(value.substr(4, 6), true)) {
|
|
133
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
134
|
+
}
|
|
135
|
+
} else if (value.length === 12) {
|
|
136
|
+
if (!/^[A-Z&Ñ]{3}[0-9]{6}[0-9A-Z]{3}$/.test(value)) {
|
|
137
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
138
|
+
}
|
|
139
|
+
if (!isValidDateCompactYYMMDD(value.substr(3, 6))) {
|
|
140
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (value.length >= 12) {
|
|
147
|
+
if (!/[1-9A-V][1-9A-Z][0-9A]$/.test(value)) {
|
|
148
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const [front, check] = strings.splitAt(value, -1);
|
|
152
|
+
|
|
153
|
+
const sum = weightedSum(front.padStart(12, ' '), {
|
|
154
|
+
modulus: 11,
|
|
155
|
+
alphabet: checkAlphabet,
|
|
156
|
+
weights: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
|
|
157
|
+
reverse: true,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// const sum = value
|
|
161
|
+
// .substr(0, value.length - 1)
|
|
162
|
+
// .padStart(12, ' ')
|
|
163
|
+
// .split('')
|
|
164
|
+
// .reduce(
|
|
165
|
+
// (acc, c, idx) => acc + (checkAlphabetDict[c] ?? 0) * (13 - idx),
|
|
166
|
+
// 0,
|
|
167
|
+
// );
|
|
168
|
+
const mod = 11 - (sum % 11);
|
|
169
|
+
let val;
|
|
170
|
+
if (mod === 11) {
|
|
171
|
+
val = '0';
|
|
172
|
+
} else if (mod === 10) {
|
|
173
|
+
val = 'A';
|
|
174
|
+
} else {
|
|
175
|
+
val = String(mod);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (check !== val) {
|
|
179
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
isValid: true,
|
|
185
|
+
compact: value,
|
|
186
|
+
isIndividual: value.length !== 12,
|
|
187
|
+
isCompany: value.length === 12,
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
193
|
+
impl;
|
package/src/my/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as nric from './nric';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { validate, format } from './nric';
|
|
2
|
+
import { InvalidLength, InvalidComponent } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('my/nric', () => {
|
|
5
|
+
it('format:770305021234', () => {
|
|
6
|
+
const result = format('770305021234');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('770305-02-1234');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:770305-02-1234', () => {
|
|
12
|
+
const result = validate('770305-02-1234');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('770305021234');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:12345678', () => {
|
|
18
|
+
const result = validate('12345678');
|
|
19
|
+
|
|
20
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:770305-17-1234', () => {
|
|
24
|
+
const result = validate('771305-17-1234');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('validate:771305-02-1234', () => {
|
|
30
|
+
const result = validate('771305-02-1234');
|
|
31
|
+
|
|
32
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// it('validate:2449/494/16/0', () => {
|
|
36
|
+
// const result = validate('2449/494/16/0');
|
|
37
|
+
|
|
38
|
+
// expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
39
|
+
// });
|
|
40
|
+
});
|
package/src/my/nric.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NRIC No. (Malaysian National Registration Identity Card Number).
|
|
3
|
+
*
|
|
4
|
+
* The NRIC No. is the unique identifier for issued to Malaysian citizens and
|
|
5
|
+
* permanent residents.
|
|
6
|
+
*
|
|
7
|
+
* The number consist of 12 digits in three sections. The first 6 digits
|
|
8
|
+
* represent the birth date, followed by two digits represeting the birth
|
|
9
|
+
* place and finally four digits. The gender of a person can be derived from
|
|
10
|
+
* the last digit: odd numbers for males and even numbers for females.
|
|
11
|
+
*
|
|
12
|
+
* PERSON
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import * as exceptions from '../exceptions';
|
|
16
|
+
import { isValidDateCompactYYMMDD, strings } from '../util';
|
|
17
|
+
import { Validator, ValidateReturn } from '../types';
|
|
18
|
+
|
|
19
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
20
|
+
return strings.cleanUnicode(input, ' -*');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const UNASSIGNED = [
|
|
24
|
+
'00',
|
|
25
|
+
'17',
|
|
26
|
+
'18',
|
|
27
|
+
'19',
|
|
28
|
+
'20',
|
|
29
|
+
'69',
|
|
30
|
+
'73',
|
|
31
|
+
'80',
|
|
32
|
+
'81',
|
|
33
|
+
'94',
|
|
34
|
+
'95',
|
|
35
|
+
'96',
|
|
36
|
+
'97',
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const impl: Validator = {
|
|
40
|
+
name: 'Malaysian National Registration Identity Card Number',
|
|
41
|
+
localName: 'National Registration Identity Card Number',
|
|
42
|
+
abbreviation: 'NRIC No.',
|
|
43
|
+
compact(input: string): string {
|
|
44
|
+
const [value, err] = clean(input);
|
|
45
|
+
|
|
46
|
+
if (err) {
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return value;
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
format(input: string): string {
|
|
54
|
+
const [value] = clean(input);
|
|
55
|
+
|
|
56
|
+
return strings.splitAt(value, 6, 8).join('-');
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
validate(input: string): ValidateReturn {
|
|
60
|
+
const [value, error] = clean(input);
|
|
61
|
+
|
|
62
|
+
if (error) {
|
|
63
|
+
return { isValid: false, error };
|
|
64
|
+
}
|
|
65
|
+
if (value.length !== 12) {
|
|
66
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
67
|
+
}
|
|
68
|
+
if (!strings.isdigits(value)) {
|
|
69
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const [bdate, place] = strings.splitAt(value, 6, 8);
|
|
73
|
+
|
|
74
|
+
if (!isValidDateCompactYYMMDD(bdate, true)) {
|
|
75
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
76
|
+
}
|
|
77
|
+
if (UNASSIGNED.includes(place)) {
|
|
78
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
isValid: true,
|
|
83
|
+
compact: value,
|
|
84
|
+
isIndividual: true,
|
|
85
|
+
isCompany: false,
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
91
|
+
impl;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { validate, format } from './bsn';
|
|
2
|
+
import { InvalidLength, InvalidChecksum } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('nl/bsn', () => {
|
|
5
|
+
it('format:111222333', () => {
|
|
6
|
+
const result = format('111222333');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('1112.22.333');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test.each([
|
|
12
|
+
'001855013', // RSIN
|
|
13
|
+
'1112.22.333', // BSN
|
|
14
|
+
])('isValid', value => {
|
|
15
|
+
const result = validate(value);
|
|
16
|
+
|
|
17
|
+
expect(result.isValid).toEqual(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('validate:1112.22.333', () => {
|
|
21
|
+
const result = validate('1112.22.333');
|
|
22
|
+
|
|
23
|
+
expect(result.isValid && result.compact).toEqual('111222333');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('validate:002455799', () => {
|
|
27
|
+
const result = validate('002455799');
|
|
28
|
+
|
|
29
|
+
// expect(result.isValid && result.compact).toEqual('002455799');
|
|
30
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('validate:12345678912', () => {
|
|
34
|
+
const result = validate('12345678912');
|
|
35
|
+
|
|
36
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('validate:1112.52.333', () => {
|
|
40
|
+
const result = validate('1112.52.333');
|
|
41
|
+
|
|
42
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('validate:123456782', () => {
|
|
46
|
+
const result = validate('123456782');
|
|
47
|
+
|
|
48
|
+
expect(result.isValid && result.compact).toEqual('123456782');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('validate:40645678', () => {
|
|
52
|
+
const result = validate('40645678');
|
|
53
|
+
|
|
54
|
+
expect(result.isValid && result.compact).toEqual('40645678');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('validate:1', () => {
|
|
58
|
+
const result = validate('1');
|
|
59
|
+
|
|
60
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('validate:1234567', () => {
|
|
64
|
+
const result = validate('1234567');
|
|
65
|
+
|
|
66
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
67
|
+
});
|
|
68
|
+
});
|
package/src/nl/bsn.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSN (Burgerservicenummer, the Dutch citizen identification number).
|
|
3
|
+
*
|
|
4
|
+
* The BSN is a unique personal identifier and has been introduced as the
|
|
5
|
+
* successor to the sofinummer. It is issued to each Dutch national. The number
|
|
6
|
+
* consists of up to nine digits (the leading zeros are commonly omitted) and
|
|
7
|
+
* contains a simple checksum.
|
|
8
|
+
*
|
|
9
|
+
* Source:
|
|
10
|
+
* https://en.wikipedia.org/wiki/National_identification_number#Netherlands
|
|
11
|
+
* https://nl.wikipedia.org/wiki/Burgerservicenummer
|
|
12
|
+
* http://www.burgerservicenummer.nl/
|
|
13
|
+
*
|
|
14
|
+
* PERSON
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import * as exceptions from '../exceptions';
|
|
18
|
+
import { strings } from '../util';
|
|
19
|
+
import { Validator, ValidateReturn } from '../types';
|
|
20
|
+
import { weightedSum } from '../util/checksum';
|
|
21
|
+
|
|
22
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
23
|
+
return strings.cleanUnicode(input, ' -.');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function checksum(value: string): boolean {
|
|
27
|
+
const nineCharValue = value.padStart(9, '0');
|
|
28
|
+
const sum = weightedSum(nineCharValue, {
|
|
29
|
+
weights: [9, 8, 7, 6, 5, 4, 3, 2, -1],
|
|
30
|
+
modulus: 11,
|
|
31
|
+
});
|
|
32
|
+
return sum === 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const impl: Validator = {
|
|
36
|
+
name: 'Dutch Citizen Identification Number',
|
|
37
|
+
localName: 'Burgerservicenummer',
|
|
38
|
+
abbreviation: 'BSN',
|
|
39
|
+
compact(input: string): string {
|
|
40
|
+
const [value, err] = clean(input);
|
|
41
|
+
|
|
42
|
+
if (err) {
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return value;
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
format(input: string): string {
|
|
50
|
+
const [value] = clean(input);
|
|
51
|
+
|
|
52
|
+
return strings.splitAt(value, 4, 6).join('.');
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
validate(input: string): ValidateReturn {
|
|
56
|
+
const [value, error] = clean(input);
|
|
57
|
+
|
|
58
|
+
if (error) {
|
|
59
|
+
return { isValid: false, error };
|
|
60
|
+
}
|
|
61
|
+
if (![8, 9].includes(value.length)) {
|
|
62
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
63
|
+
}
|
|
64
|
+
if (!strings.isdigits(value)) {
|
|
65
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
66
|
+
}
|
|
67
|
+
if (!checksum(value)) {
|
|
68
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
isValid: true,
|
|
73
|
+
compact: value,
|
|
74
|
+
isIndividual: true,
|
|
75
|
+
isCompany: false,
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
81
|
+
impl;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { validate, format } from './btw';
|
|
2
|
+
import { InvalidLength, InvalidChecksum } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('nl/btw', () => {
|
|
5
|
+
it('format:004495445B01', () => {
|
|
6
|
+
const result = format('004495445B01');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('004495445B01');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:004495445B01', () => {
|
|
12
|
+
const result = validate('004495445B01');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('004495445B01');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:NL4495445B01', () => {
|
|
18
|
+
const result = validate('NL4495445B01');
|
|
19
|
+
|
|
20
|
+
expect(result.isValid && result.compact).toEqual('004495445B01');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:NL002455799B11', () => {
|
|
24
|
+
const result = validate('NL002455799B11');
|
|
25
|
+
|
|
26
|
+
expect(result.isValid && result.compact).toEqual('002455799B11');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('validate:123456789012345', () => {
|
|
30
|
+
const result = validate('123456789012345');
|
|
31
|
+
|
|
32
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('validate:123456789B90', () => {
|
|
36
|
+
const result = validate('123456789B90');
|
|
37
|
+
|
|
38
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
39
|
+
});
|
|
40
|
+
});
|
package/src/nl/btw.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Btw-identificatienummer (Omzetbelastingnummer, the Dutch VAT number).
|
|
3
|
+
*
|
|
4
|
+
* The btw-identificatienummer (previously the btw-nummer) is the Dutch number
|
|
5
|
+
* for identifying parties in a transaction for which VAT is due. The btw-nummer
|
|
6
|
+
* is used in communication with the tax agency while the
|
|
7
|
+
* btw-identificatienummer (EORI-nummer) can be used when dealing with other
|
|
8
|
+
* companies though they are used interchangeably.
|
|
9
|
+
*
|
|
10
|
+
* The btw-nummer consists of a RSIN or BSN followed by the letter B and two
|
|
11
|
+
* digits that identify the number of the company created. The
|
|
12
|
+
* btw-identificatienummer has a similar format but different checksum and does
|
|
13
|
+
* not contain the BSN.
|
|
14
|
+
*
|
|
15
|
+
* Source
|
|
16
|
+
* https://en.wikipedia.org/wiki/VAT_identification_number
|
|
17
|
+
* https://nl.wikipedia.org/wiki/Btw-nummer_(Nederland)
|
|
18
|
+
*
|
|
19
|
+
* ENTITY
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import * as exceptions from '../exceptions';
|
|
23
|
+
import { strings } from '../util';
|
|
24
|
+
import { Validator, ValidateReturn } from '../types';
|
|
25
|
+
import { mod97base10Validate, weightedSum } from '../util/checksum';
|
|
26
|
+
|
|
27
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
28
|
+
const [value, err] = strings.cleanUnicode(input, ' -.', 'NL');
|
|
29
|
+
|
|
30
|
+
if (err) {
|
|
31
|
+
return [value, err];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const [a, b] = strings.splitAt(value, -3);
|
|
35
|
+
|
|
36
|
+
return [`${a.padStart(9, '0')}${b}`, null];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const impl: Validator = {
|
|
40
|
+
name: 'Dutch VAT Number',
|
|
41
|
+
localName: 'Btw-identificatienummer',
|
|
42
|
+
abbreviation: 'Btw-nr.',
|
|
43
|
+
compact(input: string): string {
|
|
44
|
+
const [value, err] = clean(input);
|
|
45
|
+
|
|
46
|
+
if (err) {
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return value;
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
format(input: string): string {
|
|
54
|
+
const [value] = clean(input);
|
|
55
|
+
|
|
56
|
+
return value;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
validate(input: string): ValidateReturn {
|
|
60
|
+
const [value, error] = clean(input);
|
|
61
|
+
|
|
62
|
+
if (error) {
|
|
63
|
+
return { isValid: false, error };
|
|
64
|
+
}
|
|
65
|
+
if (value.length !== 12) {
|
|
66
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
67
|
+
}
|
|
68
|
+
const [a, b, c] = strings.splitAt(value, 9, 10);
|
|
69
|
+
if (!strings.isdigits(a) || !strings.isdigits(c)) {
|
|
70
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
71
|
+
}
|
|
72
|
+
if (b !== 'B') {
|
|
73
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const sum = weightedSum(a, {
|
|
77
|
+
weights: [9, 8, 7, 6, 5, 4, 3, 2, -1],
|
|
78
|
+
modulus: 11,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (sum % 11 !== 0 && !mod97base10Validate(`NL${a}${b}${c}`)) {
|
|
82
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
isValid: true,
|
|
87
|
+
compact: `${a}${b}${c}`,
|
|
88
|
+
isIndividual: false,
|
|
89
|
+
isCompany: true,
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
95
|
+
impl;
|
package/src/nl/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { validate, format } from './onderwijsnummer';
|
|
2
|
+
import { InvalidLength, InvalidChecksum } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('nl/onderwijsnummer', () => {
|
|
5
|
+
it('format:1012.22.331', () => {
|
|
6
|
+
const result = format('1012.22.331');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('1012.22.331');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:1012.22.331', () => {
|
|
12
|
+
const result = validate('1012.22.331');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('101222331');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:1234567812', () => {
|
|
18
|
+
const result = validate('12345678012');
|
|
19
|
+
|
|
20
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:100252333', () => {
|
|
24
|
+
const result = validate('100252333');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('validate:1', () => {
|
|
30
|
+
const result = validate('1');
|
|
31
|
+
|
|
32
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
33
|
+
});
|
|
34
|
+
});
|