stdnum 1.10.0 → 1.10.2
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/README.md +1 -0
- package/lib/cjs/in/gstin.js +3 -3
- package/lib/cjs/no/fodselsnummer.js +2 -2
- package/lib/cjs/tw/natid.js +8 -5
- package/lib/cjs/tw/ui.js +8 -5
- package/lib/esm/in/gstin.js +3 -3
- package/lib/esm/no/fodselsnummer.js +2 -2
- package/lib/esm/tw/natid.js +8 -5
- package/lib/esm/tw/ui.js +8 -5
- 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 +41 -0
- package/src/tw/natid.ts +109 -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 +49 -0
- package/src/tw/ui.ts +111 -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/de/stnr.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* St.-Nr. (Steuernummer, German tax number).
|
|
3
|
+
*
|
|
4
|
+
* The Steuernummer (St.-Nr.) is a tax number assigned by regional tax offices
|
|
5
|
+
* to taxable individuals and organisations. The number is being replaced by the
|
|
6
|
+
* Steuerliche Identifikationsnummer (IdNr).
|
|
7
|
+
* The number has 10 or 11 digits for the regional form (per Bundesland) and 13
|
|
8
|
+
* digits for the number that is unique within Germany. The number consists of
|
|
9
|
+
* (part of) the Bundesfinanzamtsnummer (BUFA-Nr.), a district number, a serial
|
|
10
|
+
* number and a check digit.
|
|
11
|
+
*
|
|
12
|
+
* Source
|
|
13
|
+
* https://de.wikipedia.org/wiki/Steuernummer
|
|
14
|
+
*
|
|
15
|
+
* PERSON/ENTITY
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import * as exceptions from '../exceptions';
|
|
19
|
+
import { strings } from '../util';
|
|
20
|
+
import { Validator, ValidateReturn } from '../types';
|
|
21
|
+
// import { mod11mod10Validate } from '../util/checksum';
|
|
22
|
+
|
|
23
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
24
|
+
return strings.cleanUnicode(input, ' -./,');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type Match =
|
|
28
|
+
| { match: false }
|
|
29
|
+
| {
|
|
30
|
+
match: true;
|
|
31
|
+
f: string;
|
|
32
|
+
b: string;
|
|
33
|
+
u: string;
|
|
34
|
+
p: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type MFunc = (v: string) => Match;
|
|
38
|
+
|
|
39
|
+
function buildMatch(fmt: string): MFunc {
|
|
40
|
+
const pattern = fmt.replace(/([FBUP])\1*/g, m => {
|
|
41
|
+
return `(\\d{${m.length}})`;
|
|
42
|
+
});
|
|
43
|
+
const matcher = new RegExp(`^${pattern}$`);
|
|
44
|
+
|
|
45
|
+
return (value: string): Match => {
|
|
46
|
+
const m = matcher.exec(value);
|
|
47
|
+
|
|
48
|
+
if (!m) {
|
|
49
|
+
return { match: false };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
match: true,
|
|
54
|
+
f: m[1] ?? '',
|
|
55
|
+
b: m[2] ?? '',
|
|
56
|
+
u: m[3] ?? '',
|
|
57
|
+
p: m[4] ?? '',
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function buildMatcher(
|
|
63
|
+
rfmt: string,
|
|
64
|
+
cfmt: string,
|
|
65
|
+
): {
|
|
66
|
+
region: MFunc;
|
|
67
|
+
country: MFunc;
|
|
68
|
+
} {
|
|
69
|
+
return {
|
|
70
|
+
region: buildMatch(rfmt),
|
|
71
|
+
country: buildMatch(cfmt),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const REGION_FORMATS = {
|
|
76
|
+
'DE-BW': buildMatcher('FFBBBUUUUP', '28FF0BBBUUUUP'),
|
|
77
|
+
'DE-BY': buildMatcher('FFFBBBUUUUP', '9FFF0BBBUUUUP'),
|
|
78
|
+
'DE-BE': buildMatcher('FFBBBUUUUP', '11FF0BBBUUUUP'),
|
|
79
|
+
'DE-BB': buildMatcher('0FFBBBUUUUP', '30FF0BBBUUUUP'),
|
|
80
|
+
'DE-HB': buildMatcher('FFBBBUUUUP', '24FF0BBBUUUUP'),
|
|
81
|
+
'DE-HH': buildMatcher('FFBBBUUUUP', '22FF0BBBUUUUP'),
|
|
82
|
+
'DE-HE': buildMatcher('0FFBBBUUUUP', '26FF0BBBUUUUP'),
|
|
83
|
+
'DE-MV': buildMatcher('0FFBBBUUUUP', '40FF0BBBUUUUP'),
|
|
84
|
+
'DE-NI': buildMatcher('FFBBBUUUUP', '23FF0BBBUUUUP'),
|
|
85
|
+
'DE-NW': buildMatcher('FFFBBBBUUUP', '5FFF0BBBBUUUP'),
|
|
86
|
+
'DE-RP': buildMatcher('FFBBBUUUUP', '27FF0BBBUUUUP'),
|
|
87
|
+
'DE-SL': buildMatcher('0FFBBBUUUUP', '10FF0BBBUUUUP'),
|
|
88
|
+
'DE-SN': buildMatcher('2FFBBBUUUUP', '32FF0BBBUUUUP'),
|
|
89
|
+
'DE-ST': buildMatcher('1FFBBBUUUUP', '31FF0BBBUUUUP'),
|
|
90
|
+
'DE-SH': buildMatcher('FFBBBUUUUP', '21FF0BBBUUUUP'),
|
|
91
|
+
'DE-TH': buildMatcher('1FFBBBUUUUP', '41FF0BBBUUUUP'),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
function findMatch(value: string): Match | null {
|
|
95
|
+
let result: Match | null = null;
|
|
96
|
+
|
|
97
|
+
Object.values(REGION_FORMATS).some(({ region, country }) => {
|
|
98
|
+
const rResult = region(value);
|
|
99
|
+
if (rResult.match) {
|
|
100
|
+
result = rResult;
|
|
101
|
+
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
const cResult = country(value);
|
|
105
|
+
if (cResult.match) {
|
|
106
|
+
result = cResult;
|
|
107
|
+
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return false;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const impl: Validator = {
|
|
118
|
+
name: 'German Tax Number',
|
|
119
|
+
localName: 'Steuernummer',
|
|
120
|
+
abbreviation: ' St.-Nr.',
|
|
121
|
+
compact(input: string): string {
|
|
122
|
+
const [value, err] = clean(input);
|
|
123
|
+
|
|
124
|
+
if (err) {
|
|
125
|
+
throw err;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return value;
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
format(input: string): string {
|
|
132
|
+
const [value] = clean(input);
|
|
133
|
+
|
|
134
|
+
const match = findMatch(input);
|
|
135
|
+
|
|
136
|
+
if (!match || !match.match) {
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return `${match.f}/${match.b}/${match.u} ${match.p}`;
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
validate(input: string): ValidateReturn {
|
|
144
|
+
const [value, error] = clean(input);
|
|
145
|
+
|
|
146
|
+
if (error) {
|
|
147
|
+
return { isValid: false, error };
|
|
148
|
+
}
|
|
149
|
+
if (![10, 11, 13].includes(value.length)) {
|
|
150
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
151
|
+
}
|
|
152
|
+
if (!strings.isdigits(value)) {
|
|
153
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Make sure it's the same as a region
|
|
157
|
+
if (findMatch(value) === null) {
|
|
158
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// In the first 10 digits exactly one digit must be repeated two or
|
|
162
|
+
// three times and other digits can appear only once.
|
|
163
|
+
// Starting at 2017, the rule is, that within the first ten digits one number has to
|
|
164
|
+
// appear exactly twice or thrice.
|
|
165
|
+
const counter: Record<string, number> = {};
|
|
166
|
+
|
|
167
|
+
value
|
|
168
|
+
.substring(0, 10)
|
|
169
|
+
.split('')
|
|
170
|
+
.forEach(v => {
|
|
171
|
+
counter[v] = (counter[v] ?? 0) + 1;
|
|
172
|
+
});
|
|
173
|
+
const more = Object.values(counter); // .filter(v => v > 1);
|
|
174
|
+
if (!more.some(v => v === 2 || v === 3)) {
|
|
175
|
+
// if (more.length !== 1 && [2, 3].includes(more[0])) {
|
|
176
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// if (!mod11mod10Validate(value)) {
|
|
180
|
+
// return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
181
|
+
// }
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
isValid: true,
|
|
185
|
+
compact: value,
|
|
186
|
+
isIndividual: false,
|
|
187
|
+
isCompany: true,
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
193
|
+
impl;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { validate, format } from './svnr';
|
|
2
|
+
import {
|
|
3
|
+
InvalidLength,
|
|
4
|
+
InvalidComponent,
|
|
5
|
+
InvalidChecksum,
|
|
6
|
+
} from '../exceptions';
|
|
7
|
+
|
|
8
|
+
describe('de/svnr', () => {
|
|
9
|
+
it('format:15070649C103', () => {
|
|
10
|
+
const result = format('15070649C103');
|
|
11
|
+
expect(result).toEqual('15 070649 C 103');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('validate:15 070649 C 103', () => {
|
|
15
|
+
const result = validate('15 070649 C 103');
|
|
16
|
+
expect(result.isValid && result.compact).toEqual('15070649C103');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('validate:12345678', () => {
|
|
20
|
+
const result = validate('12345678');
|
|
21
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
22
|
+
});
|
|
23
|
+
// // Invalid Area Code
|
|
24
|
+
it('validate:01070649C103', () => {
|
|
25
|
+
const result = validate('01070649C103');
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
27
|
+
});
|
|
28
|
+
// Invalid Birth month (13)
|
|
29
|
+
it('validate:15071349C103', () => {
|
|
30
|
+
const result = validate('15071349C103');
|
|
31
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
32
|
+
});
|
|
33
|
+
// Invalid Checksum
|
|
34
|
+
it('validate:15070649C102', () => {
|
|
35
|
+
const result = validate('15070649C102');
|
|
36
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
37
|
+
});
|
|
38
|
+
describe('invalid component cases', () => {
|
|
39
|
+
it('validate:15JU0649C102', () => {
|
|
40
|
+
const result = validate('15JU0649C102');
|
|
41
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
42
|
+
});
|
|
43
|
+
it('validate:1507064CC102', () => {
|
|
44
|
+
const result = validate('1507064CC102');
|
|
45
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
46
|
+
});
|
|
47
|
+
it('validate:150706499102', () => {
|
|
48
|
+
const result = validate('150706499102');
|
|
49
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
50
|
+
});
|
|
51
|
+
it('validate:15070649CC03', () => {
|
|
52
|
+
const result = validate('15070649CC03');
|
|
53
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
package/src/de/svnr.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SVNR or RVNR (Sozialversicherungsnummer, German social security / pension insurance number).
|
|
3
|
+
*
|
|
4
|
+
* The SVNR (or RVNR) is the German social security / pension insurance number.
|
|
5
|
+
* It's also called a social insuarance number. The number consists of 12 digits.
|
|
6
|
+
*
|
|
7
|
+
* Source
|
|
8
|
+
* https://de.wikipedia.org/wiki/Versicherungsnummer
|
|
9
|
+
* https://allaboutberlin.com/guides/german-versicherungsnummer
|
|
10
|
+
*
|
|
11
|
+
* PERSON
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import * as exceptions from '../exceptions';
|
|
15
|
+
import { strings } from '../util';
|
|
16
|
+
import { weightedSum } from '../util/checksum';
|
|
17
|
+
import { Validator, ValidateReturn } from '../types';
|
|
18
|
+
|
|
19
|
+
const AREA_NUMBER_OPTIONS = [
|
|
20
|
+
'02',
|
|
21
|
+
'03',
|
|
22
|
+
'04',
|
|
23
|
+
'08',
|
|
24
|
+
'09',
|
|
25
|
+
'10',
|
|
26
|
+
'11',
|
|
27
|
+
'12',
|
|
28
|
+
'13',
|
|
29
|
+
'14',
|
|
30
|
+
'15',
|
|
31
|
+
'16',
|
|
32
|
+
'17',
|
|
33
|
+
'18',
|
|
34
|
+
'19',
|
|
35
|
+
'20',
|
|
36
|
+
'21',
|
|
37
|
+
'23',
|
|
38
|
+
'24',
|
|
39
|
+
'25',
|
|
40
|
+
'26',
|
|
41
|
+
'28',
|
|
42
|
+
'29',
|
|
43
|
+
'38',
|
|
44
|
+
'39',
|
|
45
|
+
'40',
|
|
46
|
+
'80',
|
|
47
|
+
'81',
|
|
48
|
+
'82',
|
|
49
|
+
'89',
|
|
50
|
+
].concat([...Array(79 - 42 + 1).keys()].map(x => (x + 42).toString())); // '42'-'79'
|
|
51
|
+
|
|
52
|
+
const BIRTH_MONTH_OPTIONS = [
|
|
53
|
+
'01',
|
|
54
|
+
'02',
|
|
55
|
+
'03',
|
|
56
|
+
'04',
|
|
57
|
+
'05',
|
|
58
|
+
'06',
|
|
59
|
+
'07',
|
|
60
|
+
'08',
|
|
61
|
+
'09',
|
|
62
|
+
'10',
|
|
63
|
+
'11',
|
|
64
|
+
'12',
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const checkAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
68
|
+
const checkAlphabetDict: Record<string, number> = checkAlphabet
|
|
69
|
+
.split('')
|
|
70
|
+
.reduce(
|
|
71
|
+
(acc, c, idx) => ({
|
|
72
|
+
...acc,
|
|
73
|
+
[c]: String(idx + 1).padStart(2, '0'),
|
|
74
|
+
}),
|
|
75
|
+
{},
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
79
|
+
return strings.cleanUnicode(input, ' -./,');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const impl: Validator = {
|
|
83
|
+
name: 'German Pension Insurance Number',
|
|
84
|
+
localName: 'Sozialversicherungsnummer',
|
|
85
|
+
abbreviation: 'SVNR',
|
|
86
|
+
compact(input: string): string {
|
|
87
|
+
const [value, err] = clean(input);
|
|
88
|
+
|
|
89
|
+
if (err) {
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return value;
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
format(input: string): string {
|
|
97
|
+
const [value] = clean(input);
|
|
98
|
+
|
|
99
|
+
return strings.splitAt(value, 2, 8, 9).join(' ');
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
validate(input: string): ValidateReturn {
|
|
103
|
+
const [value, error] = clean(input);
|
|
104
|
+
|
|
105
|
+
if (error) {
|
|
106
|
+
return { isValid: false, error };
|
|
107
|
+
}
|
|
108
|
+
if (value.length !== 12) {
|
|
109
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
110
|
+
}
|
|
111
|
+
if (!strings.isalphanumeric(value)) {
|
|
112
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
113
|
+
}
|
|
114
|
+
if (!AREA_NUMBER_OPTIONS.includes(value.substring(0, 2))) {
|
|
115
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
116
|
+
}
|
|
117
|
+
if (!strings.isdigits(value.substring(2, 4))) {
|
|
118
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
119
|
+
}
|
|
120
|
+
if (!BIRTH_MONTH_OPTIONS.includes(value.substring(4, 6))) {
|
|
121
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
122
|
+
}
|
|
123
|
+
if (!strings.isdigits(value.substring(6, 8))) {
|
|
124
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
125
|
+
}
|
|
126
|
+
if (!strings.isalpha(value[8])) {
|
|
127
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
128
|
+
}
|
|
129
|
+
if (!strings.isdigits(value.substring(9, 11))) {
|
|
130
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const [frontWithAlpha, check] = strings.splitAt(value, 11);
|
|
134
|
+
const front = frontWithAlpha
|
|
135
|
+
.split('')
|
|
136
|
+
.map(c => checkAlphabetDict[c] ?? c)
|
|
137
|
+
.join('');
|
|
138
|
+
const sum = weightedSum(front, {
|
|
139
|
+
weights: [2, 1, 2, 5, 7, 1, 2, 1, 2, 1, 2, 1],
|
|
140
|
+
modulus: 10,
|
|
141
|
+
sumByDigit: true,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
if (String(sum % 10) !== check) {
|
|
145
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
isValid: true,
|
|
150
|
+
compact: value,
|
|
151
|
+
isIndividual: true,
|
|
152
|
+
isCompany: false,
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
158
|
+
impl;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { validate, format } from './vat';
|
|
2
|
+
import { InvalidLength, InvalidChecksum } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('de/vat', () => {
|
|
5
|
+
it('format:DE 136,695 976', () => {
|
|
6
|
+
const result = format('DE 136,695 976');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('136695976');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:DE136695976', () => {
|
|
12
|
+
const result = validate('DE136695976');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('136695976');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:12345678', () => {
|
|
18
|
+
const result = validate('12345678');
|
|
19
|
+
|
|
20
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:136695978', () => {
|
|
24
|
+
const result = validate('136695978');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
27
|
+
});
|
|
28
|
+
});
|
package/src/de/vat.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ust ID Nr. (Umsatzsteuer Identifikationsnummer, German VAT number).
|
|
3
|
+
*
|
|
4
|
+
* The number is 10 digits long and uses the ISO 7064 Mod 11, 10 check digit
|
|
5
|
+
* algorithm.
|
|
6
|
+
*
|
|
7
|
+
* ENTITY
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as exceptions from '../exceptions';
|
|
11
|
+
import { strings } from '../util';
|
|
12
|
+
import { Validator, ValidateReturn } from '../types';
|
|
13
|
+
import { iso7064mod10x11validate } from '../util/iso7064';
|
|
14
|
+
|
|
15
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
16
|
+
const [value, err] = strings.cleanUnicode(input, ' -./,');
|
|
17
|
+
if (err !== null) {
|
|
18
|
+
return [value, err];
|
|
19
|
+
}
|
|
20
|
+
if (value.startsWith('DE')) {
|
|
21
|
+
return [value.substr(2), null];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return [value, null];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const impl: Validator = {
|
|
28
|
+
name: 'German VAT Number',
|
|
29
|
+
localName: 'Umsatzsteuer Identifikationsnummer',
|
|
30
|
+
abbreviation: 'USt ID Nr.',
|
|
31
|
+
compact(input: string): string {
|
|
32
|
+
const [value, err] = clean(input);
|
|
33
|
+
|
|
34
|
+
if (err) {
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return value;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
format(input: string): string {
|
|
42
|
+
const [value] = clean(input);
|
|
43
|
+
|
|
44
|
+
return value;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
validate(input: string): ValidateReturn {
|
|
48
|
+
const [value, error] = clean(input);
|
|
49
|
+
|
|
50
|
+
if (error) {
|
|
51
|
+
return { isValid: false, error };
|
|
52
|
+
}
|
|
53
|
+
if (value.length !== 9) {
|
|
54
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
55
|
+
}
|
|
56
|
+
if (!strings.isdigits(value)) {
|
|
57
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!iso7064mod10x11validate(value)) {
|
|
61
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
isValid: true,
|
|
66
|
+
compact: value,
|
|
67
|
+
isIndividual: false,
|
|
68
|
+
isCompany: true,
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
74
|
+
impl;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { InvalidComponent } from '../exceptions';
|
|
2
|
+
import { format, getBirthDate, validate } from './cpr';
|
|
3
|
+
|
|
4
|
+
describe('dk/cpr', () => {
|
|
5
|
+
it('format:2110625629', () => {
|
|
6
|
+
const result = format('2110625629');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('211062-5629');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('getBirthDate("511062-0629")', () => {
|
|
12
|
+
expect(() => {
|
|
13
|
+
getBirthDate('511062-0629');
|
|
14
|
+
}).toThrow(InvalidComponent);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('getBirthDate("010180-1234")', () => {
|
|
18
|
+
const result = validate('010180-1234');
|
|
19
|
+
|
|
20
|
+
expect(result.isValid).toEqual(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate wrong date', () => {
|
|
24
|
+
const result = validate('511062-5629');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('validate future date', () => {
|
|
30
|
+
const result = validate('2110525629');
|
|
31
|
+
|
|
32
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
33
|
+
});
|
|
34
|
+
});
|
package/src/dk/cpr.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CPR (personnummer, the Danish citizen number).
|
|
3
|
+
*
|
|
4
|
+
* The CPR is the national number to identify Danish citizens and is stored in
|
|
5
|
+
* the Det Centrale Personregister (Civil Registration System). The number
|
|
6
|
+
* consists of 10 digits in the format DDMMYY-SSSS where the first part
|
|
7
|
+
* represents the birth date and the second a sequence number. The first digit
|
|
8
|
+
* of the sequence number indicates the century.
|
|
9
|
+
*
|
|
10
|
+
* The numbers used to validate using a checksum but since the sequence numbers
|
|
11
|
+
* ran out this was abandoned in 2007. It is also not possible to use the
|
|
12
|
+
* checksum only for numbers that have a birth date before that because the
|
|
13
|
+
* numbers are also assigned to immigrants.
|
|
14
|
+
*
|
|
15
|
+
* More information:
|
|
16
|
+
*
|
|
17
|
+
* https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
|
|
18
|
+
* https://da.wikipedia.org/wiki/CPR-nummer
|
|
19
|
+
* https://cpr.dk/
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import * as exceptions from '../exceptions';
|
|
23
|
+
import { isValidDate, buildDate, validBirthdate, strings } from '../util';
|
|
24
|
+
import { Validator, ValidateReturn } from '../types';
|
|
25
|
+
|
|
26
|
+
export function getBirthDate(value: string): Date {
|
|
27
|
+
const [dob] = strings.splitAt(value, 6);
|
|
28
|
+
const [day, month, yearStr] = strings.splitAt(dob, 2, 4);
|
|
29
|
+
|
|
30
|
+
let year = parseInt(yearStr);
|
|
31
|
+
|
|
32
|
+
if ('5678'.includes(value[6]) && year >= 58) {
|
|
33
|
+
year += 1800;
|
|
34
|
+
} else if (
|
|
35
|
+
'0123'.includes(value[6]) ||
|
|
36
|
+
('49'.includes(value[6]) && year >= 37)
|
|
37
|
+
) {
|
|
38
|
+
year += 1900;
|
|
39
|
+
} else {
|
|
40
|
+
year += 2000;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const d = buildDate(String(year), month, day);
|
|
44
|
+
|
|
45
|
+
if (d === null || !isValidDate(String(year), month, day)) {
|
|
46
|
+
throw new exceptions.InvalidComponent(
|
|
47
|
+
'The number does not contain valid birth date information.',
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return d;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
55
|
+
const [value, err] = strings.cleanUnicode(input, ' -');
|
|
56
|
+
if (err !== null) {
|
|
57
|
+
return [value, err];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return [value, null];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const impl: Validator = {
|
|
64
|
+
name: 'Danish Citizen Number',
|
|
65
|
+
localName: 'Personnummer',
|
|
66
|
+
abbreviation: 'CPR',
|
|
67
|
+
compact(input: string): string {
|
|
68
|
+
const [value, err] = clean(input);
|
|
69
|
+
|
|
70
|
+
if (err) {
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return value;
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
format(input: string): string {
|
|
78
|
+
const [value] = clean(input);
|
|
79
|
+
|
|
80
|
+
return strings.splitAt(value, 6).join('-');
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
validate(input: string): ValidateReturn {
|
|
84
|
+
const [value, error] = clean(input);
|
|
85
|
+
|
|
86
|
+
if (error) {
|
|
87
|
+
return { isValid: false, error };
|
|
88
|
+
}
|
|
89
|
+
if (!strings.isdigits(value)) {
|
|
90
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
91
|
+
}
|
|
92
|
+
if (value.length !== 10) {
|
|
93
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
const date = getBirthDate(value);
|
|
98
|
+
if (!validBirthdate(date)) {
|
|
99
|
+
return {
|
|
100
|
+
isValid: false,
|
|
101
|
+
error: new exceptions.InvalidComponent(
|
|
102
|
+
'The birth date information is valid, but this person has not been born yet.',
|
|
103
|
+
),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
} catch (err) {
|
|
107
|
+
if (err instanceof exceptions.ValidationError) {
|
|
108
|
+
return {
|
|
109
|
+
isValid: false,
|
|
110
|
+
error: err,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
isValid: false,
|
|
115
|
+
error: new exceptions.InvalidComponent(String(err)),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
isValid: true,
|
|
121
|
+
compact: value,
|
|
122
|
+
isIndividual: true,
|
|
123
|
+
isCompany: false,
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
129
|
+
impl;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { validate, format } from './cvr';
|
|
2
|
+
import { InvalidLength, InvalidChecksum } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('dk/cvr', () => {
|
|
5
|
+
it('format:DK 13585628', () => {
|
|
6
|
+
const result = format('DK 13585628');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('13585628');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:DK 13585628', () => {
|
|
12
|
+
const result = validate('DK 13585628');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('13585628');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:1234567', () => {
|
|
18
|
+
const result = validate('1234567');
|
|
19
|
+
|
|
20
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:DK 13585627', () => {
|
|
24
|
+
const result = validate('DK 13585627');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
27
|
+
});
|
|
28
|
+
});
|