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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passport (German passport number).
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Source
|
|
6
|
+
* https://learn.microsoft.com/en-us/microsoft-365/compliance/sit-defn-germany-passport-number?view=o365-worldwide
|
|
7
|
+
* https://en.wikipedia.org/wiki/German_passport
|
|
8
|
+
* https://www.bmi.bund.de/SharedDocs/downloads/DE/veroeffentlichungen/themen/moderne-verwaltung/ausweise/personalausweis-seriennummer.pdf?__blob=publicationFile&v=15
|
|
9
|
+
*
|
|
10
|
+
* PERSON
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import * as exceptions from '../exceptions';
|
|
14
|
+
import { strings, weightedSum } from '../util';
|
|
15
|
+
import { Validator, ValidateReturn } from '../types';
|
|
16
|
+
|
|
17
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
18
|
+
return strings.cleanUnicode(input, ' -./,');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const idRegexp = /([CFGHJK][0-9CFGHJKLMNPRTVWXYZ]{8})([0-9]?)[A-Z]?/;
|
|
22
|
+
|
|
23
|
+
const impl: Validator = {
|
|
24
|
+
name: 'German Passport Number',
|
|
25
|
+
localName: 'Ausweisen',
|
|
26
|
+
abbreviation: 'Passport',
|
|
27
|
+
|
|
28
|
+
compact(input: string): string {
|
|
29
|
+
const [value, err] = clean(input);
|
|
30
|
+
|
|
31
|
+
if (err) {
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return value;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
format(input: string): string {
|
|
39
|
+
const [value] = clean(input);
|
|
40
|
+
|
|
41
|
+
return value;
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
validate(input: string): ValidateReturn {
|
|
45
|
+
const [value, error] = clean(input);
|
|
46
|
+
|
|
47
|
+
if (error) {
|
|
48
|
+
return { isValid: false, error };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (value.length < 9 || value.length > 11) {
|
|
52
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
53
|
+
}
|
|
54
|
+
const match = value.match(idRegexp);
|
|
55
|
+
if (!match) {
|
|
56
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Checksum is optional -- present in the matchine readable form, not in the human
|
|
60
|
+
if (match[2] !== '') {
|
|
61
|
+
const [issue, issueCheck] = [match[1], match[2]];
|
|
62
|
+
|
|
63
|
+
const issueSum = weightedSum(issue, {
|
|
64
|
+
weights: [7, 3, 1],
|
|
65
|
+
modulus: 10,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (String(issueSum) !== issueCheck) {
|
|
69
|
+
return {
|
|
70
|
+
isValid: false,
|
|
71
|
+
error: new exceptions.InvalidChecksum('issue.checksum'),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
isValid: true,
|
|
78
|
+
compact: value,
|
|
79
|
+
isIndividual: true,
|
|
80
|
+
isCompany: false,
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
86
|
+
impl;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { validate, format } from './pwnr';
|
|
2
|
+
import { InvalidLength, InvalidChecksum } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('de/pwnr', () => {
|
|
5
|
+
it('format:T22000129364081252010315D4', () => {
|
|
6
|
+
const result = format('T22000129364081252010315D4');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('T220001293 6408125 2010315 D 4');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('format:1220001297D640812517103198', () => {
|
|
12
|
+
const result = format('1220001297D640812517103198');
|
|
13
|
+
|
|
14
|
+
expect(result).toEqual('1220001297 6408125 1710319 D 8');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test.each([
|
|
18
|
+
'240605568468102030705109D6',
|
|
19
|
+
'2406055684-6810203-0705109-D-6',
|
|
20
|
+
'T22000129364081252010315D4',
|
|
21
|
+
'1220001297D640812517103198',
|
|
22
|
+
'1220001297D640812517103198',
|
|
23
|
+
'1220001297D 6408125 1710319 8',
|
|
24
|
+
])('validate:%s', value => {
|
|
25
|
+
const result = validate(value);
|
|
26
|
+
|
|
27
|
+
expect(result.isValid).toEqual(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test.each([
|
|
31
|
+
'2406055684',
|
|
32
|
+
'2406055684d',
|
|
33
|
+
'2406055684D',
|
|
34
|
+
'T220001293D',
|
|
35
|
+
'T220001293',
|
|
36
|
+
'L01X00T471',
|
|
37
|
+
])('validate:%s', value => {
|
|
38
|
+
const result = validate(value);
|
|
39
|
+
|
|
40
|
+
expect(result.isValid).toEqual(true);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('validate:T220001293 6408125 2010315D 4', () => {
|
|
44
|
+
const result = validate('T220001293 6408125 2010315D 4');
|
|
45
|
+
|
|
46
|
+
expect(result.isValid && result.compact).toEqual(
|
|
47
|
+
'T22000129364081252010315D4',
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('validate:T22000129364081252010315D', () => {
|
|
52
|
+
const result = validate('T22000129364081252010315D');
|
|
53
|
+
|
|
54
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('validate:T22000129364081252010315D9', () => {
|
|
58
|
+
const result = validate('T22000129364081252010315D9');
|
|
59
|
+
|
|
60
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
61
|
+
});
|
|
62
|
+
});
|
package/src/de/pwnr.ts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PwNr (Personalausweisnummer, German personal identity card number).
|
|
3
|
+
*
|
|
4
|
+
* The identity card of the Federal Republic of Germany is an official document as proof of
|
|
5
|
+
* identity for German nationals. In principle, the identity card authority responsible for
|
|
6
|
+
* the main residence assigns it at the request of the citizen.
|
|
7
|
+
*
|
|
8
|
+
* Source
|
|
9
|
+
* https://de.wikipedia.org/wiki/Personalausweis_(Deutschland)
|
|
10
|
+
* http://www.pruefziffernberechnung.de/P/Personalausweis-DE.shtml
|
|
11
|
+
* https://learn.microsoft.com/en-us/microsoft-365/compliance/sit-defn-germany-identity-card-number?view=o365-worldwide
|
|
12
|
+
* http://www.pruefziffernberechnung.de/Begleitdokumente/BKZ.shtml
|
|
13
|
+
*
|
|
14
|
+
* PERSON
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import * as exceptions from '../exceptions';
|
|
18
|
+
import { strings, isValidDateCompactYYMMDD, weightedSum } from '../util';
|
|
19
|
+
import { Validator, ValidateReturn } from '../types';
|
|
20
|
+
|
|
21
|
+
const oldRegex = /^([0-9CFGHJKLMNPRTVWXYZ]{9})([0-9])[A-Z]?$/;
|
|
22
|
+
|
|
23
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
24
|
+
const [value, err] = strings.cleanUnicode(input, ' -./,');
|
|
25
|
+
|
|
26
|
+
if (err) {
|
|
27
|
+
return [value, err];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Old format IDs had the national code at position 11 new format has them at 24
|
|
31
|
+
if (value.length >= 25 && /[A-Z]/.test(value[10])) {
|
|
32
|
+
const [p1, p2, p3, p4] = strings.splitAt(value, 10, 11, 25);
|
|
33
|
+
|
|
34
|
+
return [p1 + p3 + p2 + p4, err];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return [value, err];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function validateIssue(value: string): ValidateReturn {
|
|
41
|
+
const match = value.match(oldRegex);
|
|
42
|
+
if (!match) {
|
|
43
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const [issue, issueCheck] = [match[1], match[2]];
|
|
47
|
+
|
|
48
|
+
const issueSum = weightedSum(issue, {
|
|
49
|
+
weights: [7, 3, 1],
|
|
50
|
+
modulus: 10,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (String(issueSum) !== issueCheck) {
|
|
54
|
+
return {
|
|
55
|
+
isValid: false,
|
|
56
|
+
error: new exceptions.InvalidChecksum('issue.checksum'),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
isValid: true,
|
|
62
|
+
compact: value,
|
|
63
|
+
isIndividual: true,
|
|
64
|
+
isCompany: false,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function validateNew(value: string): ValidateReturn {
|
|
69
|
+
if (
|
|
70
|
+
!/^[0-9CFGHJKLMNPRTVWXYZ][0-9CFGHJKLMNPRTVWXYZ]+[A-Z][0-9]$/.test(value)
|
|
71
|
+
) {
|
|
72
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const [
|
|
76
|
+
issue,
|
|
77
|
+
issueCheck,
|
|
78
|
+
birth,
|
|
79
|
+
birthCheck,
|
|
80
|
+
expiry,
|
|
81
|
+
expiryCheck,
|
|
82
|
+
nationality,
|
|
83
|
+
checksum,
|
|
84
|
+
] = strings.splitAt(value, 9, 10, 16, 17, 23, 24, 25);
|
|
85
|
+
|
|
86
|
+
if (!isValidDateCompactYYMMDD(birth, true)) {
|
|
87
|
+
return {
|
|
88
|
+
isValid: false,
|
|
89
|
+
error: new exceptions.InvalidComponent('birthdate'),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (!isValidDateCompactYYMMDD(expiry)) {
|
|
93
|
+
return {
|
|
94
|
+
isValid: false,
|
|
95
|
+
error: new exceptions.InvalidComponent('expiry'),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (!/^[A-Z]$/.test(nationality)) {
|
|
99
|
+
return {
|
|
100
|
+
isValid: false,
|
|
101
|
+
error: new exceptions.InvalidComponent('nationality'),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// The hope is that the issue information grows better
|
|
106
|
+
// checks over time and should be a shared function
|
|
107
|
+
const res = validateIssue(issue + issueCheck);
|
|
108
|
+
if (res.isValid === false) {
|
|
109
|
+
return res;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const birthSum = weightedSum(birth, {
|
|
113
|
+
weights: [7, 3, 1],
|
|
114
|
+
modulus: 10,
|
|
115
|
+
});
|
|
116
|
+
const expirySum = weightedSum(expiry, {
|
|
117
|
+
weights: [7, 3, 1],
|
|
118
|
+
modulus: 10,
|
|
119
|
+
});
|
|
120
|
+
if (String(birthSum) !== birthCheck) {
|
|
121
|
+
return {
|
|
122
|
+
isValid: false,
|
|
123
|
+
error: new exceptions.InvalidChecksum('birth.checksum'),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (String(expirySum) !== expiryCheck) {
|
|
128
|
+
return {
|
|
129
|
+
isValid: false,
|
|
130
|
+
error: new exceptions.InvalidChecksum('expiry.checksum'),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const sum = weightedSum(value.substring(0, 24), {
|
|
135
|
+
weights: [7, 3, 1],
|
|
136
|
+
modulus: 10,
|
|
137
|
+
});
|
|
138
|
+
if (String(sum) !== checksum) {
|
|
139
|
+
return {
|
|
140
|
+
isValid: false,
|
|
141
|
+
error: new exceptions.InvalidChecksum('checksum'),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
isValid: true,
|
|
147
|
+
compact: value,
|
|
148
|
+
isIndividual: true,
|
|
149
|
+
isCompany: false,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const impl: Validator = {
|
|
154
|
+
name: 'German Personalausweisnummer',
|
|
155
|
+
localName: 'Personalausweisnummer',
|
|
156
|
+
abbreviation: 'PwNr',
|
|
157
|
+
compact(input: string): string {
|
|
158
|
+
const [value, err] = clean(input);
|
|
159
|
+
|
|
160
|
+
if (err) {
|
|
161
|
+
throw err;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return value;
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
format(input: string): string {
|
|
168
|
+
const [value] = clean(input);
|
|
169
|
+
|
|
170
|
+
return strings.splitAt(value, 10, 17, 24, 25).join(' ');
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
validate(input: string): ValidateReturn {
|
|
174
|
+
const [value, error] = clean(input);
|
|
175
|
+
|
|
176
|
+
if (error) {
|
|
177
|
+
return { isValid: false, error };
|
|
178
|
+
}
|
|
179
|
+
if (value.length === 26) {
|
|
180
|
+
return validateNew(value);
|
|
181
|
+
} else if (value.length === 10 || value.length === 11) {
|
|
182
|
+
return validateIssue(value);
|
|
183
|
+
} else {
|
|
184
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
190
|
+
impl;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { validate, format } from './stnr';
|
|
2
|
+
import { InvalidComponent, InvalidFormat, InvalidLength } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('de/stnr', () => {
|
|
5
|
+
it('format:18181508155', () => {
|
|
6
|
+
const result = format('18181508155');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('181/815/0815 5');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:10863924976', () => {
|
|
12
|
+
const result = validate('10863924976');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('10863924976');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:36574261809', () => {
|
|
18
|
+
const result = validate('36574261809');
|
|
19
|
+
|
|
20
|
+
expect(result.isValid && result.compact).toEqual('36574261809');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:136695978', () => {
|
|
24
|
+
const result = validate('136695978');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('validate:121/5752/5373', () => {
|
|
30
|
+
const result = validate('121/5752/5373');
|
|
31
|
+
|
|
32
|
+
expect(result.isValid && result.compact).toEqual('12157525373');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('validate:14/203/31601', () => {
|
|
36
|
+
const result = validate('14/203/31601');
|
|
37
|
+
|
|
38
|
+
expect(result.isValid && result.compact).toEqual('1420331601');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// it('validate:36574261808', () => {
|
|
42
|
+
// const result = validate('36574261808');
|
|
43
|
+
|
|
44
|
+
// expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
45
|
+
// });
|
|
46
|
+
|
|
47
|
+
it('validate:1234567890', () => {
|
|
48
|
+
const result = validate('1234567890');
|
|
49
|
+
|
|
50
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('validate:0472480661811', () => {
|
|
54
|
+
const result = validate('0472480661811');
|
|
55
|
+
|
|
56
|
+
expect(result.error).toBeInstanceOf(InvalidFormat);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Test coverage from
|
|
60
|
+
// https://de.wikipedia.org/wiki/Steuernummer
|
|
61
|
+
// -- Turns out these are not valid numbers
|
|
62
|
+
|
|
63
|
+
// test.each([
|
|
64
|
+
// '93815/08152',
|
|
65
|
+
// '181/815/08155',
|
|
66
|
+
// '21/815/08150',
|
|
67
|
+
// '48/815/08155',
|
|
68
|
+
// '75 815 08152',
|
|
69
|
+
// '02/815/08156',
|
|
70
|
+
// '013 815 08153',
|
|
71
|
+
// '79/815/08151',
|
|
72
|
+
// '24/815/08151',
|
|
73
|
+
// '133/8150/8159',
|
|
74
|
+
// '22/815/08154',
|
|
75
|
+
// '10/815/08182',
|
|
76
|
+
// '201/123/12340',
|
|
77
|
+
// '101/815/08154',
|
|
78
|
+
// '29/815/08158 ',
|
|
79
|
+
// '151/815/08156',
|
|
80
|
+
// ])('stnr(%s)', num => {
|
|
81
|
+
// const result = validate(num);
|
|
82
|
+
|
|
83
|
+
// expect(result.isValid).toEqual(true);
|
|
84
|
+
// });
|
|
85
|
+
});
|
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
|
+
});
|