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,28 @@
|
|
|
1
|
+
import { validate, format } from './orgnr';
|
|
2
|
+
import { InvalidLength, InvalidChecksum } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('se/orgnr', () => {
|
|
5
|
+
it('format:1234567897', () => {
|
|
6
|
+
const result = format('1234567897');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('123456-7897');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:1234567897', () => {
|
|
12
|
+
const result = validate('1234567897');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('1234567897');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:12345678', () => {
|
|
18
|
+
const result = validate('12345678');
|
|
19
|
+
|
|
20
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:1234567891', () => {
|
|
24
|
+
const result = validate('1234567891');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
27
|
+
});
|
|
28
|
+
});
|
package/src/se/orgnr.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orgnr (Organisationsnummer, Swedish company number).
|
|
3
|
+
*
|
|
4
|
+
* The Orgnr (Organisationsnummer) is the national number to identify Swedish
|
|
5
|
+
* companies and consists of 10 digits. These are the first 10 digits in the
|
|
6
|
+
* Swedish VAT number, i.e. it's the VAT number without the 'SE' in front and
|
|
7
|
+
* the '01' at the end.
|
|
8
|
+
*
|
|
9
|
+
* ENTITY
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import * as exceptions from '../exceptions';
|
|
13
|
+
import { strings } from '../util';
|
|
14
|
+
import { Validator, ValidateReturn } from '../types';
|
|
15
|
+
import { luhnChecksumValidate } from '../util/checksum';
|
|
16
|
+
|
|
17
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
18
|
+
return strings.cleanUnicode(input, ' -.');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const impl: Validator = {
|
|
22
|
+
name: 'Swedish Company Number',
|
|
23
|
+
localName: 'Organisationsnummer',
|
|
24
|
+
abbreviation: 'Orgnr',
|
|
25
|
+
compact(input: string): string {
|
|
26
|
+
const [value, err] = clean(input);
|
|
27
|
+
|
|
28
|
+
if (err) {
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return value;
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
format(input: string): string {
|
|
36
|
+
const [value] = clean(input);
|
|
37
|
+
|
|
38
|
+
return strings.splitAt(value, -4).join('-');
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
validate(input: string): ValidateReturn {
|
|
42
|
+
const [value, error] = clean(input);
|
|
43
|
+
|
|
44
|
+
if (error) {
|
|
45
|
+
return { isValid: false, error };
|
|
46
|
+
}
|
|
47
|
+
if (value.length !== 10) {
|
|
48
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
49
|
+
}
|
|
50
|
+
if (!strings.isdigits(value)) {
|
|
51
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!luhnChecksumValidate(value)) {
|
|
55
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
isValid: true,
|
|
60
|
+
compact: value,
|
|
61
|
+
isIndividual: false,
|
|
62
|
+
isCompany: true,
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
68
|
+
impl;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { validate, format } from './personnummer';
|
|
2
|
+
import { InvalidLength, InvalidChecksum } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('se/personnummer', () => {
|
|
5
|
+
test.each([
|
|
6
|
+
['8803200017', '880320-0017'], // no hyphen assume young person
|
|
7
|
+
['880320-0017', '880320-0017'], // standard format
|
|
8
|
+
['880320+0017', '880320+0017'], // standard format, person over 100
|
|
9
|
+
['19200901-0000', '200901+0000'], // 4digit year, hypen that's useless person over 100
|
|
10
|
+
['192009010000', '200901+0000'], // 4digit year, no hyphen, person over 100
|
|
11
|
+
['20200901-0000', '200901-0000'], // 4digit year, hyphen
|
|
12
|
+
['202009010000', '200901-0000'], // 4digit year, no hyphen
|
|
13
|
+
])('format:%s', (given, want) => {
|
|
14
|
+
const result = format(given);
|
|
15
|
+
|
|
16
|
+
expect(result).toEqual(want);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('validate:880320-0016', () => {
|
|
20
|
+
const result = validate('880320-0016');
|
|
21
|
+
|
|
22
|
+
expect(result.isValid && result.compact).toEqual('880320-0016');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test.each(['811228-9874', '670919-9530', '11900102-2384'])(
|
|
26
|
+
'validate:%s',
|
|
27
|
+
value => {
|
|
28
|
+
const result = validate(value);
|
|
29
|
+
|
|
30
|
+
expect(result.isValid).toEqual(true);
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
it('validate:12345678', () => {
|
|
35
|
+
const result = validate('12345678');
|
|
36
|
+
|
|
37
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('validate:880320-0018', () => {
|
|
41
|
+
const result = validate('880320-0018');
|
|
42
|
+
|
|
43
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personnummer (Swedish personal identity number).
|
|
3
|
+
*
|
|
4
|
+
* The Swedish Personnummer is assigned at birth to all Swedish nationals and to
|
|
5
|
+
* immigrants for tax and identification purposes. The number consists of 10 or
|
|
6
|
+
* 12 digits and starts with the birth date, followed by a serial and a check
|
|
7
|
+
* digit.
|
|
8
|
+
*
|
|
9
|
+
* Source:
|
|
10
|
+
* https://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
|
|
11
|
+
*
|
|
12
|
+
* PERSON
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import * as exceptions from '../exceptions';
|
|
16
|
+
import { isValidDateCompactYYYYMMDD, buildDate, strings } from '../util';
|
|
17
|
+
import { Validator, ValidateReturn } from '../types';
|
|
18
|
+
import { luhnChecksumValidate } from '../util/checksum';
|
|
19
|
+
|
|
20
|
+
const ONE_HUNDRED_YEARS_IN_MS = 100 * 365 * 24 * 60 * 60 * 1_000;
|
|
21
|
+
|
|
22
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
23
|
+
const [value, err] = strings.cleanUnicode(input, ' :');
|
|
24
|
+
|
|
25
|
+
if (err) {
|
|
26
|
+
return [value, err];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const [a, b, c] = strings.splitAt(value, -5, -4);
|
|
30
|
+
|
|
31
|
+
return [`${a.replace(/[-+]/g, '')}${b}${c}`, null];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function formatImpl(input: string): string {
|
|
35
|
+
const [value] = clean(input);
|
|
36
|
+
|
|
37
|
+
let front,
|
|
38
|
+
back,
|
|
39
|
+
sep = '-';
|
|
40
|
+
|
|
41
|
+
if (value.length === 12 || value.length === 13) {
|
|
42
|
+
const [yyyy, mm, dd] = strings.splitAt(value, 0, 4, 6, 8);
|
|
43
|
+
|
|
44
|
+
const d = buildDate(yyyy, mm, dd);
|
|
45
|
+
if (d === null) {
|
|
46
|
+
// bad date :(
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (new Date().getTime() - d.getTime() > ONE_HUNDRED_YEARS_IN_MS) {
|
|
51
|
+
sep = '+';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
front = `${yyyy.substring(2)}${mm}${dd}`;
|
|
55
|
+
|
|
56
|
+
back = value.substring(value.length - 4);
|
|
57
|
+
} else if (value.length === 10) {
|
|
58
|
+
front = value.substring(0, 6);
|
|
59
|
+
back = value.substring(6);
|
|
60
|
+
} else if (value.length === 11) {
|
|
61
|
+
front = value.substring(0, 6);
|
|
62
|
+
sep = value[6];
|
|
63
|
+
back = value.substring(7);
|
|
64
|
+
} else {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return `${front}${sep}${back}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const impl: Validator = {
|
|
72
|
+
name: 'Swedish Personal Identity Number',
|
|
73
|
+
localName: 'Personnummer',
|
|
74
|
+
compact(input: string): string {
|
|
75
|
+
const [value, err] = clean(input);
|
|
76
|
+
|
|
77
|
+
if (err) {
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return value;
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
format: formatImpl,
|
|
85
|
+
|
|
86
|
+
validate(input: string): ValidateReturn {
|
|
87
|
+
const [value, error] = clean(input);
|
|
88
|
+
|
|
89
|
+
if (error) {
|
|
90
|
+
return { isValid: false, error };
|
|
91
|
+
}
|
|
92
|
+
let a, b, c;
|
|
93
|
+
if (value.length === 11) {
|
|
94
|
+
[a, b, c] = strings.splitAt(value, -5, -4);
|
|
95
|
+
} else if (value.length === 13) {
|
|
96
|
+
[, a, b, c] = strings.splitAt(value, -11, -5, -4);
|
|
97
|
+
} else {
|
|
98
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
99
|
+
}
|
|
100
|
+
if (!'-+'.includes(b)) {
|
|
101
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
102
|
+
}
|
|
103
|
+
const digits = `${a}${c}`;
|
|
104
|
+
if (!strings.isdigits(digits)) {
|
|
105
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let yyyymmdd;
|
|
109
|
+
if (value.length === 13) {
|
|
110
|
+
yyyymmdd = value.substring(0, 8);
|
|
111
|
+
} else {
|
|
112
|
+
const yymmdd = value.substring(0, 6);
|
|
113
|
+
const year = new Date().getFullYear();
|
|
114
|
+
let century = Math.floor(year / 100);
|
|
115
|
+
|
|
116
|
+
if (parseInt(yymmdd.substring(0, 2), 10) > year % 100) {
|
|
117
|
+
century -= 1;
|
|
118
|
+
}
|
|
119
|
+
if (b === '+') {
|
|
120
|
+
century -= 1;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
yyyymmdd = `${century}${yymmdd}`;
|
|
124
|
+
}
|
|
125
|
+
if (!isValidDateCompactYYYYMMDD(yyyymmdd, true)) {
|
|
126
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!luhnChecksumValidate(digits)) {
|
|
130
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
isValid: true,
|
|
135
|
+
compact: formatImpl(input),
|
|
136
|
+
isIndividual: true,
|
|
137
|
+
isCompany: false,
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
143
|
+
impl;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { validate, format } from './vat';
|
|
2
|
+
import { InvalidLength, InvalidChecksum } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('se/vat', () => {
|
|
5
|
+
it('format:SE 123456789701', () => {
|
|
6
|
+
const result = format('SE 123456789701');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('123456789701');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:SE 123456789701', () => {
|
|
12
|
+
const result = validate('SE 123456789701');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('123456789701');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:12345678', () => {
|
|
18
|
+
const result = validate('12345678');
|
|
19
|
+
|
|
20
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:SE 123456789101', () => {
|
|
24
|
+
const result = validate('SE 123456789101');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
27
|
+
});
|
|
28
|
+
});
|
package/src/se/vat.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VAT (Moms, Mervärdesskatt, Swedish VAT number).
|
|
3
|
+
*
|
|
4
|
+
* The Momsregistreringsnummer is used for VAT (Moms, Mervärdesskatt) purposes
|
|
5
|
+
* and consists of 12 digits of which the last two should be 01. The first 10
|
|
6
|
+
* digits should have a valid Luhn checksum.
|
|
7
|
+
*
|
|
8
|
+
* ENTITY
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import * as exceptions from '../exceptions';
|
|
12
|
+
import { strings } from '../util';
|
|
13
|
+
import { Validator, ValidateReturn } from '../types';
|
|
14
|
+
import { luhnChecksumValidate } from '../util/checksum';
|
|
15
|
+
|
|
16
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
17
|
+
return strings.cleanUnicode(input, ' -.', 'SE');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const impl: Validator = {
|
|
21
|
+
name: 'Swedish VAT Number',
|
|
22
|
+
localName: 'Momsregistreringsnummer',
|
|
23
|
+
abbreviation: 'Momsnr.',
|
|
24
|
+
compact(input: string): string {
|
|
25
|
+
const [value, err] = clean(input);
|
|
26
|
+
|
|
27
|
+
if (err) {
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return value;
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
format(input: string): string {
|
|
35
|
+
const [value] = clean(input);
|
|
36
|
+
|
|
37
|
+
return value;
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
validate(input: string): ValidateReturn {
|
|
41
|
+
const [value, error] = clean(input);
|
|
42
|
+
|
|
43
|
+
if (error) {
|
|
44
|
+
return { isValid: false, error };
|
|
45
|
+
}
|
|
46
|
+
if (value.length !== 12) {
|
|
47
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
48
|
+
}
|
|
49
|
+
if (!strings.isdigits(value)) {
|
|
50
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const [front, end] = strings.splitAt(value, -2);
|
|
54
|
+
|
|
55
|
+
if (end !== '01') {
|
|
56
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!luhnChecksumValidate(front)) {
|
|
60
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
isValid: true,
|
|
65
|
+
compact: value,
|
|
66
|
+
isIndividual: false,
|
|
67
|
+
isCompany: true,
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
73
|
+
impl;
|
package/src/sg/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as uen from './uen';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { validate, format } from './uen';
|
|
2
|
+
import { InvalidLength } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('sg/uen', () => {
|
|
5
|
+
it('format:T01FC6132D', () => {
|
|
6
|
+
const result = format('T01FC6132D');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('T01FC6132D');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:00192200M', () => {
|
|
12
|
+
const result = validate('00192200M');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('00192200M');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:197401143C', () => {
|
|
18
|
+
const result = validate('197401143C');
|
|
19
|
+
|
|
20
|
+
expect(result.isValid && result.compact).toEqual('197401143C');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:S16FC0121D', () => {
|
|
24
|
+
const result = validate('S16FC0121D');
|
|
25
|
+
|
|
26
|
+
expect(result.isValid && result.compact).toEqual('S16FC0121D');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('validate:T01FC6132D', () => {
|
|
30
|
+
const result = validate('T01FC6132D');
|
|
31
|
+
|
|
32
|
+
expect(result.isValid && result.compact).toEqual('T01FC6132D');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('validate:123456', () => {
|
|
36
|
+
const result = validate('123456');
|
|
37
|
+
|
|
38
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// it('validate:2449/494/16/0', () => {
|
|
42
|
+
// const result = validate('2449/494/16/0');
|
|
43
|
+
|
|
44
|
+
// expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
45
|
+
// });
|
|
46
|
+
});
|
package/src/sg/uen.ts
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UEN (Singapore's Unique Entity Number).
|
|
3
|
+
*
|
|
4
|
+
* The Unique Entity Number (UEN) is a 9 or 10 digit identification issued by
|
|
5
|
+
* the government of Singapore to businesses that operate within Singapore.
|
|
6
|
+
* Accounting and Corporate Regulatory Authority (ACRA)
|
|
7
|
+
*
|
|
8
|
+
* There are three different formats:
|
|
9
|
+
* * Business (ROB): It consists of 8 digits followed by a check letter.
|
|
10
|
+
* * Local Company (ROC): It consists of 9 digits (the 4 leftmost digits
|
|
11
|
+
* represent the year of issuance) followed by a check letter.
|
|
12
|
+
* * Others: Consists of 10 characters, begins with either the R letter, or the
|
|
13
|
+
* S letter or the T letter followed by 2 digits representing the last two
|
|
14
|
+
* digits of the issuance year, followed by two letters representing the
|
|
15
|
+
* entity type, 4 digits and finally a check letter.
|
|
16
|
+
*
|
|
17
|
+
* Source
|
|
18
|
+
* https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/Singapore-TIN.pdf
|
|
19
|
+
* https://www.uen.gov.sg/ueninternet/faces/pages/admin/aboutUEN.jspx
|
|
20
|
+
*
|
|
21
|
+
* ENTITY
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import * as exceptions from '../exceptions';
|
|
25
|
+
import { strings } from '../util';
|
|
26
|
+
import { Validator, ValidateReturn } from '../types';
|
|
27
|
+
import { weightedSum } from '../util/checksum';
|
|
28
|
+
|
|
29
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
30
|
+
return strings.cleanUnicode(input, ' ');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const OTHER_UEN_ENTITY_TYPES = [
|
|
34
|
+
'CC',
|
|
35
|
+
'CD',
|
|
36
|
+
'CH',
|
|
37
|
+
'CL',
|
|
38
|
+
'CM',
|
|
39
|
+
'CP',
|
|
40
|
+
'CS',
|
|
41
|
+
'CX',
|
|
42
|
+
'DP',
|
|
43
|
+
'FB',
|
|
44
|
+
'FC',
|
|
45
|
+
'FM',
|
|
46
|
+
'FN',
|
|
47
|
+
'GA',
|
|
48
|
+
'GB',
|
|
49
|
+
'GS',
|
|
50
|
+
'HS',
|
|
51
|
+
'LL',
|
|
52
|
+
'LP',
|
|
53
|
+
'MB',
|
|
54
|
+
'MC',
|
|
55
|
+
'MD',
|
|
56
|
+
'MH',
|
|
57
|
+
'MM',
|
|
58
|
+
'MQ',
|
|
59
|
+
'NB',
|
|
60
|
+
'NR',
|
|
61
|
+
'PA',
|
|
62
|
+
'PB',
|
|
63
|
+
'PF',
|
|
64
|
+
'RF',
|
|
65
|
+
'RP',
|
|
66
|
+
'SM',
|
|
67
|
+
'SS',
|
|
68
|
+
'TC',
|
|
69
|
+
'TU',
|
|
70
|
+
'VH',
|
|
71
|
+
'XL',
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
function validateLocal(value: string): ValidateReturn {
|
|
75
|
+
const [front, check] = strings.splitAt(value, -1);
|
|
76
|
+
if (!strings.isdigits(front)) {
|
|
77
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const sum = weightedSum(front, {
|
|
81
|
+
modulus: 11,
|
|
82
|
+
weights: [10, 8, 6, 4, 9, 7, 5, 3, 1],
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const digit = 'ZKCMDNERGWH'[sum];
|
|
86
|
+
|
|
87
|
+
if (check !== digit) {
|
|
88
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
isValid: true,
|
|
93
|
+
compact: value,
|
|
94
|
+
isIndividual: false,
|
|
95
|
+
isCompany: true,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function validateBusiness(value: string): ValidateReturn {
|
|
100
|
+
const [front, check] = strings.splitAt(value, -1);
|
|
101
|
+
if (!strings.isdigits(front)) {
|
|
102
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const sum = weightedSum(front, {
|
|
106
|
+
modulus: 11,
|
|
107
|
+
weights: [10, 4, 9, 3, 8, 2, 7, 1],
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const digit = 'XMKECAWLJDB'[sum];
|
|
111
|
+
|
|
112
|
+
if (check !== digit) {
|
|
113
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
isValid: true,
|
|
118
|
+
compact: value,
|
|
119
|
+
isIndividual: false,
|
|
120
|
+
isCompany: true,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function validateOther(value: string): ValidateReturn {
|
|
125
|
+
const [kind, year, etype, rest, check] = strings.splitAt(value, 1, 3, 5, -1);
|
|
126
|
+
if (!['R', 'S', 'T'].includes(kind)) {
|
|
127
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
128
|
+
}
|
|
129
|
+
if (!strings.isdigits(year)) {
|
|
130
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (kind === 'T' && parseInt(year, 10) > new Date().getFullYear() % 100) {
|
|
134
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
135
|
+
}
|
|
136
|
+
if (!OTHER_UEN_ENTITY_TYPES.includes(etype)) {
|
|
137
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
138
|
+
}
|
|
139
|
+
if (!strings.isdigits(rest)) {
|
|
140
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
141
|
+
}
|
|
142
|
+
const alphabet = 'ABCDEFGHJKLMNPQRSTUVWX0123456789';
|
|
143
|
+
|
|
144
|
+
const digit =
|
|
145
|
+
alphabet[
|
|
146
|
+
(weightedSum(value.substr(0, 9), {
|
|
147
|
+
weights: [4, 3, 5, 3, 10, 2, 2, 5, 7],
|
|
148
|
+
modulus: 11,
|
|
149
|
+
alphabet,
|
|
150
|
+
}) +
|
|
151
|
+
6) %
|
|
152
|
+
11
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
if (check !== digit) {
|
|
156
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
isValid: true,
|
|
161
|
+
compact: value,
|
|
162
|
+
isIndividual: false,
|
|
163
|
+
isCompany: true,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const impl: Validator = {
|
|
168
|
+
name: 'Singapore Unique Entity Number',
|
|
169
|
+
localName: 'Unique Entity Number',
|
|
170
|
+
abbreviation: 'UEN',
|
|
171
|
+
compact(input: string): string {
|
|
172
|
+
const [value, err] = clean(input);
|
|
173
|
+
|
|
174
|
+
if (err) {
|
|
175
|
+
throw err;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return value;
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
format(input: string): string {
|
|
182
|
+
const [value] = clean(input);
|
|
183
|
+
|
|
184
|
+
return value;
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
validate(input: string): ValidateReturn {
|
|
188
|
+
const [value, error] = clean(input);
|
|
189
|
+
|
|
190
|
+
if (error) {
|
|
191
|
+
return { isValid: false, error };
|
|
192
|
+
}
|
|
193
|
+
if (value.length !== 9 && value.length !== 10) {
|
|
194
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (value.length === 9) {
|
|
198
|
+
return validateBusiness(value);
|
|
199
|
+
}
|
|
200
|
+
if (strings.isdigits(value[0])) {
|
|
201
|
+
return validateLocal(value);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return validateOther(value);
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
209
|
+
impl;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { validate, format } from './ddv';
|
|
2
|
+
import { InvalidLength, InvalidChecksum } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('si/ddv', () => {
|
|
5
|
+
it('format:SI 5022 3054', () => {
|
|
6
|
+
const result = format('SI 5022 3054');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('50223054');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:SI 5022 3054', () => {
|
|
12
|
+
const result = validate('SI 5022 3054');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('50223054');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:1234567', () => {
|
|
18
|
+
const result = validate('1234567');
|
|
19
|
+
|
|
20
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:SI 5022 3053', () => {
|
|
24
|
+
const result = validate('SI 5022 3053');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
27
|
+
});
|
|
28
|
+
});
|