stdnum 1.9.16 → 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.
Files changed (541) hide show
  1. package/lib/cjs/at/vnr.js +2 -2
  2. package/lib/cjs/ba/jmbg.js +2 -2
  3. package/lib/cjs/cn/ric.js +2 -2
  4. package/lib/cjs/cu/ni.js +2 -2
  5. package/lib/cjs/cz/rc.js +2 -2
  6. package/lib/cjs/de/pwnr.js +2 -2
  7. package/lib/cjs/dk/cpr.js +7 -7
  8. package/lib/cjs/ee/ik.js +2 -2
  9. package/lib/cjs/fi/hetu.js +2 -3
  10. package/lib/cjs/gr/amka.js +2 -2
  11. package/lib/cjs/is/kennitala.js +2 -2
  12. package/lib/cjs/kr/rrn.js +2 -2
  13. package/lib/cjs/lv/pvn.js +2 -2
  14. package/lib/cjs/mx/curp.d.ts +1 -1
  15. package/lib/cjs/mx/curp.js +7 -11
  16. package/lib/cjs/mx/rfc.js +2 -2
  17. package/lib/cjs/my/nric.js +2 -2
  18. package/lib/cjs/no/fodselsnummer.js +3 -3
  19. package/lib/cjs/pl/pesel.js +2 -2
  20. package/lib/cjs/ro/cnp.js +2 -2
  21. package/lib/cjs/se/personnummer.js +34 -7
  22. package/lib/cjs/tw/tax_code.js +3 -3
  23. package/lib/cjs/util/index.d.ts +1 -1
  24. package/lib/cjs/util/index.js +4 -2
  25. package/lib/cjs/util/isValidDate.d.ts +6 -4
  26. package/lib/cjs/util/isValidDate.js +28 -12
  27. package/lib/cjs/za/idnr.js +2 -3
  28. package/lib/esm/at/vnr.js +2 -2
  29. package/lib/esm/ba/jmbg.js +3 -3
  30. package/lib/esm/cn/ric.js +2 -2
  31. package/lib/esm/cu/ni.js +3 -3
  32. package/lib/esm/cz/rc.js +3 -3
  33. package/lib/esm/de/pwnr.js +2 -2
  34. package/lib/esm/dk/cpr.js +8 -8
  35. package/lib/esm/ee/ik.js +2 -2
  36. package/lib/esm/fi/hetu.js +3 -4
  37. package/lib/esm/gr/amka.js +3 -3
  38. package/lib/esm/is/kennitala.js +3 -3
  39. package/lib/esm/kr/rrn.js +2 -2
  40. package/lib/esm/lv/pvn.js +3 -3
  41. package/lib/esm/mx/curp.d.ts +1 -1
  42. package/lib/esm/mx/curp.js +8 -12
  43. package/lib/esm/mx/rfc.js +2 -2
  44. package/lib/esm/my/nric.js +2 -2
  45. package/lib/esm/no/fodselsnummer.js +3 -3
  46. package/lib/esm/pl/pesel.js +2 -2
  47. package/lib/esm/ro/cnp.js +2 -2
  48. package/lib/esm/se/personnummer.js +35 -8
  49. package/lib/esm/tw/tax_code.js +3 -3
  50. package/lib/esm/util/index.d.ts +1 -1
  51. package/lib/esm/util/index.js +2 -2
  52. package/lib/esm/util/isValidDate.d.ts +6 -4
  53. package/lib/esm/util/isValidDate.js +25 -11
  54. package/lib/esm/za/idnr.js +3 -4
  55. package/package.json +5 -2
  56. package/src/ad/index.ts +1 -0
  57. package/src/ad/nrt.spec.ts +36 -0
  58. package/src/ad/nrt.ts +87 -0
  59. package/src/al/index.ts +1 -0
  60. package/src/al/nipt.spec.ts +43 -0
  61. package/src/al/nipt.ts +111 -0
  62. package/src/ar/cbu.spec.ts +28 -0
  63. package/src/ar/cbu.ts +96 -0
  64. package/src/ar/cuit.spec.ts +28 -0
  65. package/src/ar/cuit.ts +102 -0
  66. package/src/ar/dni.spec.ts +22 -0
  67. package/src/ar/dni.ts +72 -0
  68. package/src/ar/index.ts +3 -0
  69. package/src/at/businessid.spec.ts +34 -0
  70. package/src/at/businessid.ts +73 -0
  71. package/src/at/index.ts +4 -0
  72. package/src/at/tin.spec.ts +173 -0
  73. package/src/at/tin.ts +140 -0
  74. package/src/at/uid.spec.ts +44 -0
  75. package/src/at/uid.ts +84 -0
  76. package/src/at/vnr.spec.ts +38 -0
  77. package/src/at/vnr.ts +84 -0
  78. package/src/au/abn.spec.ts +28 -0
  79. package/src/au/abn.ts +78 -0
  80. package/src/au/acn.spec.ts +34 -0
  81. package/src/au/acn.ts +76 -0
  82. package/src/au/index.ts +3 -0
  83. package/src/au/tfn.spec.ts +28 -0
  84. package/src/au/tfn.ts +79 -0
  85. package/src/az/index.ts +2 -0
  86. package/src/az/pin.spec.ts +16 -0
  87. package/src/az/pin.ts +61 -0
  88. package/src/az/tin.spec.ts +28 -0
  89. package/src/az/tin.ts +64 -0
  90. package/src/ba/index.ts +1 -0
  91. package/src/ba/jmbg.spec.ts +28 -0
  92. package/src/ba/jmbg.ts +85 -0
  93. package/src/be/bis.spec.ts +184 -0
  94. package/src/be/bis.ts +85 -0
  95. package/src/be/index.ts +4 -0
  96. package/src/be/insz.spec.ts +51 -0
  97. package/src/be/insz.ts +55 -0
  98. package/src/be/nn.spec.ts +117 -0
  99. package/src/be/nn.ts +77 -0
  100. package/src/be/personIdentifierHelpers.spec.ts +254 -0
  101. package/src/be/personIdentifierHelpers.ts +130 -0
  102. package/src/be/vat.spec.ts +46 -0
  103. package/src/be/vat.ts +84 -0
  104. package/src/bg/egn.spec.ts +28 -0
  105. package/src/bg/egn.ts +75 -0
  106. package/src/bg/index.ts +3 -0
  107. package/src/bg/pnf.spec.ts +28 -0
  108. package/src/bg/pnf.ts +73 -0
  109. package/src/bg/vat.spec.ts +34 -0
  110. package/src/bg/vat.ts +120 -0
  111. package/src/br/cnpj.spec.ts +34 -0
  112. package/src/br/cnpj.ts +89 -0
  113. package/src/br/cpf.spec.ts +34 -0
  114. package/src/br/cpf.ts +87 -0
  115. package/src/br/index.ts +2 -0
  116. package/src/by/index.ts +1 -0
  117. package/src/by/unp.spec.ts +34 -0
  118. package/src/by/unp.ts +108 -0
  119. package/src/bz/index.ts +1 -0
  120. package/src/bz/tin.spec.ts +28 -0
  121. package/src/bz/tin.ts +67 -0
  122. package/src/ca/bn.spec.ts +40 -0
  123. package/src/ca/bn.ts +88 -0
  124. package/src/ca/gst.spec.ts +34 -0
  125. package/src/ca/gst.ts +70 -0
  126. package/src/ca/index.ts +5 -0
  127. package/src/ca/pst.spec.ts +28 -0
  128. package/src/ca/pst.ts +71 -0
  129. package/src/ca/qst.spec.ts +47 -0
  130. package/src/ca/qst.ts +88 -0
  131. package/src/ca/sin.spec.ts +34 -0
  132. package/src/ca/sin.ts +72 -0
  133. package/src/ch/index.ts +3 -0
  134. package/src/ch/ssn.spec.ts +50 -0
  135. package/src/ch/ssn.ts +74 -0
  136. package/src/ch/uid.spec.ts +34 -0
  137. package/src/ch/uid.ts +82 -0
  138. package/src/ch/vat.spec.ts +28 -0
  139. package/src/ch/vat.ts +83 -0
  140. package/src/cl/index.ts +2 -0
  141. package/src/cl/run.ts +13 -0
  142. package/src/cl/rut.spec.ts +50 -0
  143. package/src/cl/rut.ts +97 -0
  144. package/src/cn/index.ts +2 -0
  145. package/src/cn/ric.spec.ts +34 -0
  146. package/src/cn/ric.ts +86 -0
  147. package/src/cn/uscc.spec.ts +34 -0
  148. package/src/cn/uscc.ts +110 -0
  149. package/src/co/index.ts +1 -0
  150. package/src/co/nit.spec.ts +40 -0
  151. package/src/co/nit.ts +85 -0
  152. package/src/cr/cpf.spec.ts +34 -0
  153. package/src/cr/cpf.ts +93 -0
  154. package/src/cr/cpj.spec.ts +28 -0
  155. package/src/cr/cpj.ts +111 -0
  156. package/src/cr/cr.spec.ts +28 -0
  157. package/src/cr/cr.ts +75 -0
  158. package/src/cr/index.ts +3 -0
  159. package/src/cu/index.ts +1 -0
  160. package/src/cu/ni.spec.ts +34 -0
  161. package/src/cu/ni.ts +74 -0
  162. package/src/cy/index.ts +1 -0
  163. package/src/cy/vat.spec.ts +28 -0
  164. package/src/cy/vat.ts +98 -0
  165. package/src/cz/dic.spec.ts +28 -0
  166. package/src/cz/dic.ts +127 -0
  167. package/src/cz/index.ts +2 -0
  168. package/src/cz/rc.spec.ts +44 -0
  169. package/src/cz/rc.ts +95 -0
  170. package/src/de/idnr.spec.ts +34 -0
  171. package/src/de/idnr.ts +91 -0
  172. package/src/de/index.ts +6 -0
  173. package/src/de/passport.spec.ts +31 -0
  174. package/src/de/passport.ts +86 -0
  175. package/src/de/pwnr.spec.ts +62 -0
  176. package/src/de/pwnr.ts +190 -0
  177. package/src/de/stnr.spec.ts +85 -0
  178. package/src/de/stnr.ts +193 -0
  179. package/src/de/svnr.spec.ts +56 -0
  180. package/src/de/svnr.ts +158 -0
  181. package/src/de/vat.spec.ts +28 -0
  182. package/src/de/vat.ts +74 -0
  183. package/src/dk/cpr.spec.ts +34 -0
  184. package/src/dk/cpr.ts +129 -0
  185. package/src/dk/cvr.spec.ts +28 -0
  186. package/src/dk/cvr.ts +81 -0
  187. package/src/dk/index.ts +2 -0
  188. package/src/do/cedula.spec.ts +34 -0
  189. package/src/do/cedula.ts +67 -0
  190. package/src/do/index.ts +3 -0
  191. package/src/do/ncf.spec.ts +34 -0
  192. package/src/do/ncf.ts +133 -0
  193. package/src/do/rnc.spec.ts +40 -0
  194. package/src/do/rnc.ts +74 -0
  195. package/src/dz/index.ts +1 -0
  196. package/src/dz/nif.spec.ts +39 -0
  197. package/src/dz/nif.ts +80 -0
  198. package/src/ec/ci.spec.ts +28 -0
  199. package/src/ec/ci.ts +92 -0
  200. package/src/ec/index.ts +2 -0
  201. package/src/ec/ruc.spec.ts +37 -0
  202. package/src/ec/ruc.ts +117 -0
  203. package/src/ee/ik.spec.ts +28 -0
  204. package/src/ee/ik.ts +114 -0
  205. package/src/ee/index.ts +3 -0
  206. package/src/ee/kmkr.spec.ts +28 -0
  207. package/src/ee/kmkr.ts +76 -0
  208. package/src/ee/registrikood.spec.ts +28 -0
  209. package/src/ee/registrikood.ts +80 -0
  210. package/src/eg/index.ts +1 -0
  211. package/src/eg/tn.spec.ts +44 -0
  212. package/src/eg/tn.ts +96 -0
  213. package/src/es/cif.spec.ts +43 -0
  214. package/src/es/cif.ts +84 -0
  215. package/src/es/dni.spec.ts +28 -0
  216. package/src/es/dni.ts +83 -0
  217. package/src/es/index.ts +5 -0
  218. package/src/es/nie.spec.ts +28 -0
  219. package/src/es/nie.ts +79 -0
  220. package/src/es/nif.spec.ts +52 -0
  221. package/src/es/nif.ts +95 -0
  222. package/src/es/nss.spec.ts +28 -0
  223. package/src/es/nss.ts +132 -0
  224. package/src/exceptions.ts +66 -0
  225. package/src/fi/alv.spec.ts +28 -0
  226. package/src/fi/alv.ts +76 -0
  227. package/src/fi/hetu.spec.ts +37 -0
  228. package/src/fi/hetu.ts +108 -0
  229. package/src/fi/index.ts +3 -0
  230. package/src/fi/ytunnus.spec.ts +28 -0
  231. package/src/fi/ytunnus.ts +49 -0
  232. package/src/fo/index.ts +1 -0
  233. package/src/fo/vn.spec.ts +34 -0
  234. package/src/fo/vn.ts +71 -0
  235. package/src/fr/index.ts +5 -0
  236. package/src/fr/nif.spec.ts +34 -0
  237. package/src/fr/nif.ts +82 -0
  238. package/src/fr/nir.spec.ts +36 -0
  239. package/src/fr/nir.ts +98 -0
  240. package/src/fr/siren.spec.ts +28 -0
  241. package/src/fr/siren.ts +68 -0
  242. package/src/fr/siret.spec.ts +38 -0
  243. package/src/fr/siret.ts +79 -0
  244. package/src/fr/tva.spec.ts +40 -0
  245. package/src/fr/tva.ts +125 -0
  246. package/src/gb/index.ts +3 -0
  247. package/src/gb/nino-prefixes.ts +245 -0
  248. package/src/gb/nino.spec.ts +80 -0
  249. package/src/gb/nino.ts +80 -0
  250. package/src/gb/utr.spec.ts +28 -0
  251. package/src/gb/utr.ts +76 -0
  252. package/src/gb/vat.spec.ts +40 -0
  253. package/src/gb/vat.ts +112 -0
  254. package/src/gen/ean.spec.ts +34 -0
  255. package/src/gen/ean.ts +71 -0
  256. package/src/gen/index.ts +1 -0
  257. package/src/gh/index.ts +1 -0
  258. package/src/gh/tin.spec.ts +42 -0
  259. package/src/gh/tin.ts +93 -0
  260. package/src/gn/index.ts +1 -0
  261. package/src/gn/nifp.spec.ts +40 -0
  262. package/src/gn/nifp.ts +72 -0
  263. package/src/gr/amka.spec.ts +28 -0
  264. package/src/gr/amka.ts +76 -0
  265. package/src/gr/index.ts +2 -0
  266. package/src/gr/vat.spec.ts +34 -0
  267. package/src/gr/vat.ts +84 -0
  268. package/src/gt/cui.spec.ts +34 -0
  269. package/src/gt/cui.ts +110 -0
  270. package/src/gt/index.ts +2 -0
  271. package/src/gt/nit.spec.ts +34 -0
  272. package/src/gt/nit.ts +86 -0
  273. package/src/hk/hkid.spec.ts +52 -0
  274. package/src/hk/hkid.ts +90 -0
  275. package/src/hk/index.ts +1 -0
  276. package/src/hr/index.ts +1 -0
  277. package/src/hr/oib.spec.ts +28 -0
  278. package/src/hr/oib.ts +67 -0
  279. package/src/hu/anum.spec.ts +28 -0
  280. package/src/hu/anum.ts +71 -0
  281. package/src/hu/index.ts +1 -0
  282. package/src/id/index.ts +1 -0
  283. package/src/id/npwp.spec.ts +34 -0
  284. package/src/id/npwp.ts +116 -0
  285. package/src/ie/index.ts +2 -0
  286. package/src/ie/pps.spec.ts +58 -0
  287. package/src/ie/pps.ts +81 -0
  288. package/src/ie/vat.spec.ts +40 -0
  289. package/src/ie/vat.ts +99 -0
  290. package/src/il/hp.spec.ts +38 -0
  291. package/src/il/hp.ts +75 -0
  292. package/src/il/idnr.spec.ts +28 -0
  293. package/src/il/idnr.ts +70 -0
  294. package/src/il/index.ts +2 -0
  295. package/src/in/aadhaar.spec.ts +40 -0
  296. package/src/in/aadhaar.ts +85 -0
  297. package/src/in/epic.spec.ts +34 -0
  298. package/src/in/epic.ts +85 -0
  299. package/src/in/gstin.spec.ts +34 -0
  300. package/src/in/gstin.ts +156 -0
  301. package/src/in/index.ts +4 -0
  302. package/src/in/pan.spec.ts +40 -0
  303. package/src/in/pan.ts +93 -0
  304. package/src/index.ts +404 -0
  305. package/src/is/index.ts +2 -0
  306. package/src/is/kennitala.spec.ts +46 -0
  307. package/src/is/kennitala.ts +80 -0
  308. package/src/is/vsk.spec.ts +22 -0
  309. package/src/is/vsk.ts +60 -0
  310. package/src/it/aic.spec.ts +40 -0
  311. package/src/it/aic.ts +97 -0
  312. package/src/it/codicefiscale.spec.ts +28 -0
  313. package/src/it/codicefiscale.ts +167 -0
  314. package/src/it/index.ts +3 -0
  315. package/src/it/iva.spec.ts +28 -0
  316. package/src/it/iva.ts +65 -0
  317. package/src/jp/cn.spec.ts +28 -0
  318. package/src/jp/cn.ts +77 -0
  319. package/src/jp/index.ts +1 -0
  320. package/src/ke/index.ts +1 -0
  321. package/src/ke/pin.spec.ts +34 -0
  322. package/src/ke/pin.ts +77 -0
  323. package/src/kr/brn.spec.ts +28 -0
  324. package/src/kr/brn.ts +91 -0
  325. package/src/kr/index.ts +2 -0
  326. package/src/kr/rrn.spec.ts +34 -0
  327. package/src/kr/rrn.ts +104 -0
  328. package/src/li/index.ts +1 -0
  329. package/src/li/peid.spec.ts +22 -0
  330. package/src/li/peid.ts +71 -0
  331. package/src/lt/asmens.spec.ts +28 -0
  332. package/src/lt/asmens.ts +73 -0
  333. package/src/lt/index.ts +2 -0
  334. package/src/lt/pvm.spec.ts +34 -0
  335. package/src/lt/pvm.ts +75 -0
  336. package/src/lu/index.ts +1 -0
  337. package/src/lu/tva.spec.ts +28 -0
  338. package/src/lu/tva.ts +70 -0
  339. package/src/lv/index.ts +1 -0
  340. package/src/lv/pvn.spec.ts +44 -0
  341. package/src/lv/pvn.ts +102 -0
  342. package/src/ma/ice.spec.ts +39 -0
  343. package/src/ma/ice.ts +72 -0
  344. package/src/ma/ice9.spec.ts +28 -0
  345. package/src/ma/ice9.ts +62 -0
  346. package/src/ma/index.ts +2 -0
  347. package/src/mc/index.ts +1 -0
  348. package/src/mc/tva.spec.ts +28 -0
  349. package/src/mc/tva.ts +67 -0
  350. package/src/md/idno.spec.ts +28 -0
  351. package/src/md/idno.ts +78 -0
  352. package/src/md/index.ts +1 -0
  353. package/src/me/index.ts +2 -0
  354. package/src/me/jmbg.ts +17 -0
  355. package/src/me/pib.spec.ts +158 -0
  356. package/src/me/pib.ts +77 -0
  357. package/src/mk/edb.spec.ts +50 -0
  358. package/src/mk/edb.ts +88 -0
  359. package/src/mk/index.ts +2 -0
  360. package/src/mk/jmbg.ts +17 -0
  361. package/src/mt/index.ts +1 -0
  362. package/src/mt/vat.spec.ts +28 -0
  363. package/src/mt/vat.ts +69 -0
  364. package/src/mu/index.ts +1 -0
  365. package/src/mu/nid.spec.ts +34 -0
  366. package/src/mu/nid.ts +89 -0
  367. package/src/mx/banks.ts +658 -0
  368. package/src/mx/clabe.spec.ts +68 -0
  369. package/src/mx/clabe.ts +105 -0
  370. package/src/mx/curp.spec.ts +28 -0
  371. package/src/mx/curp.ts +261 -0
  372. package/src/mx/index.ts +3 -0
  373. package/src/mx/rfc.spec.ts +69 -0
  374. package/src/mx/rfc.ts +193 -0
  375. package/src/my/index.ts +1 -0
  376. package/src/my/nric.spec.ts +40 -0
  377. package/src/my/nric.ts +91 -0
  378. package/src/nl/bsn.spec.ts +68 -0
  379. package/src/nl/bsn.ts +81 -0
  380. package/src/nl/btw.spec.ts +40 -0
  381. package/src/nl/btw.ts +95 -0
  382. package/src/nl/index.ts +3 -0
  383. package/src/nl/onderwijsnummer.spec.ts +34 -0
  384. package/src/nl/onderwijsnummer.ts +77 -0
  385. package/src/no/fodselsnummer.spec.ts +56 -0
  386. package/src/no/fodselsnummer.ts +118 -0
  387. package/src/no/index.ts +4 -0
  388. package/src/no/kontonr.spec.ts +34 -0
  389. package/src/no/kontonr.ts +84 -0
  390. package/src/no/mva.spec.ts +28 -0
  391. package/src/no/mva.ts +80 -0
  392. package/src/no/orgnr.spec.ts +28 -0
  393. package/src/no/orgnr.ts +75 -0
  394. package/src/nz/bank.spec.ts +28 -0
  395. package/src/nz/bank.ts +238 -0
  396. package/src/nz/index.ts +2 -0
  397. package/src/nz/ird.spec.ts +34 -0
  398. package/src/nz/ird.ts +102 -0
  399. package/src/pe/ce.spec.ts +46 -0
  400. package/src/pe/ce.ts +61 -0
  401. package/src/pe/cui.spec.ts +28 -0
  402. package/src/pe/cui.ts +85 -0
  403. package/src/pe/index.ts +3 -0
  404. package/src/pe/ruc.spec.ts +46 -0
  405. package/src/pe/ruc.ts +84 -0
  406. package/src/pk/cnic.spec.ts +34 -0
  407. package/src/pk/cnic.ts +97 -0
  408. package/src/pk/index.ts +2 -0
  409. package/src/pk/ntn.spec.ts +22 -0
  410. package/src/pk/ntn.ts +65 -0
  411. package/src/pl/index.ts +3 -0
  412. package/src/pl/nip.spec.ts +34 -0
  413. package/src/pl/nip.ts +74 -0
  414. package/src/pl/pesel.spec.ts +34 -0
  415. package/src/pl/pesel.ts +97 -0
  416. package/src/pl/regon.spec.ts +52 -0
  417. package/src/pl/regon.ts +88 -0
  418. package/src/pt/cc.spec.ts +43 -0
  419. package/src/pt/cc.ts +74 -0
  420. package/src/pt/index.ts +3 -0
  421. package/src/pt/nif.spec.ts +28 -0
  422. package/src/pt/nif.ts +78 -0
  423. package/src/pt/nipc.ts +27 -0
  424. package/src/py/cedula.spec.ts +46 -0
  425. package/src/py/cedula.ts +73 -0
  426. package/src/py/index.ts +2 -0
  427. package/src/py/ruc.spec.ts +40 -0
  428. package/src/py/ruc.ts +93 -0
  429. package/src/ro/cif.spec.ts +40 -0
  430. package/src/ro/cif.ts +62 -0
  431. package/src/ro/cnp.spec.ts +50 -0
  432. package/src/ro/cnp.ts +158 -0
  433. package/src/ro/cui.spec.ts +28 -0
  434. package/src/ro/cui.ts +83 -0
  435. package/src/ro/index.ts +4 -0
  436. package/src/ro/onrc.spec.ts +28 -0
  437. package/src/ro/onrc.ts +109 -0
  438. package/src/rs/index.ts +2 -0
  439. package/src/rs/jmbg.ts +16 -0
  440. package/src/rs/pib.spec.ts +28 -0
  441. package/src/rs/pib.ts +69 -0
  442. package/src/ru/index.ts +1 -0
  443. package/src/ru/inn.spec.ts +32 -0
  444. package/src/ru/inn.ts +106 -0
  445. package/src/se/index.ts +3 -0
  446. package/src/se/orgnr.spec.ts +28 -0
  447. package/src/se/orgnr.ts +68 -0
  448. package/src/se/personnummer.spec.ts +45 -0
  449. package/src/se/personnummer.ts +143 -0
  450. package/src/se/vat.spec.ts +28 -0
  451. package/src/se/vat.ts +73 -0
  452. package/src/sg/index.ts +1 -0
  453. package/src/sg/uen.spec.ts +46 -0
  454. package/src/sg/uen.ts +209 -0
  455. package/src/si/ddv.spec.ts +28 -0
  456. package/src/si/ddv.ts +76 -0
  457. package/src/si/emso.spec.ts +15 -0
  458. package/src/si/emso.ts +27 -0
  459. package/src/si/index.ts +3 -0
  460. package/src/si/jmbg.ts +20 -0
  461. package/src/sk/dph.spec.ts +28 -0
  462. package/src/sk/dph.ts +71 -0
  463. package/src/sk/index.ts +2 -0
  464. package/src/sk/rc.ts +12 -0
  465. package/src/sm/coe.spec.ts +34 -0
  466. package/src/sm/coe.ts +80 -0
  467. package/src/sm/index.ts +1 -0
  468. package/src/sv/index.ts +1 -0
  469. package/src/sv/nit.spec.ts +34 -0
  470. package/src/sv/nit.ts +117 -0
  471. package/src/th/idnr.spec.ts +41 -0
  472. package/src/th/idnr.ts +80 -0
  473. package/src/th/index.ts +3 -0
  474. package/src/th/moa.spec.ts +62 -0
  475. package/src/th/moa.ts +85 -0
  476. package/src/th/tin.spec.ts +77 -0
  477. package/src/th/tin.ts +56 -0
  478. package/src/tn/index.ts +1 -0
  479. package/src/tn/mf.spec.ts +37 -0
  480. package/src/tn/mf.ts +169 -0
  481. package/src/tr/index.ts +2 -0
  482. package/src/tr/tckimlik.spec.ts +40 -0
  483. package/src/tr/tckimlik.ts +87 -0
  484. package/src/tr/vkn.spec.ts +28 -0
  485. package/src/tr/vkn.ts +87 -0
  486. package/src/tw/ban.spec.ts +28 -0
  487. package/src/tw/ban.ts +67 -0
  488. package/src/tw/index.ts +5 -0
  489. package/src/tw/natid.spec.ts +28 -0
  490. package/src/tw/natid.ts +105 -0
  491. package/src/tw/tax_code.spec.ts +34 -0
  492. package/src/tw/tax_code.ts +98 -0
  493. package/src/tw/ubn.spec.ts +28 -0
  494. package/src/tw/ubn.ts +80 -0
  495. package/src/tw/ui.spec.ts +38 -0
  496. package/src/tw/ui.ts +107 -0
  497. package/src/types.ts +82 -0
  498. package/src/ua/edrpou.spec.ts +28 -0
  499. package/src/ua/edrpou.ts +88 -0
  500. package/src/ua/index.ts +2 -0
  501. package/src/ua/rntrc.spec.ts +28 -0
  502. package/src/ua/rntrc.ts +77 -0
  503. package/src/us/ein.spec.ts +28 -0
  504. package/src/us/ein.ts +179 -0
  505. package/src/us/index.ts +2 -0
  506. package/src/us/ssn.spec.ts +28 -0
  507. package/src/us/ssn.ts +117 -0
  508. package/src/util/checksum.spec.ts +70 -0
  509. package/src/util/checksum.ts +258 -0
  510. package/src/util/index.ts +13 -0
  511. package/src/util/isValidDate.spec.ts +49 -0
  512. package/src/util/isValidDate.ts +87 -0
  513. package/src/util/iso7064.spec.ts +17 -0
  514. package/src/util/iso7064.ts +8 -0
  515. package/src/util/pymod.ts +8 -0
  516. package/src/util/strings/char.ts +18 -0
  517. package/src/util/strings/clean.spec.ts +15 -0
  518. package/src/util/strings/clean.ts +305 -0
  519. package/src/util/strings/format.ts +18 -0
  520. package/src/util/strings/index.ts +5 -0
  521. package/src/util/strings/reverseString.ts +3 -0
  522. package/src/util/strings/splitAt.spec.ts +15 -0
  523. package/src/util/strings/splitAt.ts +16 -0
  524. package/src/uy/cedula.spec.ts +28 -0
  525. package/src/uy/cedula.ts +74 -0
  526. package/src/uy/index.ts +3 -0
  527. package/src/uy/nie.spec.ts +28 -0
  528. package/src/uy/nie.ts +84 -0
  529. package/src/uy/rut.spec.ts +34 -0
  530. package/src/uy/rut.ts +99 -0
  531. package/src/ve/index.ts +1 -0
  532. package/src/ve/rif.spec.ts +38 -0
  533. package/src/ve/rif.ts +92 -0
  534. package/src/vn/index.ts +1 -0
  535. package/src/vn/mst.spec.ts +40 -0
  536. package/src/vn/mst.ts +100 -0
  537. package/src/za/idnr.spec.ts +28 -0
  538. package/src/za/idnr.ts +84 -0
  539. package/src/za/index.ts +2 -0
  540. package/src/za/tin.spec.ts +28 -0
  541. package/src/za/tin.ts +75 -0
package/src/nz/bank.ts ADDED
@@ -0,0 +1,238 @@
1
+ /**
2
+ * New Zealand Bank account number
3
+ *
4
+ * In the real bank account format for country - New Zealand is in this format.
5
+ * As per the standards bank account number should be as the format
6
+ * BB-RRRR-AAAAAAA-SSS (B- Bank, R-Branch, A-Account,S-Suffix).
7
+ * BBRRRR is captured as the National bank Code and it is expected to enter a
8
+ * 10 digit account number, like so: AAAAAAASSS.
9
+ *
10
+ * Source
11
+ * http://www.paymentsnz.co.nz/clearing-systems/bulk-electronic-clearing-system
12
+ * https://www.ird.govt.nz/resources/d/8/d8e49dce-1bda-4875-8acf-9ebf908c6e17/rwt-nrwt-spec-2014.pdf
13
+ *
14
+ * BANK
15
+ */
16
+
17
+ import * as exceptions from '../exceptions';
18
+ import { strings } from '../util';
19
+ import { Validator, ValidateReturn } from '../types';
20
+ import { weightedSum } from '../util/checksum';
21
+
22
+ // Data from pages 10 and 11 of
23
+ // https://www.ird.govt.nz/resources/d/8/d8e49dce-1bda-4875-8acf-9ebf908c6e17/rwt-nrwt-spec-2014.pdf
24
+ const bankData: Record<
25
+ string,
26
+ {
27
+ algorithm: string;
28
+ branches: [number, number][];
29
+ }
30
+ > = {
31
+ '01': {
32
+ algorithm: 'AB',
33
+ branches: [
34
+ [1, 999],
35
+ [1100, 1199],
36
+ [1800, 1899],
37
+ ],
38
+ },
39
+ '02': {
40
+ algorithm: 'AB',
41
+ branches: [
42
+ [1, 999],
43
+ [1200, 1299],
44
+ ],
45
+ },
46
+ '03': {
47
+ algorithm: 'AB',
48
+ branches: [
49
+ [1, 999],
50
+ [1300, 1399],
51
+ [1500, 1599],
52
+ [1700, 1799],
53
+ [1900, 1999],
54
+ ],
55
+ },
56
+ '06': {
57
+ algorithm: 'AB',
58
+ branches: [
59
+ [1, 999],
60
+ [1400, 1499],
61
+ ],
62
+ },
63
+ '08': { algorithm: 'D', branches: [[6500, 6599]] },
64
+ '09': { algorithm: 'E', branches: [[0, 0]] },
65
+ '11': {
66
+ algorithm: 'AB',
67
+ branches: [
68
+ [5000, 6499],
69
+ [6600, 8999],
70
+ ],
71
+ },
72
+ '12': {
73
+ algorithm: 'AB',
74
+ branches: [
75
+ [3000, 3299],
76
+ [3400, 3499],
77
+ [3600, 3699],
78
+ ],
79
+ },
80
+ '13': { algorithm: 'AB', branches: [[4900, 4999]] },
81
+ '14': { algorithm: 'AB', branches: [[4700, 4799]] },
82
+ '15': { algorithm: 'AB', branches: [[3900, 3999]] },
83
+ '16': { algorithm: 'AB', branches: [[4400, 4499]] },
84
+ '17': { algorithm: 'AB', branches: [[3300, 3399]] },
85
+ '18': { algorithm: 'AB', branches: [[3500, 3599]] },
86
+ '19': { algorithm: 'AB', branches: [[4600, 4649]] },
87
+ '20': { algorithm: 'AB', branches: [[4100, 4199]] },
88
+ '21': { algorithm: 'AB', branches: [[4800, 4899]] },
89
+ '22': { algorithm: 'AB', branches: [[4000, 4049]] },
90
+ '23': { algorithm: 'AB', branches: [[3700, 3799]] },
91
+ '24': { algorithm: 'AB', branches: [[4300, 4349]] },
92
+ '25': { algorithm: 'F', branches: [[2500, 2599]] },
93
+ '26': { algorithm: 'G', branches: [[2600, 2699]] },
94
+ '27': { algorithm: 'AB', branches: [[3800, 3849]] },
95
+ '28': { algorithm: 'G', branches: [[2100, 2149]] },
96
+ '29': { algorithm: 'G', branches: [[2150, 2299]] },
97
+ '30': { algorithm: 'AB', branches: [[2900, 2949]] },
98
+ '31': { algorithm: 'X', branches: [[2800, 2849]] },
99
+ '33': { algorithm: 'F', branches: [[6700, 6799]] },
100
+ '35': { algorithm: 'AB', branches: [[2400, 2499]] },
101
+ '38': { algorithm: 'AB', branches: [[9000, 9499]] },
102
+ };
103
+
104
+ const algorithms: Record<string, { weights: number[]; modulus: number }> = {
105
+ A: {
106
+ weights: [0, 0, 6, 3, 7, 9, 0, 0, 10, 5, 8, 4, 2, 1, 0, 0, 0, 0],
107
+ modulus: 11,
108
+ },
109
+ B: {
110
+ weights: [0, 0, 0, 0, 0, 0, 0, 0, 10, 5, 8, 4, 2, 1, 0, 0, 0, 0],
111
+ modulus: 11,
112
+ },
113
+ C: {
114
+ weights: [3, 7, 0, 0, 0, 0, 9, 1, 10, 5, 3, 4, 2, 1, 0, 0, 0, 0],
115
+ modulus: 11,
116
+ },
117
+ D: {
118
+ weights: [0, 0, 0, 0, 0, 0, 0, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0],
119
+ modulus: 11,
120
+ },
121
+ E: {
122
+ weights: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 4, 3, 2, 0, 0, 0, 1],
123
+ modulus: 11,
124
+ },
125
+ F: {
126
+ weights: [0, 0, 0, 0, 0, 0, 0, 1, 7, 3, 1, 7, 3, 1, 0, 0, 0, 0],
127
+ modulus: 10,
128
+ },
129
+ G: {
130
+ weights: [0, 0, 0, 0, 0, 0, 0, 1, 3, 7, 1, 3, 7, 1, 0, 3, 7, 1],
131
+ modulus: 10,
132
+ },
133
+ X: {
134
+ weights: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
135
+ modulus: 1,
136
+ },
137
+ };
138
+
139
+ function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
140
+ // We're going to allow '-' or ' ' separators
141
+ const [valueA, err] = strings.cleanUnicode(input, '');
142
+
143
+ if (err !== null) {
144
+ return [valueA, err];
145
+ }
146
+ const cvalue = valueA.trim();
147
+
148
+ // No separtor, keep it simple
149
+ if (!/[ -]/.test(cvalue)) {
150
+ return [cvalue, null];
151
+ }
152
+
153
+ const parts = cvalue.split(/[ -]/g);
154
+ if (parts.length !== 4) {
155
+ return [cvalue, new exceptions.InvalidFormat()];
156
+ }
157
+
158
+ return [
159
+ [
160
+ parts[0].padStart(2, '0'),
161
+ parts[1].padStart(4, '0'),
162
+ parts[2].padStart(7, '0'),
163
+ parts[3].padStart(3, '0'),
164
+ ].join(''),
165
+ null,
166
+ ];
167
+ }
168
+
169
+ const impl: Validator = {
170
+ name: 'New Zealand Bank Account Number',
171
+ localName: 'Bank Account Number',
172
+ compact(input: string): string {
173
+ const [value, err] = clean(input);
174
+
175
+ if (err) {
176
+ throw err;
177
+ }
178
+
179
+ return value;
180
+ },
181
+
182
+ format(input: string): string {
183
+ const [value] = clean(input);
184
+
185
+ return strings.splitAt(value, 2, 6, -3).join('-');
186
+ },
187
+
188
+ validate(input: string): ValidateReturn {
189
+ const [value, error] = clean(input);
190
+
191
+ if (error) {
192
+ return { isValid: false, error };
193
+ }
194
+ if (value.length !== 16) {
195
+ return { isValid: false, error: new exceptions.InvalidLength() };
196
+ }
197
+ if (!strings.isdigits(value)) {
198
+ return { isValid: false, error: new exceptions.InvalidFormat() };
199
+ }
200
+
201
+ const [bank, branch, account, suffix] = strings.splitAt(value, 2, 6, -3);
202
+
203
+ const bankInfo = bankData[bank];
204
+ if (!bankInfo) {
205
+ return { isValid: false, error: new exceptions.InvalidComponent() };
206
+ }
207
+ const bnum = parseInt(branch, 10);
208
+ if (!bankInfo.branches.some(pair => bnum >= pair[0] && bnum <= pair[1])) {
209
+ return { isValid: false, error: new exceptions.InvalidComponent() };
210
+ }
211
+
212
+ let alg = bankInfo.algorithm;
213
+ if (alg === 'AB') {
214
+ alg = parseInt(account, 10) < 990000 ? 'A' : 'B';
215
+ }
216
+
217
+ const algInfo = algorithms[alg];
218
+ if (!algInfo) {
219
+ return { isValid: false, error: new exceptions.InvalidComponent() };
220
+ }
221
+
222
+ const sum = weightedSum(`${bank}${branch}0${account}0${suffix}`, algInfo);
223
+
224
+ if (String(sum) !== '0') {
225
+ return { isValid: false, error: new exceptions.InvalidChecksum() };
226
+ }
227
+
228
+ return {
229
+ isValid: true,
230
+ compact: value,
231
+ isIndividual: false,
232
+ isCompany: false,
233
+ };
234
+ },
235
+ };
236
+
237
+ export const { name, localName, abbreviation, validate, format, compact } =
238
+ impl;
@@ -0,0 +1,2 @@
1
+ export * as ird from './ird';
2
+ export * as bank from './bank';
@@ -0,0 +1,34 @@
1
+ import { validate, format } from './ird';
2
+ import { InvalidLength, InvalidChecksum } from '../exceptions';
3
+
4
+ describe('nz/ird', () => {
5
+ it('format:4909185-0', () => {
6
+ const result = format('4909185-0');
7
+
8
+ expect(result).toEqual('49-091-850');
9
+ });
10
+
11
+ it('validate:4909185-0', () => {
12
+ const result = validate('4909185-0');
13
+
14
+ expect(result.isValid && result.compact).toEqual('49091850');
15
+ });
16
+
17
+ it('validate:NZ 4909185-0', () => {
18
+ const result = validate('NZ 4909185-0');
19
+
20
+ expect(result.isValid && result.compact).toEqual('49091850');
21
+ });
22
+
23
+ it('validate:123478', () => {
24
+ const result = validate('123478');
25
+
26
+ expect(result.error).toBeInstanceOf(InvalidLength);
27
+ });
28
+
29
+ it('validate:136410133', () => {
30
+ const result = validate('136410133');
31
+
32
+ expect(result.error).toBeInstanceOf(InvalidChecksum);
33
+ });
34
+ });
package/src/nz/ird.ts ADDED
@@ -0,0 +1,102 @@
1
+ /**
2
+ * IRD number (New Zealand Inland Revenue Department (Te Tari Taake) number).
3
+ *
4
+ * The IRD number is used by the New Zealand Inland Revenue Department (Te Tari Taake)
5
+ * to identify businesses and individuals for tax purposes. The number consists of 8 or 9 digits
6
+ * where the last digit is a check digit.
7
+ *
8
+ * Source
9
+ * https://www.ird.govt.nz/
10
+ * https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/New%20Zealand-TIN.pdf
11
+ *
12
+ * PERSON/ENTITY
13
+ */
14
+
15
+ import * as exceptions from '../exceptions';
16
+ import { strings } from '../util';
17
+ import { Validator, ValidateReturn } from '../types';
18
+ import { weightedSum } from '../util/checksum';
19
+
20
+ function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
21
+ const [value, err] = strings.cleanUnicode(input, ' -');
22
+
23
+ if (err !== null) {
24
+ return [value, err];
25
+ }
26
+
27
+ if (value.startsWith('NZ')) {
28
+ return [value.substr(2), null];
29
+ }
30
+
31
+ return [value, null];
32
+ }
33
+
34
+ const impl: Validator = {
35
+ name: 'Inland Revenue Department Number',
36
+ localName: 'Te Tari Taake',
37
+ abbreviation: 'IRD',
38
+
39
+ compact(input: string): string {
40
+ const [value, err] = clean(input);
41
+
42
+ if (err) {
43
+ throw err;
44
+ }
45
+
46
+ return value;
47
+ },
48
+
49
+ format(input: string): string {
50
+ const [value] = clean(input);
51
+
52
+ return strings.splitAt(value, 2, 5).join('-');
53
+ },
54
+
55
+ validate(input: string): ValidateReturn {
56
+ const [value, error] = clean(input);
57
+
58
+ if (error) {
59
+ return { isValid: false, error };
60
+ }
61
+ if (value.length !== 8 && value.length !== 9) {
62
+ return { isValid: false, error: new exceptions.InvalidLength() };
63
+ }
64
+ if (!strings.isdigits(value)) {
65
+ return { isValid: false, error: new exceptions.InvalidFormat() };
66
+ }
67
+
68
+ const [frontV, check] = strings.splitAt(value, -1);
69
+ const front = frontV.padStart(8, '0');
70
+
71
+ let sum =
72
+ (11 -
73
+ weightedSum(front, {
74
+ weights: [3, 2, 7, 6, 5, 4, 3, 2],
75
+ modulus: 11,
76
+ })) %
77
+ 11;
78
+ if (sum === 10) {
79
+ sum =
80
+ (11 -
81
+ weightedSum(front, {
82
+ weights: [7, 4, 3, 2, 5, 2, 7, 6],
83
+ modulus: 11,
84
+ })) %
85
+ 11;
86
+ }
87
+
88
+ if (String(sum) !== check) {
89
+ return { isValid: false, error: new exceptions.InvalidChecksum() };
90
+ }
91
+
92
+ return {
93
+ isValid: true,
94
+ compact: value,
95
+ isIndividual: true, // cannot determine based on ird
96
+ isCompany: true, // cannot determine based on ird
97
+ };
98
+ },
99
+ };
100
+
101
+ export const { name, localName, abbreviation, validate, format, compact } =
102
+ impl;
@@ -0,0 +1,46 @@
1
+ import { validate, format } from './ce';
2
+ import { InvalidLength } from '../exceptions';
3
+
4
+ describe('pe/cui', () => {
5
+ it('format:001766062', () => {
6
+ const result = format('001766062');
7
+
8
+ expect(result).toEqual('001766062');
9
+ });
10
+
11
+ it('validate:001766062', () => {
12
+ const result = validate('001766062');
13
+
14
+ expect(result.isValid && result.compact).toEqual('001766062');
15
+ });
16
+
17
+ it('validate:001043328', () => {
18
+ const result = validate('001043328');
19
+
20
+ expect(result.isValid && result.compact).toEqual('001043328');
21
+ });
22
+
23
+ it('validate:001112311', () => {
24
+ const result = validate('001112311');
25
+
26
+ expect(result.isValid && result.compact).toEqual('001112311');
27
+ });
28
+
29
+ it('validate:000056828', () => {
30
+ const result = validate('000056828');
31
+
32
+ expect(result.isValid && result.compact).toEqual('000056828');
33
+ });
34
+
35
+ it('validate:000494998', () => {
36
+ const result = validate('000494998');
37
+
38
+ expect(result.isValid && result.compact).toEqual('000494998');
39
+ });
40
+
41
+ it('validate:12345678', () => {
42
+ const result = validate('12345678');
43
+
44
+ expect(result.error).toBeInstanceOf(InvalidLength);
45
+ });
46
+ });
package/src/pe/ce.ts ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * CE (Carné de Extranjería, Peruvian ID card for foreigners).
3
+ *
4
+ * Source
5
+ *
6
+ * PERSON TAX
7
+ */
8
+
9
+ import * as exceptions from '../exceptions';
10
+ import { strings } from '../util';
11
+ import { Validator, ValidateReturn } from '../types';
12
+
13
+ function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
14
+ return strings.cleanUnicode(input, ' -');
15
+ }
16
+
17
+ const impl: Validator = {
18
+ name: 'Peruvian ID Card for Foreigners',
19
+ localName: 'Carné de Extranjería',
20
+ abbreviation: 'CE',
21
+
22
+ compact(input: string): string {
23
+ const [value, err] = clean(input);
24
+
25
+ if (err) {
26
+ throw err;
27
+ }
28
+
29
+ return value;
30
+ },
31
+
32
+ format(input: string): string {
33
+ const [value] = clean(input);
34
+
35
+ return value;
36
+ },
37
+
38
+ validate(input: string): ValidateReturn {
39
+ const [value, error] = clean(input);
40
+
41
+ if (error) {
42
+ return { isValid: false, error };
43
+ }
44
+ if (value.length !== 9) {
45
+ return { isValid: false, error: new exceptions.InvalidLength() };
46
+ }
47
+ if (!strings.isdigits(value)) {
48
+ return { isValid: false, error: new exceptions.InvalidFormat() };
49
+ }
50
+
51
+ return {
52
+ isValid: true,
53
+ compact: value,
54
+ isIndividual: true,
55
+ isCompany: false,
56
+ };
57
+ },
58
+ };
59
+
60
+ export const { name, localName, abbreviation, validate, format, compact } =
61
+ impl;
@@ -0,0 +1,28 @@
1
+ import { validate, format } from './cui';
2
+ import { InvalidLength, InvalidChecksum } from '../exceptions';
3
+
4
+ describe('pe/cui', () => {
5
+ it('format:101174102', () => {
6
+ const result = format('101174102');
7
+
8
+ expect(result).toEqual('10117410-2');
9
+ });
10
+
11
+ it('validate:10117410-2', () => {
12
+ const result = validate('10117410-2');
13
+
14
+ expect(result.isValid && result.compact).toEqual('101174102');
15
+ });
16
+
17
+ it('validate:1011741', () => {
18
+ const result = validate('1011741');
19
+
20
+ expect(result.error).toBeInstanceOf(InvalidLength);
21
+ });
22
+
23
+ it('validate:10117410-3', () => {
24
+ const result = validate('10117410-3');
25
+
26
+ expect(result.error).toBeInstanceOf(InvalidChecksum);
27
+ });
28
+ });
package/src/pe/cui.ts ADDED
@@ -0,0 +1,85 @@
1
+ /**
2
+ * CUI (Cédula Única de Identidad, Peruvian Personal Identification Card).
3
+ *
4
+ * The Cédula Única de Identidad is the unique identifier for persons that
5
+ * appears on the Documento Nacional de Identidad (DNI), the national identity
6
+ * document of Peru. The number consists of 8 digits and an optional extra check
7
+ * digit.
8
+ *
9
+ * Source
10
+ * https://www.gob.pe/235-documento-nacional-de-identidad-dni
11
+ * https://es.wikipedia.org/wiki/Documento_Nacional_de_Identidad_(Perú)
12
+ *
13
+ * PERSON
14
+ */
15
+
16
+ import * as exceptions from '../exceptions';
17
+ import { strings, weightedSum } from '../util';
18
+ import { Validator, ValidateReturn } from '../types';
19
+
20
+ function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
21
+ return strings.cleanUnicode(input, ' -');
22
+ }
23
+
24
+ const impl: Validator = {
25
+ name: 'Peruvian Personal Identification Card',
26
+ localName: 'Cédula Única de Identidad',
27
+ abbreviation: 'CUI',
28
+
29
+ compact(input: string): string {
30
+ const [value, err] = clean(input);
31
+
32
+ if (err) {
33
+ throw err;
34
+ }
35
+
36
+ return value;
37
+ },
38
+
39
+ format(input: string): string {
40
+ const [value] = clean(input);
41
+
42
+ if (value.length === 9) {
43
+ return strings.splitAt(value, 8).join('-');
44
+ }
45
+ return value;
46
+ },
47
+
48
+ validate(input: string): ValidateReturn {
49
+ const [value, error] = clean(input);
50
+
51
+ if (error) {
52
+ return { isValid: false, error };
53
+ }
54
+ if (value.length !== 8 && value.length !== 9) {
55
+ return { isValid: false, error: new exceptions.InvalidLength() };
56
+ }
57
+ if (!strings.isdigits(value)) {
58
+ return { isValid: false, error: new exceptions.InvalidFormat() };
59
+ }
60
+
61
+ if (value.length === 9) {
62
+ const [front, check] = strings.splitAt(value, 8);
63
+ const sum = weightedSum(front, {
64
+ weights: [3, 2, 7, 6, 5, 4, 3, 2],
65
+ modulus: 11,
66
+ });
67
+
68
+ const digits = ['65432110987'[sum], 'KJIHGFEDCBA'[sum]];
69
+
70
+ if (!digits.includes(check)) {
71
+ return { isValid: false, error: new exceptions.InvalidChecksum() };
72
+ }
73
+ }
74
+
75
+ return {
76
+ isValid: true,
77
+ compact: value,
78
+ isIndividual: true,
79
+ isCompany: false,
80
+ };
81
+ },
82
+ };
83
+
84
+ export const { name, localName, abbreviation, validate, format, compact } =
85
+ impl;
@@ -0,0 +1,3 @@
1
+ export * as ce from './ce';
2
+ export * as cui from './cui';
3
+ export * as ruc from './ruc';
@@ -0,0 +1,46 @@
1
+ import { validate, format } from './ruc';
2
+ import { InvalidLength, InvalidChecksum } from '../exceptions';
3
+
4
+ describe('pe/cui', () => {
5
+ it('format:20512333797', () => {
6
+ const result = format('20512333797');
7
+
8
+ expect(result).toEqual('20512333797');
9
+ });
10
+
11
+ it('validate:20512333797', () => {
12
+ const result = validate('20512333797');
13
+
14
+ expect(result.isValid && result.compact).toEqual('20512333797');
15
+ });
16
+
17
+ it('validate:205123337', () => {
18
+ const result = validate('205123337');
19
+
20
+ expect(result.error).toBeInstanceOf(InvalidLength);
21
+ });
22
+
23
+ it('validate:20512333798', () => {
24
+ const result = validate('20512333798');
25
+
26
+ expect(result.error).toBeInstanceOf(InvalidChecksum);
27
+ });
28
+
29
+ it('validate:20480977239', () => {
30
+ const result = validate('20480977239');
31
+
32
+ expect(result.isValid && result.compact).toEqual('20480977239');
33
+ });
34
+
35
+ it('validate:20503644968', () => {
36
+ const result = validate('20503644968');
37
+
38
+ expect(result.isValid && result.compact).toEqual('20503644968');
39
+ });
40
+
41
+ it('validate:20515397290', () => {
42
+ const result = validate('20515397290');
43
+
44
+ expect(result.isValid && result.compact).toEqual('20515397290');
45
+ });
46
+ });