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/cl/rut.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Chile RUT/RUN numbers
|
|
4
|
+
*
|
|
5
|
+
* RUT number (Rol Unico Tributario).
|
|
6
|
+
*
|
|
7
|
+
* The RUT, the Chilean national tax number is the same as the RUN (Rol Único
|
|
8
|
+
* Nacional) the Chilean national identification number. The number consists of
|
|
9
|
+
* 8 digits, followed by a check digit.
|
|
10
|
+
*
|
|
11
|
+
* PERSON/ENTITY
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import * as exceptions from '../exceptions';
|
|
15
|
+
import { strings, weightedSum } from '../util';
|
|
16
|
+
import { Validator, ValidateReturn } from '../types';
|
|
17
|
+
|
|
18
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
19
|
+
const [v, err] = strings.cleanUnicode(input, ' -');
|
|
20
|
+
|
|
21
|
+
if (err) {
|
|
22
|
+
return ['', err];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (v.startsWith('CL')) {
|
|
26
|
+
return [v.substr(2), null];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return [v, null];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const impl: Validator = {
|
|
33
|
+
name: 'Chilean National Tax Number',
|
|
34
|
+
localName: 'Rol Único Tributario ',
|
|
35
|
+
abbreviation: 'RUT',
|
|
36
|
+
compact(input: string): string {
|
|
37
|
+
const [value, err] = clean(input);
|
|
38
|
+
|
|
39
|
+
if (err) {
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return value;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
format(input: string): string {
|
|
47
|
+
const [value] = clean(input);
|
|
48
|
+
|
|
49
|
+
const [a, b, c, d] = strings.splitAt(value, 2, 5, 8);
|
|
50
|
+
|
|
51
|
+
return `${a}.${b}.${c}-${d}`;
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Check if the number is a valid RUT number.
|
|
56
|
+
* This checks the length, formatting and other contraints. It does not check
|
|
57
|
+
* for control letter.
|
|
58
|
+
*/
|
|
59
|
+
validate(input: string): ValidateReturn {
|
|
60
|
+
const [value, error] = clean(input);
|
|
61
|
+
|
|
62
|
+
if (error) {
|
|
63
|
+
return { isValid: false, error };
|
|
64
|
+
}
|
|
65
|
+
if (value.length !== 8 && value.length !== 9) {
|
|
66
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const [front, check] = strings.splitAt(value, value.length - 1);
|
|
70
|
+
|
|
71
|
+
if (!strings.isdigits(front)) {
|
|
72
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const sum = weightedSum(front, {
|
|
76
|
+
reverse: true,
|
|
77
|
+
weights: [9, 8, 7, 6, 5, 4, 9, 8, 7],
|
|
78
|
+
modulus: 11,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const digit = '0123456789K'[sum];
|
|
82
|
+
|
|
83
|
+
if (check !== digit) {
|
|
84
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
isValid: true,
|
|
89
|
+
compact: value,
|
|
90
|
+
isIndividual: true,
|
|
91
|
+
isCompany: true,
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
97
|
+
impl;
|
package/src/cn/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { validate, format } from './ric';
|
|
2
|
+
import { InvalidLength, InvalidChecksum } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('cn/ric', () => {
|
|
5
|
+
it('format:360426199101010071', () => {
|
|
6
|
+
const result = format('360426199101010071');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('360426199101010071');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:360426199101010071', () => {
|
|
12
|
+
const result = validate('360426199101010071');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('360426199101010071');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:120103198806018241', () => {
|
|
18
|
+
const result = validate('120103198806018241');
|
|
19
|
+
|
|
20
|
+
expect(result.isValid && result.compact).toEqual('120103198806018241');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:12345678', () => {
|
|
24
|
+
const result = validate('12345678');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('validate:360426199101010072', () => {
|
|
30
|
+
const result = validate('360426199101010072');
|
|
31
|
+
|
|
32
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
33
|
+
});
|
|
34
|
+
});
|
package/src/cn/ric.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RIC No. (Chinese Resident Identity Card Number).
|
|
3
|
+
*
|
|
4
|
+
* The RIC No. is the unique identifier for issued to China (PRC) residents.
|
|
5
|
+
*
|
|
6
|
+
* The number consist of 18 digits in four sections. The first 6 digits refers to
|
|
7
|
+
* the resident's location, followed by 8 digits represeting the resident's birth
|
|
8
|
+
* day in the form YYYY-MM-DD. The next 3 digits is the order code which is the
|
|
9
|
+
* code used to disambiguate people with the same date of birth and address code.
|
|
10
|
+
* Men are assigned to odd numbers, women assigned to even numbers. The final
|
|
11
|
+
* digit is the checksum.
|
|
12
|
+
*
|
|
13
|
+
* Source
|
|
14
|
+
*
|
|
15
|
+
* PERSON
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import * as exceptions from '../exceptions';
|
|
19
|
+
import { strings, weightedSum } from '../util';
|
|
20
|
+
import { Validator, ValidateReturn } from '../types';
|
|
21
|
+
import { isValidDateCompactYYYYMMDD } from '../util/isValidDate';
|
|
22
|
+
|
|
23
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
24
|
+
return strings.cleanUnicode(input, ' ');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const impl: Validator = {
|
|
28
|
+
name: 'Chinese Resident Identity Card Number',
|
|
29
|
+
localName: '居民身份证',
|
|
30
|
+
abbreviation: 'RIC No',
|
|
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 !== 18) {
|
|
54
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
55
|
+
}
|
|
56
|
+
const [front, check] = strings.splitAt(value, 17);
|
|
57
|
+
if (!strings.isdigits(front)) {
|
|
58
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!isValidDateCompactYYYYMMDD(front.substring(6, 14), true)) {
|
|
62
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const checkValue = weightedSum(front, {
|
|
66
|
+
weights: [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2],
|
|
67
|
+
modulus: 11,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const digit = '10X98765432'[checkValue];
|
|
71
|
+
|
|
72
|
+
if (check !== digit) {
|
|
73
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
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,34 @@
|
|
|
1
|
+
import { validate, format } from './uscc';
|
|
2
|
+
import { InvalidLength, InvalidChecksum, InvalidFormat } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('cn/uscc', () => {
|
|
5
|
+
it('format:91110000600037341L', () => {
|
|
6
|
+
const result = format('91110000600037341L');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('91110000600037341L');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:91110000600037341L', () => {
|
|
12
|
+
const result = validate('91110000600037341L');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('91110000600037341L');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:12345678', () => {
|
|
18
|
+
const result = validate('12345678');
|
|
19
|
+
|
|
20
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:A1110000600037341L', () => {
|
|
24
|
+
const result = validate('A1110000600037341L');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidFormat);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('validate:91110000600037342L', () => {
|
|
30
|
+
const result = validate('91110000600037342L');
|
|
31
|
+
|
|
32
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
33
|
+
});
|
|
34
|
+
});
|
package/src/cn/uscc.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* USCC (Unified Social Credit Code, 统一社会信用代码, China tax number).
|
|
3
|
+
*
|
|
4
|
+
* This number consists of 18 digits or uppercase English letters (excluding the
|
|
5
|
+
* letters I, O, Z, S, V). The number is comprised of several parts:
|
|
6
|
+
*
|
|
7
|
+
* Digit 1 represents the registering authority,
|
|
8
|
+
* Digit 2 represents the registered entity type,
|
|
9
|
+
* Digits 3 through 8 represent the registering region code,
|
|
10
|
+
* Digits 9 through 17 represent the organisation code,
|
|
11
|
+
* Digit 18 is a check digit (either a number or letter).
|
|
12
|
+
*
|
|
13
|
+
* The registering authority digit most often is a 9, which represents the State
|
|
14
|
+
* Administration for Industry and Commerce (SAIC) as the registering authority.
|
|
15
|
+
*
|
|
16
|
+
* The registered entity type indicates the type of business (or entity). The
|
|
17
|
+
* most common entity types in China are:
|
|
18
|
+
*
|
|
19
|
+
* Wholly Foreign-Owned Enterprises (WFOE): 外商独资企业
|
|
20
|
+
* Joint Ventures (JV): 合资
|
|
21
|
+
* Representative Office: 代表处
|
|
22
|
+
* State-Owned Enterprise (SOE): 国有企业
|
|
23
|
+
* Private Enterprise: 民营企业
|
|
24
|
+
* Individually-Owned: 个体户
|
|
25
|
+
*
|
|
26
|
+
* The registering region code, sometimes referred to as the "administrative
|
|
27
|
+
* division code", is a string of six numbers that indicates where the company
|
|
28
|
+
* is registered. It roughly follows the organisation of the official Chinese
|
|
29
|
+
* regions.
|
|
30
|
+
*
|
|
31
|
+
* The organisation code comes directly from the China Organization Code
|
|
32
|
+
* certificate, an alternative document to the China Business License. It can
|
|
33
|
+
* contain letters or digits.
|
|
34
|
+
*
|
|
35
|
+
* SOURCES
|
|
36
|
+
* https://zh.wikipedia.org/wiki/统一社会信用代码
|
|
37
|
+
* https://zh.wikipedia.org/wiki/校验码
|
|
38
|
+
* https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/China-TIN.pdf
|
|
39
|
+
*
|
|
40
|
+
* ENTITY
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
import * as exceptions from '../exceptions';
|
|
44
|
+
import { strings, weightedSum } from '../util';
|
|
45
|
+
import { Validator, ValidateReturn } from '../types';
|
|
46
|
+
|
|
47
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
48
|
+
return strings.cleanUnicode(input, ' -');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const alphabet = '0123456789ABCDEFGHJKLMNPQRTUWXY';
|
|
52
|
+
|
|
53
|
+
const impl: Validator = {
|
|
54
|
+
name: 'Chinese Unified Social Credit Code',
|
|
55
|
+
localName: '统一社会信用代码',
|
|
56
|
+
abbreviation: 'USCC',
|
|
57
|
+
compact(input: string): string {
|
|
58
|
+
const [value, err] = clean(input);
|
|
59
|
+
|
|
60
|
+
if (err) {
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return value;
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
format(input: string): string {
|
|
68
|
+
const [value] = clean(input);
|
|
69
|
+
|
|
70
|
+
return value;
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
validate(input: string): ValidateReturn {
|
|
74
|
+
const [value, error] = clean(input);
|
|
75
|
+
|
|
76
|
+
if (error) {
|
|
77
|
+
return { isValid: false, error };
|
|
78
|
+
}
|
|
79
|
+
if (value.length !== 18) {
|
|
80
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
81
|
+
}
|
|
82
|
+
const [front, back, check] = strings.splitAt(value, 8, 17);
|
|
83
|
+
if (!strings.isdigits(front)) {
|
|
84
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
85
|
+
}
|
|
86
|
+
if (back.split('').some(v => !alphabet.includes(v))) {
|
|
87
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const digit = weightedSum(value.substr(0, 17), {
|
|
91
|
+
weights: [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28],
|
|
92
|
+
modulus: 31,
|
|
93
|
+
alphabet,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (alphabet[31 - digit] !== check) {
|
|
97
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
isValid: true,
|
|
102
|
+
compact: value,
|
|
103
|
+
isIndividual: false,
|
|
104
|
+
isCompany: true,
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
110
|
+
impl;
|
package/src/co/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as nit from './nit';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { validate, format } from './nit';
|
|
2
|
+
import { InvalidLength, InvalidChecksum } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('co/nit', () => {
|
|
5
|
+
it('format:213.123.4321', () => {
|
|
6
|
+
const result = format('213.123.4321');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('213.123.432-1');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:213.123.432-1', () => {
|
|
12
|
+
const result = validate('213.123.432-1');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('2131234321');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:10184648519', () => {
|
|
18
|
+
const result = validate('10184648519');
|
|
19
|
+
|
|
20
|
+
expect(result.isValid && result.compact).toEqual('10184648519');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:900544472-2', () => {
|
|
24
|
+
const result = validate('900544472-2');
|
|
25
|
+
|
|
26
|
+
expect(result.isValid && result.compact).toEqual('9005444722');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('validate:21312', () => {
|
|
30
|
+
const result = validate('21312');
|
|
31
|
+
|
|
32
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('validate:2131234325', () => {
|
|
36
|
+
const result = validate('2131234325');
|
|
37
|
+
|
|
38
|
+
expect(result.error).toBeInstanceOf(InvalidChecksum);
|
|
39
|
+
});
|
|
40
|
+
});
|
package/src/co/nit.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Columbian Número de Identificación Tributaria
|
|
4
|
+
*
|
|
5
|
+
* The Tax Identification Number (NIT) is a unique Colombian number, assigned by the DIAN (Dirección
|
|
6
|
+
* de Impuestos y Aduanas Nacionales de Colombia) when the entity is registered in the
|
|
7
|
+
* RUT (Registro Único Tributario).
|
|
8
|
+
*
|
|
9
|
+
* Sources:
|
|
10
|
+
* https://es.wikipedia.org/wiki/N%C3%BAmero_de_Identificaci%C3%B3n_Tributaria
|
|
11
|
+
*
|
|
12
|
+
* PERSON/ENTITY
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import * as exceptions from '../exceptions';
|
|
16
|
+
import { strings, weightedSum } from '../util';
|
|
17
|
+
import { Validator, ValidateReturn } from '../types';
|
|
18
|
+
|
|
19
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
20
|
+
return strings.cleanUnicode(input, ',.- ');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const impl: Validator = {
|
|
24
|
+
name: 'Colombian Tax Identification Number',
|
|
25
|
+
localName: 'Número de Identificación Tributaria',
|
|
26
|
+
abbreviation: 'NIT',
|
|
27
|
+
|
|
28
|
+
compact(input: string): string {
|
|
29
|
+
const [value, err] = clean(input);
|
|
30
|
+
|
|
31
|
+
if (err) {
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return value.toLocaleUpperCase();
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
format(input: string): string {
|
|
39
|
+
const [value] = clean(input);
|
|
40
|
+
|
|
41
|
+
const [p1, p2, p3, p4] = strings.splitAt(value, 3, 6, 9);
|
|
42
|
+
|
|
43
|
+
return `${p1}.${p2}.${p3}-${p4}`;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* This checks the length, formatting and other contraints. It does not check
|
|
48
|
+
* for control letter.
|
|
49
|
+
*/
|
|
50
|
+
validate(input: string): ValidateReturn {
|
|
51
|
+
const [value, error] = clean(input);
|
|
52
|
+
|
|
53
|
+
if (error) {
|
|
54
|
+
return { isValid: false, error };
|
|
55
|
+
}
|
|
56
|
+
if (value.length < 8 || value.length > 16) {
|
|
57
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
58
|
+
}
|
|
59
|
+
if (!strings.isdigits(value)) {
|
|
60
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const [front, check] = strings.splitAt(value, -1);
|
|
64
|
+
const sum = weightedSum(front, {
|
|
65
|
+
weights: [3, 7, 13, 17, 19, 23, 29, 37, 41, 43, 47, 53, 59, 67, 71],
|
|
66
|
+
reverse: true,
|
|
67
|
+
modulus: 11,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const digit = '01987654321'[sum];
|
|
71
|
+
if (check !== digit) {
|
|
72
|
+
return { isValid: false, error: new exceptions.InvalidChecksum() };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
isValid: true,
|
|
77
|
+
compact: value,
|
|
78
|
+
isIndividual: true,
|
|
79
|
+
isCompany: true,
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
85
|
+
impl;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { validate, format } from './cpf';
|
|
2
|
+
import { InvalidLength, InvalidComponent } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('cr/cpf', () => {
|
|
5
|
+
it('format:701610395', () => {
|
|
6
|
+
const result = format('701610395');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('07-0161-0395');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('format:1-613-584', () => {
|
|
12
|
+
const result = format('1-613-584');
|
|
13
|
+
|
|
14
|
+
expect(result).toEqual('01-0613-0584');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:3-0455-0175', () => {
|
|
18
|
+
const result = validate('3-0455-0175');
|
|
19
|
+
|
|
20
|
+
expect(result.isValid && result.compact).toEqual('0304550175');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:30-1234-1234', () => {
|
|
24
|
+
const result = validate('30-1234-1234');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('validate:12345678', () => {
|
|
30
|
+
const result = validate('12345678');
|
|
31
|
+
|
|
32
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
33
|
+
});
|
|
34
|
+
});
|
package/src/cr/cpf.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CPF (Cédula de Persona Física, Costa Rica physical person ID number).
|
|
3
|
+
*
|
|
4
|
+
* The Cédula de Persona Física (CPF), also known as Cédula de Identidad is an
|
|
5
|
+
* identifier of physical persons.
|
|
6
|
+
*
|
|
7
|
+
* The number consists of 10 digits in the form 0P-TTTT-AAAA where P represents
|
|
8
|
+
* the province, TTTT represents the volume (tomo) padded with zeroes on the
|
|
9
|
+
* left, and AAAA represents the entry (asiento) also padded with zeroes on the
|
|
10
|
+
* left.
|
|
11
|
+
*
|
|
12
|
+
* It seems to be usual for the leading zeroes in each of the three parts to be
|
|
13
|
+
* omitted.
|
|
14
|
+
*
|
|
15
|
+
* Source
|
|
16
|
+
* https://www.hacienda.go.cr/consultapagos/ayuda_cedulas.htm
|
|
17
|
+
* https://www.procomer.com/downloads/quiero/guia_solicitud_vuce.pdf (page 11)
|
|
18
|
+
* https://www.hacienda.go.cr/ATV/frmConsultaSituTributaria.aspx
|
|
19
|
+
*
|
|
20
|
+
* PERSON
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import * as exceptions from '../exceptions';
|
|
24
|
+
import { strings } from '../util';
|
|
25
|
+
import { Validator, ValidateReturn } from '../types';
|
|
26
|
+
|
|
27
|
+
function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
|
|
28
|
+
const [value, err] = strings.cleanUnicode(input, ' ');
|
|
29
|
+
if (err) {
|
|
30
|
+
return [value, err];
|
|
31
|
+
}
|
|
32
|
+
const parts = value.split('-');
|
|
33
|
+
if (parts.length === 3) {
|
|
34
|
+
parts[0] = parts[0].padStart(2, '0');
|
|
35
|
+
parts[1] = parts[1].padStart(4, '0');
|
|
36
|
+
parts[2] = parts[2].padStart(4, '0');
|
|
37
|
+
}
|
|
38
|
+
const number = parts.join('');
|
|
39
|
+
|
|
40
|
+
if (number.length !== 10 && number.length !== 9) {
|
|
41
|
+
return ['', new exceptions.InvalidLength()];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return [number.padStart(10, '0'), err];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const impl: Validator = {
|
|
48
|
+
name: 'Costa Rica Physical Person ID Number',
|
|
49
|
+
localName: 'Cédula de Persona Física',
|
|
50
|
+
abbreviation: 'CPF',
|
|
51
|
+
compact(input: string): string {
|
|
52
|
+
const [value, err] = clean(input);
|
|
53
|
+
|
|
54
|
+
if (err) {
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return value;
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
format(input: string): string {
|
|
62
|
+
const [value] = clean(input);
|
|
63
|
+
|
|
64
|
+
return strings.splitAt(value, 2, 6).join('-');
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
validate(input: string): ValidateReturn {
|
|
68
|
+
const [value, error] = clean(input);
|
|
69
|
+
|
|
70
|
+
if (error) {
|
|
71
|
+
return { isValid: false, error };
|
|
72
|
+
}
|
|
73
|
+
if (value.length !== 10) {
|
|
74
|
+
return { isValid: false, error: new exceptions.InvalidLength() };
|
|
75
|
+
}
|
|
76
|
+
if (!strings.isdigits(value)) {
|
|
77
|
+
return { isValid: false, error: new exceptions.InvalidFormat() };
|
|
78
|
+
}
|
|
79
|
+
if (value[0] !== '0') {
|
|
80
|
+
return { isValid: false, error: new exceptions.InvalidComponent() };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
isValid: true,
|
|
85
|
+
compact: value,
|
|
86
|
+
isIndividual: true,
|
|
87
|
+
isCompany: false,
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const { name, localName, abbreviation, validate, format, compact } =
|
|
93
|
+
impl;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { validate, format } from './cpj';
|
|
2
|
+
import { InvalidLength, InvalidComponent } from '../exceptions';
|
|
3
|
+
|
|
4
|
+
describe('cr/cpj', () => {
|
|
5
|
+
it('format:4 000 042138', () => {
|
|
6
|
+
const result = format('4 000 042138');
|
|
7
|
+
|
|
8
|
+
expect(result).toEqual('4-000-042138');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('validate:3-101-999999', () => {
|
|
12
|
+
const result = validate('3-101-999999');
|
|
13
|
+
|
|
14
|
+
expect(result.isValid && result.compact).toEqual('3101999999');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('validate:310132541', () => {
|
|
18
|
+
const result = validate('310132541');
|
|
19
|
+
|
|
20
|
+
expect(result.error).toBeInstanceOf(InvalidLength);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('validate:3-534-123559', () => {
|
|
24
|
+
const result = validate('3-534-123559');
|
|
25
|
+
|
|
26
|
+
expect(result.error).toBeInstanceOf(InvalidComponent);
|
|
27
|
+
});
|
|
28
|
+
});
|