@stll/stdnum 0.0.1 → 2.0.0

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 (808) hide show
  1. package/LICENSE +1 -5
  2. package/README.md +28 -4
  3. package/dist/_checksums/luhn.js.map +1 -1
  4. package/dist/_checksums/mod1110.js +1 -1
  5. package/dist/_checksums/mod1110.js.map +1 -1
  6. package/dist/_checksums/mod112.js +5 -5
  7. package/dist/_checksums/mod112.js.map +1 -1
  8. package/dist/_checksums/mod97.js.map +1 -1
  9. package/dist/_checksums/verhoeff.js.map +1 -1
  10. package/dist/_checksums/weighted-sum.js.map +1 -1
  11. package/dist/_util/arabic.js.map +1 -1
  12. package/dist/_util/clean.js.map +1 -1
  13. package/dist/_util/date.js.map +1 -1
  14. package/dist/_util/generate.d.ts +13 -1
  15. package/dist/_util/generate.js +23 -1
  16. package/dist/_util/generate.js.map +1 -1
  17. package/dist/_util/result.js.map +1 -1
  18. package/dist/_util/strings.js.map +1 -1
  19. package/dist/ad/mod.d.ts +3 -2
  20. package/dist/ad/nrt.d.ts +16 -2
  21. package/dist/ad/nrt.js +4 -16
  22. package/dist/ad/nrt.js.map +1 -1
  23. package/dist/ae/eid.d.ts +2 -3
  24. package/dist/ae/eid.js +2 -12
  25. package/dist/ae/eid.js.map +1 -1
  26. package/dist/ae/mod.d.ts +3 -2
  27. package/dist/ai/mod.d.ts +3 -2
  28. package/dist/ai/tin.d.ts +20 -2
  29. package/dist/ai/tin.js +1 -18
  30. package/dist/ai/tin.js.map +1 -1
  31. package/dist/al/mod.d.ts +3 -2
  32. package/dist/al/nipt.d.ts +13 -2
  33. package/dist/al/nipt.js +1 -11
  34. package/dist/al/nipt.js.map +1 -1
  35. package/dist/am/mod.d.ts +3 -2
  36. package/dist/am/tin.d.ts +16 -2
  37. package/dist/am/tin.js +1 -14
  38. package/dist/am/tin.js.map +1 -1
  39. package/dist/ar/cbu.d.ts +2 -3
  40. package/dist/ar/cbu.js +2 -10
  41. package/dist/ar/cbu.js.map +1 -1
  42. package/dist/ar/cuit.d.ts +2 -3
  43. package/dist/ar/cuit.js +13 -29
  44. package/dist/ar/cuit.js.map +1 -1
  45. package/dist/ar/dni.d.ts +11 -2
  46. package/dist/ar/dni.js +1 -9
  47. package/dist/ar/dni.js.map +1 -1
  48. package/dist/ar/mod.d.ts +3 -2
  49. package/dist/at/businessid.d.ts +10 -2
  50. package/dist/at/businessid.js +1 -8
  51. package/dist/at/businessid.js.map +1 -1
  52. package/dist/at/mod.d.ts +3 -2
  53. package/dist/at/tin.d.ts +2 -3
  54. package/dist/at/tin.js +1 -11
  55. package/dist/at/tin.js.map +1 -1
  56. package/dist/at/uid.d.ts +2 -3
  57. package/dist/at/uid.js +2 -10
  58. package/dist/at/uid.js.map +1 -1
  59. package/dist/at/vnr.d.ts +5 -4
  60. package/dist/at/vnr.js +23 -16
  61. package/dist/at/vnr.js.map +1 -1
  62. package/dist/au/abn.d.ts +2 -3
  63. package/dist/au/abn.js +1 -10
  64. package/dist/au/abn.js.map +1 -1
  65. package/dist/au/acn.d.ts +2 -3
  66. package/dist/au/acn.js +1 -10
  67. package/dist/au/acn.js.map +1 -1
  68. package/dist/au/mod.d.ts +3 -2
  69. package/dist/au/tfn.d.ts +2 -3
  70. package/dist/au/tfn.js +1 -10
  71. package/dist/au/tfn.js.map +1 -1
  72. package/dist/az/mod.d.ts +3 -2
  73. package/dist/az/voen.d.ts +2 -3
  74. package/dist/az/voen.js +1 -14
  75. package/dist/az/voen.js.map +1 -1
  76. package/dist/ba/jmbg.d.ts +2 -3
  77. package/dist/ba/jmbg.js +4 -11
  78. package/dist/ba/jmbg.js.map +1 -1
  79. package/dist/ba/mod.d.ts +3 -2
  80. package/dist/bd/mod.d.ts +3 -2
  81. package/dist/bd/nid.d.ts +23 -2
  82. package/dist/bd/nid.js +11 -32
  83. package/dist/bd/nid.js.map +1 -1
  84. package/dist/be/bis.d.ts +2 -3
  85. package/dist/be/bis.js +1 -11
  86. package/dist/be/bis.js.map +1 -1
  87. package/dist/be/mod.d.ts +3 -2
  88. package/dist/be/nn.d.ts +2 -3
  89. package/dist/be/nn.js +1 -11
  90. package/dist/be/nn.js.map +1 -1
  91. package/dist/be/vat.d.ts +2 -3
  92. package/dist/be/vat.js +1 -9
  93. package/dist/be/vat.js.map +1 -1
  94. package/dist/bg/egn.d.ts +2 -3
  95. package/dist/bg/egn.js +5 -13
  96. package/dist/bg/egn.js.map +1 -1
  97. package/dist/bg/mod.d.ts +3 -2
  98. package/dist/bg/pnf.d.ts +2 -3
  99. package/dist/bg/pnf.js +1 -8
  100. package/dist/bg/pnf.js.map +1 -1
  101. package/dist/bg/vat.d.ts +2 -3
  102. package/dist/bg/vat.js +3 -9
  103. package/dist/bg/vat.js.map +1 -1
  104. package/dist/bh/cpr.d.ts +5 -4
  105. package/dist/bh/cpr.js +9 -19
  106. package/dist/bh/cpr.js.map +1 -1
  107. package/dist/bh/mod.d.ts +3 -2
  108. package/dist/bic.d.ts +13 -2
  109. package/dist/bic.js +14 -26
  110. package/dist/bic.js.map +1 -1
  111. package/dist/br/cnpj.d.ts +2 -3
  112. package/dist/br/cnpj.js +1 -20
  113. package/dist/br/cnpj.js.map +1 -1
  114. package/dist/br/cpf.d.ts +2 -3
  115. package/dist/br/cpf.js +1 -14
  116. package/dist/br/cpf.js.map +1 -1
  117. package/dist/br/mod.d.ts +3 -2
  118. package/dist/by/mod.d.ts +3 -2
  119. package/dist/by/unp.d.ts +2 -3
  120. package/dist/by/unp.js +9 -17
  121. package/dist/by/unp.js.map +1 -1
  122. package/dist/bz/mod.d.ts +3 -2
  123. package/dist/bz/tin.d.ts +5 -4
  124. package/dist/bz/tin.js +10 -27
  125. package/dist/bz/tin.js.map +1 -1
  126. package/dist/ca/bn.d.ts +2 -3
  127. package/dist/ca/bn.js +2 -10
  128. package/dist/ca/bn.js.map +1 -1
  129. package/dist/ca/mod.d.ts +3 -2
  130. package/dist/ca/sin.d.ts +2 -3
  131. package/dist/ca/sin.js +2 -10
  132. package/dist/ca/sin.js.map +1 -1
  133. package/dist/ch/mod.d.ts +3 -2
  134. package/dist/ch/ssn.d.ts +2 -3
  135. package/dist/ch/ssn.js +1 -9
  136. package/dist/ch/ssn.js.map +1 -1
  137. package/dist/ch/uid.d.ts +2 -3
  138. package/dist/ch/uid.js +1 -9
  139. package/dist/ch/uid.js.map +1 -1
  140. package/dist/ch/vat.d.ts +2 -3
  141. package/dist/ch/vat.js +1 -9
  142. package/dist/ch/vat.js.map +1 -1
  143. package/dist/cl/mod.d.ts +3 -2
  144. package/dist/cl/rut.d.ts +2 -3
  145. package/dist/cl/rut.js +2 -15
  146. package/dist/cl/rut.js.map +1 -1
  147. package/dist/cn/mod.d.ts +3 -2
  148. package/dist/cn/ric.d.ts +2 -3
  149. package/dist/cn/ric.js +4 -14
  150. package/dist/cn/ric.js.map +1 -1
  151. package/dist/cn/uscc.d.ts +2 -3
  152. package/dist/cn/uscc.js +8 -16
  153. package/dist/cn/uscc.js.map +1 -1
  154. package/dist/co/mod.d.ts +3 -2
  155. package/dist/co/nit.d.ts +2 -3
  156. package/dist/co/nit.js +6 -13
  157. package/dist/co/nit.js.map +1 -1
  158. package/dist/cr/cpf.d.ts +18 -2
  159. package/dist/cr/cpf.js +5 -19
  160. package/dist/cr/cpf.js.map +1 -1
  161. package/dist/cr/mod.d.ts +3 -2
  162. package/dist/creditcard.d.ts +2 -3
  163. package/dist/creditcard.js +5 -14
  164. package/dist/creditcard.js.map +1 -1
  165. package/dist/cu/mod.d.ts +3 -2
  166. package/dist/cu/ni.d.ts +5 -4
  167. package/dist/cu/ni.js +13 -18
  168. package/dist/cu/ni.js.map +1 -1
  169. package/dist/cy/mod.d.ts +3 -2
  170. package/dist/cy/vat.d.ts +2 -3
  171. package/dist/cy/vat.js +1 -8
  172. package/dist/cy/vat.js.map +1 -1
  173. package/dist/cz/dic.d.ts +2 -3
  174. package/dist/cz/dic.js +7 -13
  175. package/dist/cz/dic.js.map +1 -1
  176. package/dist/cz/ico.d.ts +2 -3
  177. package/dist/cz/ico.js +2 -10
  178. package/dist/cz/ico.js.map +1 -1
  179. package/dist/cz/mod.d.ts +3 -2
  180. package/dist/cz/rc.d.ts +2 -3
  181. package/dist/cz/rc.js +22 -21
  182. package/dist/cz/rc.js.map +1 -1
  183. package/dist/de/handelsreg.d.ts +19 -2
  184. package/dist/de/handelsreg.js +10 -26
  185. package/dist/de/handelsreg.js.map +1 -1
  186. package/dist/de/idnr.d.ts +2 -3
  187. package/dist/de/idnr.js +2 -12
  188. package/dist/de/idnr.js.map +1 -1
  189. package/dist/de/mod.d.ts +3 -2
  190. package/dist/de/stnr.d.ts +17 -3
  191. package/dist/de/stnr.js +1 -15
  192. package/dist/de/stnr.js.map +1 -1
  193. package/dist/de/svnr.d.ts +2 -3
  194. package/dist/de/svnr.js +4 -13
  195. package/dist/de/svnr.js.map +1 -1
  196. package/dist/de/vat.d.ts +2 -3
  197. package/dist/de/vat.js +2 -11
  198. package/dist/de/vat.js.map +1 -1
  199. package/dist/dk/cpr.d.ts +5 -4
  200. package/dist/dk/cpr.js +14 -12
  201. package/dist/dk/cpr.js.map +1 -1
  202. package/dist/dk/cvr.d.ts +2 -3
  203. package/dist/dk/cvr.js +2 -15
  204. package/dist/dk/cvr.js.map +1 -1
  205. package/dist/dk/mod.d.ts +3 -2
  206. package/dist/dk/vat.d.ts +2 -3
  207. package/dist/dk/vat.js +3 -13
  208. package/dist/dk/vat.js.map +1 -1
  209. package/dist/do/mod.d.ts +3 -2
  210. package/dist/do/rnc.d.ts +2 -3
  211. package/dist/do/rnc.js +3 -17
  212. package/dist/do/rnc.js.map +1 -1
  213. package/dist/ec/mod.d.ts +3 -2
  214. package/dist/ec/ruc.d.ts +2 -3
  215. package/dist/ec/ruc.js +2 -19
  216. package/dist/ec/ruc.js.map +1 -1
  217. package/dist/ee/ik.d.ts +2 -3
  218. package/dist/ee/ik.js +6 -15
  219. package/dist/ee/ik.js.map +1 -1
  220. package/dist/ee/mod.d.ts +3 -2
  221. package/dist/ee/registrikood.d.ts +2 -3
  222. package/dist/ee/registrikood.js +9 -15
  223. package/dist/ee/registrikood.js.map +1 -1
  224. package/dist/ee/vat.d.ts +2 -3
  225. package/dist/ee/vat.js +2 -10
  226. package/dist/ee/vat.js.map +1 -1
  227. package/dist/eg/mod.d.ts +3 -2
  228. package/dist/eg/tn.d.ts +11 -2
  229. package/dist/eg/tn.js +1 -9
  230. package/dist/eg/tn.js.map +1 -1
  231. package/dist/es/cif.d.ts +2 -3
  232. package/dist/es/cif.js +3 -12
  233. package/dist/es/cif.js.map +1 -1
  234. package/dist/es/dni.d.ts +2 -3
  235. package/dist/es/dni.js +1 -9
  236. package/dist/es/dni.js.map +1 -1
  237. package/dist/es/mod.d.ts +3 -2
  238. package/dist/es/nie.d.ts +2 -3
  239. package/dist/es/nie.js +14 -22
  240. package/dist/es/nie.js.map +1 -1
  241. package/dist/es/nss.d.ts +2 -3
  242. package/dist/es/nss.js +1 -16
  243. package/dist/es/nss.js.map +1 -1
  244. package/dist/es/vat.d.ts +2 -3
  245. package/dist/es/vat.js +5 -10
  246. package/dist/es/vat.js.map +1 -1
  247. package/dist/eu/mod.d.ts +3 -2
  248. package/dist/eu/vat.d.ts +5 -4
  249. package/dist/eu/vat.js +44 -2
  250. package/dist/eu/vat.js.map +1 -1
  251. package/dist/fi/hetu.d.ts +5 -4
  252. package/dist/fi/hetu.js +19 -12
  253. package/dist/fi/hetu.js.map +1 -1
  254. package/dist/fi/mod.d.ts +3 -2
  255. package/dist/fi/vat.d.ts +2 -3
  256. package/dist/fi/vat.js +3 -10
  257. package/dist/fi/vat.js.map +1 -1
  258. package/dist/fi/ytunnus.d.ts +2 -3
  259. package/dist/fi/ytunnus.js +2 -10
  260. package/dist/fi/ytunnus.js.map +1 -1
  261. package/dist/fr/mod.d.ts +3 -2
  262. package/dist/fr/nif.d.ts +2 -3
  263. package/dist/fr/nif.js +1 -9
  264. package/dist/fr/nif.js.map +1 -1
  265. package/dist/fr/nir.d.ts +2 -3
  266. package/dist/fr/nir.js +3 -14
  267. package/dist/fr/nir.js.map +1 -1
  268. package/dist/fr/siren.d.ts +2 -3
  269. package/dist/fr/siren.js +2 -10
  270. package/dist/fr/siren.js.map +1 -1
  271. package/dist/fr/siret.d.ts +2 -3
  272. package/dist/fr/siret.js +2 -11
  273. package/dist/fr/siret.js.map +1 -1
  274. package/dist/fr/tva.d.ts +2 -3
  275. package/dist/fr/tva.js +2 -12
  276. package/dist/fr/tva.js.map +1 -1
  277. package/dist/gb/mod.d.ts +3 -2
  278. package/dist/gb/nino.d.ts +12 -2
  279. package/dist/gb/nino.js +8 -17
  280. package/dist/gb/nino.js.map +1 -1
  281. package/dist/gb/sedol.d.ts +2 -3
  282. package/dist/gb/sedol.js +9 -18
  283. package/dist/gb/sedol.js.map +1 -1
  284. package/dist/gb/utr.d.ts +2 -3
  285. package/dist/gb/utr.js +2 -10
  286. package/dist/gb/utr.js.map +1 -1
  287. package/dist/gb/vat.d.ts +2 -3
  288. package/dist/gb/vat.js +2 -11
  289. package/dist/gb/vat.js.map +1 -1
  290. package/dist/ge/mod.d.ts +3 -2
  291. package/dist/ge/pin.d.ts +14 -2
  292. package/dist/ge/pin.js +1 -12
  293. package/dist/ge/pin.js.map +1 -1
  294. package/dist/gh/mod.d.ts +3 -2
  295. package/dist/gh/tin.d.ts +2 -3
  296. package/dist/gh/tin.js +10 -24
  297. package/dist/gh/tin.js.map +1 -1
  298. package/dist/gr/amka.d.ts +2 -3
  299. package/dist/gr/amka.js +3 -11
  300. package/dist/gr/amka.js.map +1 -1
  301. package/dist/gr/mod.d.ts +3 -2
  302. package/dist/gr/vat.d.ts +2 -3
  303. package/dist/gr/vat.js +1 -10
  304. package/dist/gr/vat.js.map +1 -1
  305. package/dist/gt/mod.d.ts +3 -2
  306. package/dist/gt/nit.d.ts +2 -3
  307. package/dist/gt/nit.js +6 -14
  308. package/dist/gt/nit.js.map +1 -1
  309. package/dist/hk/hkid.d.ts +2 -3
  310. package/dist/hk/hkid.js +2 -10
  311. package/dist/hk/hkid.js.map +1 -1
  312. package/dist/hk/mod.d.ts +3 -2
  313. package/dist/hr/mod.d.ts +3 -2
  314. package/dist/hr/vat.d.ts +2 -3
  315. package/dist/hr/vat.js +2 -9
  316. package/dist/hr/vat.js.map +1 -1
  317. package/dist/hu/mod.d.ts +3 -2
  318. package/dist/hu/vat.d.ts +2 -3
  319. package/dist/hu/vat.js +3 -10
  320. package/dist/hu/vat.js.map +1 -1
  321. package/dist/iban.d.ts +2 -3
  322. package/dist/iban.js +2 -8
  323. package/dist/iban.js.map +1 -1
  324. package/dist/id/mod.d.ts +3 -2
  325. package/dist/id/npwp.d.ts +2 -3
  326. package/dist/id/npwp.js +3 -13
  327. package/dist/id/npwp.js.map +1 -1
  328. package/dist/ie/mod.d.ts +3 -2
  329. package/dist/ie/pps.d.ts +2 -3
  330. package/dist/ie/pps.js +1 -10
  331. package/dist/ie/pps.js.map +1 -1
  332. package/dist/ie/vat.d.ts +2 -3
  333. package/dist/ie/vat.js +1 -9
  334. package/dist/ie/vat.js.map +1 -1
  335. package/dist/il/idnr.d.ts +2 -3
  336. package/dist/il/idnr.js +2 -9
  337. package/dist/il/idnr.js.map +1 -1
  338. package/dist/il/mod.d.ts +3 -2
  339. package/dist/in/aadhaar.d.ts +2 -3
  340. package/dist/in/aadhaar.js +2 -12
  341. package/dist/in/aadhaar.js.map +1 -1
  342. package/dist/in/gstin.d.ts +2 -3
  343. package/dist/in/gstin.js +4 -11
  344. package/dist/in/gstin.js.map +1 -1
  345. package/dist/in/mod.d.ts +3 -2
  346. package/dist/in/pan.d.ts +15 -2
  347. package/dist/in/pan.js +3 -15
  348. package/dist/in/pan.js.map +1 -1
  349. package/dist/index.d.ts +2 -2
  350. package/dist/index.js +6 -6
  351. package/dist/iq/mod.d.ts +3 -2
  352. package/dist/iq/nid.d.ts +16 -2
  353. package/dist/iq/nid.js +2 -15
  354. package/dist/iq/nid.js.map +1 -1
  355. package/dist/ir/mod.d.ts +3 -2
  356. package/dist/ir/nid.d.ts +2 -3
  357. package/dist/ir/nid.js +2 -24
  358. package/dist/ir/nid.js.map +1 -1
  359. package/dist/is/kennitala.d.ts +2 -3
  360. package/dist/is/kennitala.js +2 -13
  361. package/dist/is/kennitala.js.map +1 -1
  362. package/dist/is/mod.d.ts +3 -2
  363. package/dist/is/vsk.d.ts +9 -2
  364. package/dist/is/vsk.js +1 -7
  365. package/dist/is/vsk.js.map +1 -1
  366. package/dist/isin.d.ts +2 -3
  367. package/dist/isin.js +11 -21
  368. package/dist/isin.js.map +1 -1
  369. package/dist/it/codicefiscale.d.ts +5 -4
  370. package/dist/it/codicefiscale.js +27 -23
  371. package/dist/it/codicefiscale.js.map +1 -1
  372. package/dist/it/iva.d.ts +2 -3
  373. package/dist/it/iva.js +2 -9
  374. package/dist/it/iva.js.map +1 -1
  375. package/dist/it/mod.d.ts +3 -2
  376. package/dist/jp/cn.d.ts +2 -3
  377. package/dist/jp/cn.js +1 -9
  378. package/dist/jp/cn.js.map +1 -1
  379. package/dist/jp/mod.d.ts +3 -2
  380. package/dist/jp/mynumber.d.ts +2 -3
  381. package/dist/jp/mynumber.js +1 -10
  382. package/dist/jp/mynumber.js.map +1 -1
  383. package/dist/kr/brn.d.ts +11 -2
  384. package/dist/kr/brn.js +1 -9
  385. package/dist/kr/brn.js.map +1 -1
  386. package/dist/kr/mod.d.ts +3 -2
  387. package/dist/kr/rrn.d.ts +5 -4
  388. package/dist/kr/rrn.js +15 -13
  389. package/dist/kr/rrn.js.map +1 -1
  390. package/dist/kw/civil.d.ts +6 -5
  391. package/dist/kw/civil.js +20 -17
  392. package/dist/kw/civil.js.map +1 -1
  393. package/dist/kw/mod.d.ts +3 -2
  394. package/dist/kz/iin.d.ts +2 -3
  395. package/dist/kz/iin.js +4 -18
  396. package/dist/kz/iin.js.map +1 -1
  397. package/dist/kz/mod.d.ts +3 -2
  398. package/dist/lei.d.ts +2 -3
  399. package/dist/lei.js +2 -11
  400. package/dist/lei.js.map +1 -1
  401. package/dist/li/mod.d.ts +3 -2
  402. package/dist/li/peid.d.ts +11 -2
  403. package/dist/li/peid.js +1 -9
  404. package/dist/li/peid.js.map +1 -1
  405. package/dist/lk/mod.d.ts +3 -2
  406. package/dist/lk/nic.d.ts +5 -4
  407. package/dist/lk/nic.js +16 -16
  408. package/dist/lk/nic.js.map +1 -1
  409. package/dist/lt/asmens.d.ts +2 -3
  410. package/dist/lt/asmens.js +2 -1
  411. package/dist/lt/asmens.js.map +1 -1
  412. package/dist/lt/mod.d.ts +3 -2
  413. package/dist/lt/vat.d.ts +2 -3
  414. package/dist/lt/vat.js +2 -10
  415. package/dist/lt/vat.js.map +1 -1
  416. package/dist/lu/mod.d.ts +3 -2
  417. package/dist/lu/vat.d.ts +2 -3
  418. package/dist/lu/vat.js +2 -8
  419. package/dist/lu/vat.js.map +1 -1
  420. package/dist/luhn.d.ts +2 -3
  421. package/dist/luhn.js +9 -9
  422. package/dist/luhn.js.map +1 -1
  423. package/dist/lv/mod.d.ts +3 -2
  424. package/dist/lv/vat.d.ts +2 -3
  425. package/dist/lv/vat.js +19 -18
  426. package/dist/lv/vat.js.map +1 -1
  427. package/dist/ma/ice.d.ts +2 -3
  428. package/dist/ma/ice.js +2 -11
  429. package/dist/ma/ice.js.map +1 -1
  430. package/dist/ma/mod.d.ts +3 -2
  431. package/dist/mc/mod.d.ts +3 -2
  432. package/dist/mc/tva.d.ts +2 -3
  433. package/dist/mc/tva.js +1 -0
  434. package/dist/mc/tva.js.map +1 -1
  435. package/dist/md/idno.d.ts +2 -3
  436. package/dist/md/idno.js +1 -10
  437. package/dist/md/idno.js.map +1 -1
  438. package/dist/md/mod.d.ts +3 -2
  439. package/dist/me/mod.d.ts +3 -2
  440. package/dist/me/pib.d.ts +2 -3
  441. package/dist/me/pib.js +2 -10
  442. package/dist/me/pib.js.map +1 -1
  443. package/dist/mk/edb.d.ts +2 -3
  444. package/dist/mk/edb.js +2 -11
  445. package/dist/mk/edb.js.map +1 -1
  446. package/dist/mk/mod.d.ts +3 -2
  447. package/dist/mt/mod.d.ts +3 -2
  448. package/dist/mt/vat.d.ts +2 -3
  449. package/dist/mt/vat.js +3 -10
  450. package/dist/mt/vat.js.map +1 -1
  451. package/dist/mu/brn.d.ts +23 -2
  452. package/dist/mu/brn.js +1 -21
  453. package/dist/mu/brn.js.map +1 -1
  454. package/dist/mu/mod.d.ts +3 -2
  455. package/dist/mx/clabe.d.ts +2 -3
  456. package/dist/mx/clabe.js +1 -14
  457. package/dist/mx/clabe.js.map +1 -1
  458. package/dist/mx/curp.d.ts +5 -4
  459. package/dist/mx/curp.js +27 -19
  460. package/dist/mx/curp.js.map +1 -1
  461. package/dist/mx/mod.d.ts +3 -2
  462. package/dist/mx/rfc.d.ts +5 -4
  463. package/dist/mx/rfc.js +23 -20
  464. package/dist/mx/rfc.js.map +1 -1
  465. package/dist/my/mod.d.ts +3 -2
  466. package/dist/my/nric.d.ts +5 -4
  467. package/dist/my/nric.js +18 -16
  468. package/dist/my/nric.js.map +1 -1
  469. package/dist/ng/mod.d.ts +3 -2
  470. package/dist/ng/nin.d.ts +13 -2
  471. package/dist/ng/nin.js +1 -11
  472. package/dist/ng/nin.js.map +1 -1
  473. package/dist/ni/mod.d.ts +3 -2
  474. package/dist/ni/ruc.d.ts +2 -3
  475. package/dist/ni/ruc.js +1 -23
  476. package/dist/ni/ruc.js.map +1 -1
  477. package/dist/nl/bsn.d.ts +2 -3
  478. package/dist/nl/bsn.js +2 -10
  479. package/dist/nl/bsn.js.map +1 -1
  480. package/dist/nl/kvk.d.ts +9 -2
  481. package/dist/nl/kvk.js +1 -7
  482. package/dist/nl/kvk.js.map +1 -1
  483. package/dist/nl/mod.d.ts +3 -2
  484. package/dist/nl/vat.d.ts +2 -3
  485. package/dist/nl/vat.js +4 -50
  486. package/dist/nl/vat.js.map +1 -1
  487. package/dist/no/fodselsnummer.d.ts +2 -3
  488. package/dist/no/fodselsnummer.js +3 -10
  489. package/dist/no/fodselsnummer.js.map +1 -1
  490. package/dist/no/mod.d.ts +3 -2
  491. package/dist/no/mva.d.ts +2 -3
  492. package/dist/no/mva.js +1 -8
  493. package/dist/no/mva.js.map +1 -1
  494. package/dist/no/orgnr.d.ts +2 -3
  495. package/dist/no/orgnr.js +2 -8
  496. package/dist/no/orgnr.js.map +1 -1
  497. package/dist/nz/ird.d.ts +2 -3
  498. package/dist/nz/ird.js +4 -13
  499. package/dist/nz/ird.js.map +1 -1
  500. package/dist/nz/mod.d.ts +3 -2
  501. package/dist/pa/mod.d.ts +3 -2
  502. package/dist/pa/ruc.d.ts +2 -3
  503. package/dist/pa/ruc.js +4 -19
  504. package/dist/pa/ruc.js.map +1 -1
  505. package/dist/patterns.d.ts +8 -10
  506. package/dist/patterns.js +83 -28
  507. package/dist/patterns.js.map +1 -1
  508. package/dist/pe/mod.d.ts +3 -2
  509. package/dist/pe/ruc.d.ts +2 -3
  510. package/dist/pe/ruc.js +10 -24
  511. package/dist/pe/ruc.js.map +1 -1
  512. package/dist/ph/mod.d.ts +3 -2
  513. package/dist/ph/philid.d.ts +14 -2
  514. package/dist/ph/philid.js +1 -12
  515. package/dist/ph/philid.js.map +1 -1
  516. package/dist/pk/cnic.d.ts +14 -2
  517. package/dist/pk/cnic.js +1 -12
  518. package/dist/pk/cnic.js.map +1 -1
  519. package/dist/pk/mod.d.ts +3 -2
  520. package/dist/pl/mod.d.ts +3 -2
  521. package/dist/pl/nip.d.ts +2 -3
  522. package/dist/pl/nip.js +2 -10
  523. package/dist/pl/nip.js.map +1 -1
  524. package/dist/pl/pesel.d.ts +2 -3
  525. package/dist/pl/pesel.js +4 -13
  526. package/dist/pl/pesel.js.map +1 -1
  527. package/dist/pl/regon.d.ts +2 -3
  528. package/dist/pl/regon.js +2 -11
  529. package/dist/pl/regon.js.map +1 -1
  530. package/dist/pt/cc.d.ts +2 -3
  531. package/dist/pt/cc.js +7 -13
  532. package/dist/pt/cc.js.map +1 -1
  533. package/dist/pt/mod.d.ts +3 -2
  534. package/dist/pt/vat.d.ts +2 -3
  535. package/dist/pt/vat.js +3 -11
  536. package/dist/pt/vat.js.map +1 -1
  537. package/dist/ro/cnp.d.ts +2 -3
  538. package/dist/ro/cnp.js +5 -14
  539. package/dist/ro/cnp.js.map +1 -1
  540. package/dist/ro/mod.d.ts +3 -2
  541. package/dist/ro/vat.d.ts +2 -3
  542. package/dist/ro/vat.js +13 -11
  543. package/dist/ro/vat.js.map +1 -1
  544. package/dist/rs/mod.d.ts +3 -2
  545. package/dist/rs/pib.d.ts +2 -3
  546. package/dist/rs/pib.js +1 -9
  547. package/dist/rs/pib.js.map +1 -1
  548. package/dist/ru/inn.d.ts +2 -3
  549. package/dist/ru/inn.js +2 -12
  550. package/dist/ru/inn.js.map +1 -1
  551. package/dist/ru/mod.d.ts +3 -2
  552. package/dist/se/mod.d.ts +3 -2
  553. package/dist/se/orgnr.d.ts +2 -3
  554. package/dist/se/orgnr.js +2 -9
  555. package/dist/se/orgnr.js.map +1 -1
  556. package/dist/se/personnummer.d.ts +2 -3
  557. package/dist/se/personnummer.js +8 -15
  558. package/dist/se/personnummer.js.map +1 -1
  559. package/dist/se/vat.d.ts +2 -3
  560. package/dist/se/vat.js +3 -10
  561. package/dist/se/vat.js.map +1 -1
  562. package/dist/sg/mod.d.ts +3 -2
  563. package/dist/sg/uen.d.ts +2 -3
  564. package/dist/sg/uen.js +47 -70
  565. package/dist/sg/uen.js.map +1 -1
  566. package/dist/si/emso.d.ts +2 -3
  567. package/dist/si/emso.js +12 -14
  568. package/dist/si/emso.js.map +1 -1
  569. package/dist/si/mod.d.ts +3 -2
  570. package/dist/si/vat.d.ts +2 -3
  571. package/dist/si/vat.js +3 -12
  572. package/dist/si/vat.js.map +1 -1
  573. package/dist/sk/dic.d.ts +2 -3
  574. package/dist/sk/dic.js +1 -0
  575. package/dist/sk/dic.js.map +1 -1
  576. package/dist/sk/ico.d.ts +2 -3
  577. package/dist/sk/ico.js +1 -0
  578. package/dist/sk/ico.js.map +1 -1
  579. package/dist/sk/mod.d.ts +3 -2
  580. package/dist/sk/rc.d.ts +4 -5
  581. package/dist/sk/rc.js +6 -2
  582. package/dist/sk/rc.js.map +1 -1
  583. package/dist/th/mod.d.ts +3 -2
  584. package/dist/th/tin.d.ts +2 -3
  585. package/dist/th/tin.js +1 -11
  586. package/dist/th/tin.js.map +1 -1
  587. package/dist/tr/mod.d.ts +3 -2
  588. package/dist/tr/tckimlik.d.ts +2 -3
  589. package/dist/tr/tckimlik.js +1 -20
  590. package/dist/tr/tckimlik.js.map +1 -1
  591. package/dist/tr/vkn.d.ts +2 -3
  592. package/dist/tr/vkn.js +1 -20
  593. package/dist/tr/vkn.js.map +1 -1
  594. package/dist/tw/mod.d.ts +3 -2
  595. package/dist/tw/ubn.d.ts +2 -3
  596. package/dist/tw/ubn.js +2 -12
  597. package/dist/tw/ubn.js.map +1 -1
  598. package/dist/types.d.ts +56 -21
  599. package/dist/ua/edrpou.d.ts +2 -3
  600. package/dist/ua/edrpou.js +5 -12
  601. package/dist/ua/edrpou.js.map +1 -1
  602. package/dist/ua/mod.d.ts +3 -2
  603. package/dist/us/ein.d.ts +12 -2
  604. package/dist/us/ein.js +88 -97
  605. package/dist/us/ein.js.map +1 -1
  606. package/dist/us/itin.d.ts +13 -2
  607. package/dist/us/itin.js +4 -15
  608. package/dist/us/itin.js.map +1 -1
  609. package/dist/us/mod.d.ts +3 -2
  610. package/dist/us/rtn.d.ts +2 -3
  611. package/dist/us/rtn.js +11 -23
  612. package/dist/us/rtn.js.map +1 -1
  613. package/dist/us/ssn.d.ts +13 -2
  614. package/dist/us/ssn.js +1 -11
  615. package/dist/us/ssn.js.map +1 -1
  616. package/dist/uy/mod.d.ts +3 -2
  617. package/dist/uy/rut.d.ts +2 -3
  618. package/dist/uy/rut.js +2 -15
  619. package/dist/uy/rut.js.map +1 -1
  620. package/dist/ve/mod.d.ts +3 -2
  621. package/dist/ve/rif.d.ts +2 -3
  622. package/dist/ve/rif.js +13 -26
  623. package/dist/ve/rif.js.map +1 -1
  624. package/dist/vn/mod.d.ts +3 -2
  625. package/dist/vn/mst.d.ts +2 -3
  626. package/dist/vn/mst.js +1 -12
  627. package/dist/vn/mst.js.map +1 -1
  628. package/dist/za/idnr.d.ts +2 -3
  629. package/dist/za/idnr.js +4 -16
  630. package/dist/za/idnr.js.map +1 -1
  631. package/dist/za/mod.d.ts +3 -2
  632. package/package.json +34 -21
  633. package/src/_checksums/mod1110.ts +1 -1
  634. package/src/_checksums/mod112.ts +7 -6
  635. package/src/_util/generate.ts +38 -0
  636. package/src/ad/nrt.ts +19 -7
  637. package/src/ae/eid.ts +7 -3
  638. package/src/ai/tin.ts +7 -3
  639. package/src/al/nipt.ts +7 -3
  640. package/src/am/tin.ts +7 -3
  641. package/src/ar/cbu.ts +9 -5
  642. package/src/ar/cuit.ts +22 -10
  643. package/src/ar/dni.ts +7 -3
  644. package/src/at/businessid.ts +7 -3
  645. package/src/at/tin.ts +7 -3
  646. package/src/at/uid.ts +7 -3
  647. package/src/at/vnr.ts +62 -12
  648. package/src/au/abn.ts +7 -3
  649. package/src/au/acn.ts +7 -3
  650. package/src/au/tfn.ts +7 -3
  651. package/src/az/voen.ts +9 -3
  652. package/src/ba/jmbg.ts +9 -7
  653. package/src/bd/nid.ts +11 -7
  654. package/src/be/bis.ts +8 -4
  655. package/src/be/nn.ts +7 -3
  656. package/src/be/vat.ts +7 -3
  657. package/src/bg/egn.ts +19 -10
  658. package/src/bg/pnf.ts +7 -3
  659. package/src/bg/vat.ts +8 -3
  660. package/src/bh/cpr.ts +17 -4
  661. package/src/bic.ts +26 -20
  662. package/src/br/cnpj.ts +7 -3
  663. package/src/br/cpf.ts +7 -3
  664. package/src/by/unp.ts +19 -9
  665. package/src/bz/tin.ts +19 -4
  666. package/src/ca/bn.ts +7 -3
  667. package/src/ca/sin.ts +7 -3
  668. package/src/ch/ssn.ts +7 -3
  669. package/src/ch/uid.ts +7 -3
  670. package/src/ch/vat.ts +9 -5
  671. package/src/cl/rut.ts +11 -5
  672. package/src/cn/ric.ts +11 -7
  673. package/src/cn/uscc.ts +27 -11
  674. package/src/co/nit.ts +14 -6
  675. package/src/cr/cpf.ts +11 -6
  676. package/src/creditcard.ts +10 -6
  677. package/src/cu/ni.ts +28 -7
  678. package/src/cy/vat.ts +7 -3
  679. package/src/cz/dic.ts +9 -4
  680. package/src/cz/ico.ts +7 -3
  681. package/src/cz/rc.ts +61 -29
  682. package/src/de/handelsreg.ts +21 -6
  683. package/src/de/idnr.ts +10 -3
  684. package/src/de/stnr.ts +11 -3
  685. package/src/de/svnr.ts +14 -5
  686. package/src/de/vat.ts +7 -3
  687. package/src/dk/cpr.ts +23 -8
  688. package/src/dk/cvr.ts +7 -3
  689. package/src/dk/vat.ts +8 -3
  690. package/src/do/rnc.ts +9 -5
  691. package/src/ec/ruc.ts +9 -5
  692. package/src/ee/ik.ts +21 -10
  693. package/src/ee/registrikood.ts +12 -7
  694. package/src/ee/vat.ts +7 -3
  695. package/src/eg/tn.ts +7 -3
  696. package/src/es/cif.ts +10 -7
  697. package/src/es/dni.ts +7 -3
  698. package/src/es/nie.ts +18 -9
  699. package/src/es/nss.ts +7 -3
  700. package/src/es/vat.ts +13 -5
  701. package/src/eu/vat.ts +55 -6
  702. package/src/fi/hetu.ts +26 -8
  703. package/src/fi/vat.ts +8 -3
  704. package/src/fi/ytunnus.ts +7 -3
  705. package/src/fr/nif.ts +7 -3
  706. package/src/fr/nir.ts +9 -7
  707. package/src/fr/siren.ts +7 -3
  708. package/src/fr/siret.ts +7 -3
  709. package/src/fr/tva.ts +7 -3
  710. package/src/gb/nino.ts +18 -13
  711. package/src/gb/sedol.ts +21 -15
  712. package/src/gb/utr.ts +7 -3
  713. package/src/gb/vat.ts +7 -3
  714. package/src/ge/pin.ts +7 -3
  715. package/src/gh/tin.ts +11 -6
  716. package/src/gr/amka.ts +7 -3
  717. package/src/gr/vat.ts +7 -3
  718. package/src/gt/nit.ts +13 -6
  719. package/src/hk/hkid.ts +9 -4
  720. package/src/hr/vat.ts +7 -3
  721. package/src/hu/vat.ts +8 -3
  722. package/src/iban.ts +7 -3
  723. package/src/id/npwp.ts +7 -3
  724. package/src/ie/pps.ts +7 -3
  725. package/src/ie/vat.ts +7 -3
  726. package/src/il/idnr.ts +7 -3
  727. package/src/in/aadhaar.ts +7 -3
  728. package/src/in/gstin.ts +10 -4
  729. package/src/in/pan.ts +15 -6
  730. package/src/index.ts +6 -0
  731. package/src/iq/nid.ts +7 -3
  732. package/src/ir/nid.ts +7 -3
  733. package/src/is/kennitala.ts +7 -3
  734. package/src/is/vsk.ts +7 -3
  735. package/src/isin.ts +17 -7
  736. package/src/it/codicefiscale.ts +49 -7
  737. package/src/it/iva.ts +7 -3
  738. package/src/jp/cn.ts +7 -3
  739. package/src/jp/mynumber.ts +7 -3
  740. package/src/kr/brn.ts +7 -3
  741. package/src/kr/rrn.ts +27 -8
  742. package/src/kw/civil.ts +31 -14
  743. package/src/kz/iin.ts +9 -8
  744. package/src/lei.ts +7 -3
  745. package/src/li/peid.ts +7 -3
  746. package/src/lk/nic.ts +31 -8
  747. package/src/lt/asmens.ts +8 -4
  748. package/src/lt/vat.ts +8 -3
  749. package/src/lu/vat.ts +8 -3
  750. package/src/luhn.ts +10 -3
  751. package/src/lv/vat.ts +53 -23
  752. package/src/ma/ice.ts +7 -3
  753. package/src/mc/tva.ts +9 -5
  754. package/src/md/idno.ts +7 -3
  755. package/src/me/pib.ts +7 -3
  756. package/src/mk/edb.ts +7 -3
  757. package/src/mt/vat.ts +8 -3
  758. package/src/mu/brn.ts +7 -3
  759. package/src/mx/clabe.ts +7 -3
  760. package/src/mx/curp.ts +47 -10
  761. package/src/mx/rfc.ts +42 -7
  762. package/src/my/nric.ts +33 -8
  763. package/src/ng/nin.ts +7 -3
  764. package/src/ni/ruc.ts +7 -3
  765. package/src/nl/bsn.ts +7 -3
  766. package/src/nl/kvk.ts +7 -3
  767. package/src/nl/vat.ts +18 -69
  768. package/src/no/fodselsnummer.ts +12 -7
  769. package/src/no/mva.ts +9 -5
  770. package/src/no/orgnr.ts +7 -3
  771. package/src/nz/ird.ts +12 -8
  772. package/src/pa/ruc.ts +39 -11
  773. package/src/patterns.ts +184 -46
  774. package/src/pe/ruc.ts +13 -10
  775. package/src/ph/philid.ts +7 -3
  776. package/src/pk/cnic.ts +9 -3
  777. package/src/pl/nip.ts +7 -3
  778. package/src/pl/pesel.ts +9 -7
  779. package/src/pl/regon.ts +7 -3
  780. package/src/pt/cc.ts +13 -7
  781. package/src/pt/vat.ts +8 -3
  782. package/src/ro/cnp.ts +16 -8
  783. package/src/ro/vat.ts +8 -3
  784. package/src/rs/pib.ts +7 -3
  785. package/src/ru/inn.ts +9 -5
  786. package/src/se/orgnr.ts +7 -3
  787. package/src/se/personnummer.ts +35 -32
  788. package/src/se/vat.ts +8 -3
  789. package/src/sg/uen.ts +44 -23
  790. package/src/si/emso.ts +37 -11
  791. package/src/si/vat.ts +8 -3
  792. package/src/sk/dic.ts +8 -4
  793. package/src/sk/ico.ts +3 -2
  794. package/src/sk/rc.ts +17 -4
  795. package/src/th/tin.ts +7 -3
  796. package/src/tr/tckimlik.ts +7 -3
  797. package/src/tr/vkn.ts +7 -3
  798. package/src/tw/ubn.ts +9 -5
  799. package/src/types.ts +69 -7
  800. package/src/ua/edrpou.ts +10 -5
  801. package/src/us/ein.ts +95 -91
  802. package/src/us/itin.ts +14 -11
  803. package/src/us/rtn.ts +32 -19
  804. package/src/us/ssn.ts +7 -3
  805. package/src/uy/rut.ts +9 -5
  806. package/src/ve/rif.ts +19 -12
  807. package/src/vn/mst.ts +7 -3
  808. package/src/za/idnr.ts +9 -7
package/src/no/orgnr.ts CHANGED
@@ -6,14 +6,17 @@
6
6
  * @see https://www.brreg.no/
7
7
  */
8
8
 
9
+ import type {
10
+ ValidateResult,
11
+ CountryValidator,
12
+ } from "../types";
13
+
9
14
  import { weightedSum } from "#checksums/weighted-sum";
10
15
  import { clean } from "#util/clean";
11
16
  import { randomDigits } from "#util/generate";
12
17
  import { err } from "#util/result";
13
18
  import { isdigits } from "#util/strings";
14
19
 
15
- import type { ValidateResult, Validator } from "../types";
16
-
17
20
  const WEIGHTS = [3, 2, 7, 6, 5, 4, 3, 2, 1] as const;
18
21
 
19
22
  const compact = (value: string): string =>
@@ -59,12 +62,13 @@ const generate = (): string => {
59
62
  };
60
63
 
61
64
  /** Norwegian Organization Number. */
62
- const orgnr: Validator = {
65
+ const orgnr: CountryValidator<"NO"> = {
63
66
  name: "Norwegian Organization Number",
64
67
  localName: "Organisasjonsnummer",
65
68
  abbreviation: "Orgnr",
66
69
  aliases: ["organisasjonsnummer", "org.nr"] as const,
67
70
  candidatePattern: "\\d{9}",
71
+ scope: "country",
68
72
  country: "NO",
69
73
  entityType: "company",
70
74
  sourceUrl: "https://www.brreg.no/",
package/src/nz/ird.ts CHANGED
@@ -9,13 +9,16 @@
9
9
  * @see https://www.ird.govt.nz/
10
10
  */
11
11
 
12
+ import type {
13
+ ValidateResult,
14
+ CountryValidator,
15
+ } from "../types";
16
+
12
17
  import { clean } from "#util/clean";
13
18
  import { randomDigits } from "#util/generate";
14
19
  import { err } from "#util/result";
15
20
  import { isdigits } from "#util/strings";
16
21
 
17
- import type { ValidateResult, Validator } from "../types";
18
-
19
22
  const PRIMARY_WEIGHTS = [3, 2, 7, 6, 5, 4, 3, 2] as const;
20
23
 
21
24
  const SECONDARY_WEIGHTS = [7, 4, 3, 2, 5, 2, 7, 6] as const;
@@ -28,15 +31,15 @@ const SECONDARY_WEIGHTS = [7, 4, 3, 2, 5, 2, 7, 6] as const;
28
31
  const calcCheckDigit = (payload: string): number | null => {
29
32
  const padded = payload.padStart(8, "0");
30
33
  let sum = 0;
31
- for (let i = 0; i < 8; i++) {
32
- sum += PRIMARY_WEIGHTS[i]! * Number(padded[i]);
34
+ for (const [i, weight] of PRIMARY_WEIGHTS.entries()) {
35
+ sum += weight * Number(padded[i]);
33
36
  }
34
37
  let remainder = ((-sum % 11) + 11) % 11;
35
38
  if (remainder !== 10) return remainder;
36
39
 
37
40
  sum = 0;
38
- for (let i = 0; i < 8; i++) {
39
- sum += SECONDARY_WEIGHTS[i]! * Number(padded[i]);
41
+ for (const [i, weight] of SECONDARY_WEIGHTS.entries()) {
42
+ sum += weight * Number(padded[i]);
40
43
  }
41
44
  remainder = ((-sum % 11) + 11) % 11;
42
45
  if (remainder === 10) return null;
@@ -80,7 +83,7 @@ const validate = (value: string): ValidateResult => {
80
83
  "IRD number cannot have a valid check digit",
81
84
  );
82
85
  }
83
- if (expected !== Number(v[v.length - 1])) {
86
+ if (expected !== Number(v.at(-1))) {
84
87
  return err(
85
88
  "INVALID_CHECKSUM",
86
89
  "IRD check digit does not match",
@@ -105,12 +108,13 @@ const generate = (): string => {
105
108
  };
106
109
 
107
110
  /** New Zealand IRD Number. */
108
- const ird: Validator = {
111
+ const ird: CountryValidator<"NZ"> = {
109
112
  name: "IRD Number",
110
113
  localName: "IRD Number",
111
114
  abbreviation: "IRD",
112
115
  aliases: ["IRD number", "tax number NZ"] as const,
113
116
  candidatePattern: "\\d{8,9}",
117
+ scope: "country",
114
118
  country: "NZ",
115
119
  entityType: "any",
116
120
  compact,
package/src/pa/ruc.ts CHANGED
@@ -17,12 +17,15 @@
17
17
  * @see https://dgi.mef.gob.pa/
18
18
  */
19
19
 
20
+ import type {
21
+ ValidateResult,
22
+ CountryValidator,
23
+ } from "../types";
24
+
20
25
  import { clean } from "#util/clean";
21
26
  import { randomInt } from "#util/generate";
22
27
  import { err } from "#util/result";
23
28
 
24
- import type { ValidateResult, Validator } from "../types";
25
-
26
29
  /**
27
30
  * Legacy cross-reference table: maps two-digit codes
28
31
  * at positions 5–6 of old-format juridical RUCs.
@@ -111,19 +114,26 @@ const computeDV = (
111
114
  ): string | null => {
112
115
  const len = segments.length;
113
116
 
114
- if (
115
- len < 3 ||
116
- len > 4 ||
117
- (len === 4 && segments[1] !== "NT")
118
- ) {
117
+ if (len < 3 || len > 4) {
118
+ return null;
119
+ }
120
+ // The NT designation requires exactly 4 segments
121
+ // (xxNT-NT-xxx-xxx); any other 4-segment shape is
122
+ // unrecognized, and a 3-segment "NT" in position 1
123
+ // is malformed.
124
+ if ((len === 4) !== (segments[1] === "NT")) {
119
125
  return null;
120
126
  }
121
127
 
122
128
  let buf: string;
123
129
  let isOld = false;
124
130
 
131
+ // SAFETY: length check above ensures 3..4 segments.
132
+ // eslint-disable-next-line no-non-null-assertion
125
133
  const s0 = segments[0]!;
134
+ // eslint-disable-next-line no-non-null-assertion
126
135
  const s1 = segments[1]!;
136
+ // eslint-disable-next-line no-non-null-assertion
127
137
  const s2 = segments[2]!;
128
138
 
129
139
  if (raw[0] === "E") {
@@ -138,7 +148,9 @@ const computeDV = (
138
148
  z(5 - s2.length) +
139
149
  s2;
140
150
  } else if (s1 === "NT") {
141
- // NT designation (xxNT-xxx-xxx)
151
+ // NT designation (xxNT-NT-xxx-xxx)
152
+ // SAFETY: NT branch implies len === 4 (checked above).
153
+ // eslint-disable-next-line no-non-null-assertion
142
154
  const s3 = segments[3]!;
143
155
  const prefix = s0.slice(0, -2);
144
156
  buf =
@@ -220,8 +232,14 @@ const computeDV = (
220
232
  s1 +
221
233
  z(6 - s2.length) +
222
234
  s2;
235
+ // SAFETY: juridical branch zero-pads s0 to at least
236
+ // 10 chars (z(10 - s0.length)), so buf[3..6] are
237
+ // always defined.
223
238
  isOld =
224
- buf[3] === "0" && buf[4] === "0" && buf[5]! < "5";
239
+ buf[3] === "0" &&
240
+ buf[4] === "0" &&
241
+ // eslint-disable-next-line no-non-null-assertion
242
+ buf[5]! < "5";
225
243
  }
226
244
 
227
245
  // Apply legacy cross-reference for old format
@@ -270,7 +288,10 @@ const validate = (value: string): ValidateResult => {
270
288
  );
271
289
  }
272
290
 
291
+ // SAFETY: both DV regex capture groups are required.
292
+ // eslint-disable-next-line no-non-null-assertion
273
293
  const rucPart = dvMatch[1]!;
294
+ // eslint-disable-next-line no-non-null-assertion
274
295
  const dvPart = dvMatch[2]!;
275
296
 
276
297
  // The RUC part should be hyphen-separated segments
@@ -318,7 +339,10 @@ const format = (value: string): string => {
318
339
  const dvMatch = v.match(/^(.+?)-?\s*DV[:\s]*(\d{2})$/);
319
340
  if (!dvMatch) return v;
320
341
 
342
+ // SAFETY: both DV regex capture groups are required.
343
+ // eslint-disable-next-line no-non-null-assertion
321
344
  const rucPart = dvMatch[1]!.replace(/-+$/, "");
345
+ // eslint-disable-next-line no-non-null-assertion
322
346
  const dvPart = dvMatch[2]!;
323
347
  const segments = rucPart.split("-");
324
348
  return `${segments.join("-")} DV ${dvPart}`;
@@ -330,17 +354,21 @@ const generate = (): string => {
330
354
  const volume = String(randomInt(1, 9999));
331
355
  const folio = String(randomInt(1, 99999));
332
356
  const segments = [province, volume, folio];
333
- const dv = computeDV(segments, segments.join("-"))!;
357
+ const dv = computeDV(segments, segments.join("-"));
358
+ if (dv === null) {
359
+ throw new Error("Failed to compute Panama RUC DV");
360
+ }
334
361
  return `${segments.join("-")} DV${dv}`;
335
362
  };
336
363
 
337
364
  /** Panama tax identification number. */
338
- const ruc: Validator = {
365
+ const ruc: CountryValidator<"PA"> = {
339
366
  name: "Tax Identification Number",
340
367
  localName: "Registro Único de Contribuyente",
341
368
  abbreviation: "RUC",
342
369
  aliases: ["RUC"] as const,
343
370
  candidatePattern: "\\d{1,2}-?\\d{1,4}-?\\d{1,6}",
371
+ scope: "country",
344
372
  country: "PA",
345
373
  entityType: "any",
346
374
  description: "Tax identifier issued by Panama's DGI",
package/src/patterns.ts CHANGED
@@ -27,13 +27,19 @@
27
27
  * ```
28
28
  */
29
29
 
30
- import type { CountryCode, Validator } from "./types";
30
+ import type {
31
+ CountryCode,
32
+ CountryValidator,
33
+ Validator,
34
+ } from "./types";
31
35
 
32
36
  // ─── Pattern type ─────────────────────────────
33
37
 
34
- export type ValidatorPattern = {
38
+ export type ValidatorPattern<
39
+ TValidator extends Validator = Validator,
40
+ > = {
35
41
  /** The validator this pattern was derived from. */
36
- validator: Validator;
42
+ validator: TValidator;
37
43
  /** Loose regex matching candidates in text. */
38
44
  regex: RegExp;
39
45
  };
@@ -66,10 +72,9 @@ const inferLengths = (v: Validator): number[] => {
66
72
  * "25 123 891" → [2, 3, 3].
67
73
  */
68
74
  const inferGroups = (v: Validator): number[] | null => {
69
- if (!v.examples || v.examples.length === 0) {
70
- return null;
71
- }
72
- const compact = v.compact(v.examples[0]!);
75
+ const first = v.examples?.[0];
76
+ if (first === undefined) return null;
77
+ const compact = v.compact(first);
73
78
  const formatted = v.format(compact);
74
79
  if (formatted === compact) return null;
75
80
 
@@ -98,35 +103,59 @@ const inferGroups = (v: Validator): number[] | null => {
98
103
  * (e.g., "CZ" for DIČ, "CHE" for Swiss UID).
99
104
  */
100
105
  const inferPrefix = (v: Validator): string | null => {
101
- if (!v.examples || v.examples.length === 0) {
102
- return null;
103
- }
104
- const compact = v.compact(v.examples[0]!);
106
+ const examples = v.examples;
107
+ const first = examples?.[0];
108
+ if (!examples || first === undefined) return null;
109
+ const compact = v.compact(first);
105
110
  // Prefix already present in compact form.
106
111
  // But only if ALL examples share the same prefix
107
112
  // (e.g., "CHE" for Swiss UID). If examples have
108
113
  // different prefixes (IBAN: GB/DE/FR), there's
109
114
  // no fixed prefix — it's part of the value.
110
115
  const compactMatch = compact.match(/^([A-Z]+)\d/);
111
- if (compactMatch && v.examples!.length > 1) {
112
- const pfx = compactMatch[1]!;
113
- const allSame = v.examples!.every((ex) =>
114
- v.compact(ex).startsWith(pfx),
116
+ const compactPrefix = compactMatch?.[1];
117
+ if (compactPrefix !== undefined && examples.length > 1) {
118
+ const allSame = examples.every((ex) =>
119
+ v.compact(ex).startsWith(compactPrefix),
115
120
  );
116
- if (allSame) return pfx;
117
- } else if (compactMatch && v.examples!.length === 1) {
118
- return compactMatch[1]!;
121
+ if (allSame) return compactPrefix;
122
+ } else if (
123
+ compactPrefix !== undefined &&
124
+ examples.length === 1
125
+ ) {
126
+ return compactPrefix;
119
127
  }
120
128
  // Prefix added only by format()
121
129
  // (e.g., "DE" for de.vat, "CZ" for cz.dic)
122
130
  const formatted = v.format(compact);
123
131
  const fmtMatch = formatted.match(/^([A-Z]+)[\s\-./]?\d/);
124
- if (fmtMatch && !compact.startsWith(fmtMatch[1]!)) {
125
- return fmtMatch[1]!;
132
+ const fmtPrefix = fmtMatch?.[1];
133
+ if (
134
+ fmtPrefix !== undefined &&
135
+ !compact.startsWith(fmtPrefix)
136
+ ) {
137
+ return fmtPrefix;
126
138
  }
127
139
  return null;
128
140
  };
129
141
 
142
+ /**
143
+ * Character class for a string fragment:
144
+ * `\d` if all digits, `[A-Z]` if all letters,
145
+ * `[A-Z0-9]` if mixed.
146
+ */
147
+ const charClassFor = (s: string): string => {
148
+ let hasLetter = false;
149
+ let hasDigit = false;
150
+ for (const ch of s) {
151
+ if (/[a-zA-Z]/.test(ch)) hasLetter = true;
152
+ if (/\d/.test(ch)) hasDigit = true;
153
+ }
154
+ if (hasLetter && hasDigit) return "[A-Z0-9]";
155
+ if (hasLetter) return "[A-Z]";
156
+ return "\\d";
157
+ };
158
+
130
159
  /**
131
160
  * Determine the character class needed for the
132
161
  * compact form: `\d` if all digits, `[A-Z0-9]`
@@ -136,18 +165,81 @@ const inferCharClass = (v: Validator): string => {
136
165
  if (!v.examples || v.examples.length === 0) {
137
166
  return "\\d";
138
167
  }
139
- let hasLetter = false;
140
- let hasDigit = false;
141
- for (const ex of v.examples) {
142
- const c = v.compact(ex);
143
- for (const ch of c) {
144
- if (/[a-zA-Z]/.test(ch)) hasLetter = true;
145
- if (/\d/.test(ch)) hasDigit = true;
168
+ const combined = v.examples
169
+ .map((ex) => v.compact(ex))
170
+ .join("");
171
+ return charClassFor(combined);
172
+ };
173
+
174
+ type PerGroup = { size: number; charClass: string };
175
+
176
+ /**
177
+ * Infer per-group sizes AND character classes from
178
+ * format(). Returns groups with per-position char
179
+ * classes, e.g., "12 010188 M 01 1" →
180
+ * sizes: [2, 6, 1, 2, 1]
181
+ * classes: ["\d", "\d", "[A-Z]", "\d", "\d"]
182
+ *
183
+ * Only returns non-null when per-group classes
184
+ * differ (some groups are letters, some digits).
185
+ * Letter-only groups before the first digit group
186
+ * are treated as prefixes and excluded (handled
187
+ * by inferPrefix separately).
188
+ */
189
+ const inferPerGroup = (v: Validator): PerGroup[] | null => {
190
+ const first = v.examples?.[0];
191
+ if (first === undefined) return null;
192
+ const compact = v.compact(first);
193
+ const formatted = v.format(compact);
194
+ if (formatted === compact) return null;
195
+
196
+ // Only applies to mixed validators (compact has
197
+ // both letters and digits in separate positions,
198
+ // like German SVNR "12010188M011").
199
+ const compactMixed =
200
+ /[a-zA-Z]/.test(compact) && /\d/.test(compact);
201
+ if (!compactMixed) return null;
202
+
203
+ // Also skip if any single part mixes letters and
204
+ // digits (IBAN, ISIN) — inferGroups already
205
+ // handles those correctly with the global class.
206
+ const parts = formatted.split(/[^a-zA-Z0-9]+/);
207
+ const isAlphanumeric = parts.some(
208
+ (p) => /[a-zA-Z]/.test(p) && /\d/.test(p),
209
+ );
210
+ if (isAlphanumeric) return null;
211
+
212
+ // Keep digit groups and letter-only groups that
213
+ // appear AFTER the first digit group (embedded
214
+ // letters). Skip letter-only groups before the
215
+ // first digit group (prefix like "CHE").
216
+ const filtered: PerGroup[] = [];
217
+ let seenDigitGroup = false;
218
+ for (const p of parts) {
219
+ if (p.length === 0) continue;
220
+ if (/\d/.test(p)) {
221
+ seenDigitGroup = true;
222
+ filtered.push({
223
+ size: p.length,
224
+ charClass: charClassFor(p),
225
+ });
226
+ } else if (seenDigitGroup) {
227
+ filtered.push({
228
+ size: p.length,
229
+ charClass: charClassFor(p),
230
+ });
146
231
  }
147
232
  }
148
- if (hasLetter && hasDigit) return "[A-Z0-9]";
149
- if (hasLetter) return "[A-Z]";
150
- return "\\d";
233
+
234
+ if (filtered.length <= 1) return null;
235
+
236
+ const firstClass = filtered[0]?.charClass;
237
+ const allSame = filtered.every(
238
+ (g) => g.charClass === firstClass,
239
+ );
240
+ if (allSame) return null;
241
+
242
+ return filtered;
151
243
  };
152
244
 
153
245
  /**
@@ -159,6 +251,18 @@ const groupsToPattern = (
159
251
  cc: string,
160
252
  ): string => groups.map((g) => `${cc}{${g}}`).join(SEP);
161
253
 
254
+ /**
255
+ * Build a group regex with per-group char classes.
256
+ * Produces tighter patterns when groups have different
257
+ * character types (e.g., digits vs letters).
258
+ */
259
+ const groupsToPatternPerClass = (
260
+ groups: readonly { size: number; charClass: string }[],
261
+ ): string =>
262
+ groups
263
+ .map(({ size, charClass }) => `${charClass}{${size}}`)
264
+ .join(SEP);
265
+
162
266
  /**
163
267
  * Derive a loose candidate-matching regex from
164
268
  * a validator. The regex finds potential matches;
@@ -175,7 +279,16 @@ export const toRegex = (v: Validator): RegExp => {
175
279
 
176
280
  let pattern: string;
177
281
 
178
- if (groups && lengths.length <= 1) {
282
+ // Use per-group char classes when groups mix
283
+ // digits and letters (e.g., German SVNR:
284
+ // "12 010188 M 01 1" → [\d, \d, [A-Z], \d, \d]).
285
+ // This prevents overly broad [A-Z0-9] from
286
+ // matching all-caps prose as identifiers.
287
+ const perGroup = inferPerGroup(v);
288
+
289
+ if (perGroup && lengths.length <= 1) {
290
+ pattern = groupsToPatternPerClass(perGroup);
291
+ } else if (groups && lengths.length <= 1) {
179
292
  pattern = groupsToPattern(groups, cc);
180
293
  } else if (lengths.length === 1) {
181
294
  pattern = `${cc}{${lengths[0]}}`;
@@ -207,9 +320,9 @@ export const toRegex = (v: Validator): RegExp => {
207
320
  /**
208
321
  * Build patterns for a list of validators.
209
322
  */
210
- export const toPatterns = (
211
- validators: readonly Validator[],
212
- ): ValidatorPattern[] =>
323
+ export const toPatterns = <TValidator extends Validator>(
324
+ validators: readonly TValidator[],
325
+ ): ValidatorPattern<TValidator>[] =>
213
326
  validators.map((v) => ({
214
327
  validator: v,
215
328
  regex: toRegex(v),
@@ -219,22 +332,47 @@ export const toPatterns = (
219
332
  * Filter validators by country code and build
220
333
  * patterns.
221
334
  */
222
- export const byCountry = (
223
- country: CountryCode,
224
- validators: readonly Validator[],
225
- ): ValidatorPattern[] =>
226
- toPatterns(
227
- validators.filter((v) => v.country === country),
335
+ type CountryScopedValidator<
336
+ TValidator extends Validator,
337
+ TCountry extends CountryCode,
338
+ > =
339
+ TValidator extends CountryValidator<
340
+ infer TValidatorCountry,
341
+ infer TParsed
342
+ >
343
+ ? TCountry extends TValidatorCountry
344
+ ? TValidator & CountryValidator<TCountry, TParsed>
345
+ : TValidatorCountry extends TCountry
346
+ ? TValidator
347
+ : never
348
+ : never;
349
+
350
+ export const byCountry = <
351
+ TCountry extends CountryCode,
352
+ TValidator extends Validator,
353
+ >(
354
+ country: TCountry,
355
+ validators: readonly TValidator[],
356
+ ): ValidatorPattern<
357
+ CountryScopedValidator<TValidator, TCountry>
358
+ >[] => {
359
+ const countryValidators = validators.filter(
360
+ (
361
+ v,
362
+ ): v is CountryScopedValidator<TValidator, TCountry> =>
363
+ v.scope === "country" && v.country === country,
228
364
  );
365
+ return toPatterns(countryValidators);
366
+ };
229
367
 
230
368
  /**
231
369
  * Filter validators by entity type and build
232
370
  * patterns.
233
371
  */
234
- export const byEntityType = (
372
+ export const byEntityType = <TValidator extends Validator>(
235
373
  entityType: "person" | "company" | "any",
236
- validators: readonly Validator[],
237
- ): ValidatorPattern[] =>
374
+ validators: readonly TValidator[],
375
+ ): ValidatorPattern<TValidator>[] =>
238
376
  toPatterns(
239
377
  validators.filter(
240
378
  (v) =>
@@ -247,6 +385,6 @@ export const byEntityType = (
247
385
  /**
248
386
  * Build patterns for ALL provided validators.
249
387
  */
250
- export const allPatterns = (
251
- validators: readonly Validator[],
252
- ): ValidatorPattern[] => toPatterns(validators);
388
+ export const allPatterns = <TValidator extends Validator>(
389
+ validators: readonly TValidator[],
390
+ ): ValidatorPattern<TValidator>[] => toPatterns(validators);
package/src/pe/ruc.ts CHANGED
@@ -14,13 +14,16 @@
14
14
  * @see https://en.wikipedia.org/wiki/Tax_identification_number#Peru
15
15
  */
16
16
 
17
+ import type {
18
+ ValidateResult,
19
+ CountryValidator,
20
+ } from "../types";
21
+
17
22
  import { clean } from "#util/clean";
18
- import { randomDigits } from "#util/generate";
23
+ import { randomDigits, randomPick } from "#util/generate";
19
24
  import { err } from "#util/result";
20
25
  import { isdigits } from "#util/strings";
21
26
 
22
- import type { ValidateResult, Validator } from "../types";
23
-
24
27
  /**
25
28
  * Valid type prefixes for RUC numbers.
26
29
  * 10 = natural person, 15 = non-domiciled without RUC,
@@ -29,7 +32,8 @@ import type { ValidateResult, Validator } from "../types";
29
32
  */
30
33
  const VALID_PREFIXES = new Set(["10", "15", "17", "20"]);
31
34
 
32
- const WEIGHTS = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
35
+ const WEIGHTS = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2] as const;
36
+ const GENERATE_PREFIXES = ["10", "15", "17", "20"] as const;
33
37
 
34
38
  const compact = (value: string): string =>
35
39
  clean(value, " -.").trim();
@@ -42,8 +46,8 @@ const compact = (value: string): string =>
42
46
  */
43
47
  const calcCheckDigit = (body: string): number => {
44
48
  let sum = 0;
45
- for (let i = 0; i < 10; i++) {
46
- sum += Number(body[i]) * WEIGHTS[i]!;
49
+ for (const [i, weight] of WEIGHTS.entries()) {
50
+ sum += Number(body[i]) * weight;
47
51
  }
48
52
  const remainder = 11 - (sum % 11);
49
53
  if (remainder >= 10) return remainder - 10;
@@ -87,9 +91,7 @@ const format = (value: string): string => compact(value);
87
91
 
88
92
  /** Generate a random valid Peruvian RUC. */
89
93
  const generate = (): string => {
90
- const prefixes = ["10", "15", "17", "20"] as const;
91
- const prefix =
92
- prefixes[Math.floor(Math.random() * prefixes.length)]!;
94
+ const prefix = randomPick(GENERATE_PREFIXES);
93
95
  const body = prefix + randomDigits(8);
94
96
  return body + String(calcCheckDigit(body));
95
97
  };
@@ -100,12 +102,13 @@ const generate = (): string => {
100
102
  * Examples sourced from python-stdnum test suite
101
103
  * (pe.ruc module).
102
104
  */
103
- const ruc: Validator = {
105
+ const ruc: CountryValidator<"PE"> = {
104
106
  name: "Peruvian Tax ID",
105
107
  localName: "Registro Único de Contribuyentes",
106
108
  abbreviation: "RUC",
107
109
  aliases: ["RUC"] as const,
108
110
  candidatePattern: "\\d{11}",
111
+ scope: "country",
109
112
  country: "PE",
110
113
  entityType: "any",
111
114
  compact,
package/src/ph/philid.ts CHANGED
@@ -14,13 +14,16 @@ const generate = (): string => randomDigits(12);
14
14
  * @see https://philsys.gov.ph/
15
15
  */
16
16
 
17
+ import type {
18
+ ValidateResult,
19
+ CountryValidator,
20
+ } from "../types";
21
+
17
22
  import { clean } from "#util/clean";
18
23
  import { randomDigits } from "#util/generate";
19
24
  import { err } from "#util/result";
20
25
  import { isdigits } from "#util/strings";
21
26
 
22
- import type { ValidateResult, Validator } from "../types";
23
-
24
27
  const compact = (value: string): string =>
25
28
  clean(value, " -");
26
29
 
@@ -50,12 +53,13 @@ const format = (value: string): string => {
50
53
  };
51
54
 
52
55
  /** Philippine Identification System Number. */
53
- const philid: Validator = {
56
+ const philid: CountryValidator<"PH"> = {
54
57
  name: "Philippine Identification System Number",
55
58
  localName: "PhilSys Card Number",
56
59
  abbreviation: "PhilID",
57
60
  aliases: ["PhilID", "PhilSys", "Philippine ID"] as const,
58
61
  candidatePattern: "\\d{4}-\\d{4}-\\d{4}-\\d{4}",
62
+ scope: "country",
59
63
  country: "PH",
60
64
  entityType: "person",
61
65
  description:
package/src/pk/cnic.ts CHANGED
@@ -20,13 +20,16 @@ const generate = (): string => {
20
20
  * @see https://en.wikipedia.org/wiki/CNIC_(Pakistan)
21
21
  */
22
22
 
23
+ import type {
24
+ ValidateResult,
25
+ CountryValidator,
26
+ } from "../types";
27
+
23
28
  import { clean } from "#util/clean";
24
29
  import { randomDigits, randomInt } from "#util/generate";
25
30
  import { err } from "#util/result";
26
31
  import { isdigits } from "#util/strings";
27
32
 
28
- import type { ValidateResult, Validator } from "../types";
29
-
30
33
  const compact = (value: string): string =>
31
34
  clean(value, " -");
32
35
 
@@ -53,6 +56,8 @@ const validate = (value: string): ValidateResult => {
53
56
  );
54
57
  }
55
58
  // First digit must be a valid province code
59
+ // SAFETY: v.length === 13 above guarantees v[0] exists.
60
+ // eslint-disable-next-line no-non-null-assertion
56
61
  if (!VALID_PROVINCES.has(v[0]!)) {
57
62
  return err(
58
63
  "INVALID_COMPONENT",
@@ -79,12 +84,13 @@ const format = (value: string): string => {
79
84
  };
80
85
 
81
86
  /** Pakistan Computerized National Identity Card. */
82
- const cnic: Validator = {
87
+ const cnic: CountryValidator<"PK"> = {
83
88
  name: "Computerized National Identity Card",
84
89
  localName: "Computerized National Identity Card",
85
90
  abbreviation: "CNIC",
86
91
  aliases: ["CNIC", "شناختی کارڈ"] as const,
87
92
  candidatePattern: "\\d{5}-?\\d{7}-?\\d",
93
+ scope: "country",
88
94
  country: "PK",
89
95
  entityType: "person",
90
96
  lengths: [13],