From 2b13d774c17df6f797113bab89cb4406ff40d092 Mon Sep 17 00:00:00 2001 From: Menyin Chang Date: Wed, 13 May 2026 14:48:14 -0300 Subject: [PATCH 1/3] fix(sv/nit): align check digit logic with Python reference implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The TypeScript NIT validator diverged from the upstream python-stdnum implementation in two places, causing valid NITs to be rejected. 1. Old-vs-new NIT branch selection The condition used strict equality against the sequential block: value.substr(10, 3) === '100' The Python reference uses a lexicographic comparison: number[10:13] <= '100' As a result, any "old" NIT whose sequential block was below '100' (i.e. '000'–'099') was being validated with the new-NIT formula and incorrectly flagged as InvalidChecksum. Changed to `<= '100'` to match. 2. New-NIT check digit edge case The formula was: (11 - weightedSum(...)) % 10 The Python equivalent is: (-total % 11) % 10 which, expanded, is `((11 - total % 11) % 11) % 10`. The outer `% 11` matters: when the weighted sum is divisible by 11, Python returns 0 while the TS version returned 1, rejecting otherwise-valid numbers. Added the missing `% 11` step. No changes to weights, length/format/component checks, or the SV-prefix handling. Verified against the docstring fixture `0614-050707-104-8`. --- src/sv/nit.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sv/nit.ts b/src/sv/nit.ts index 8e3fce36..238877d0 100644 --- a/src/sv/nit.ts +++ b/src/sv/nit.ts @@ -84,7 +84,7 @@ const impl: Validator = { let sum; const [front, check] = strings.splitAt(value, 13); - if (value.substr(10, 3) === '100') { + if (value.substr(10, 3) <= '100') { sum = weightedSum(front, { weights: [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2], @@ -92,11 +92,12 @@ const impl: Validator = { }) % 10; } else { sum = - (11 - + ((11 - weightedSum(front, { weights: [2, 7, 6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2], modulus: 11, })) % + 11)% 10; } From f75a72aeabe141b24d9cdc8f4cbf0288b1d3af77 Mon Sep 17 00:00:00 2001 From: Menyin Chang Date: Wed, 13 May 2026 14:53:49 -0300 Subject: [PATCH 2/3] Update src/sv/nit.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/sv/nit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sv/nit.ts b/src/sv/nit.ts index 238877d0..e3c62453 100644 --- a/src/sv/nit.ts +++ b/src/sv/nit.ts @@ -84,7 +84,7 @@ const impl: Validator = { let sum; const [front, check] = strings.splitAt(value, 13); - if (value.substr(10, 3) <= '100') { + if (value.slice(10, 13) <= '100') { sum = weightedSum(front, { weights: [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2], From 5ab61679599de7ed84cc747209c494e58349f2f2 Mon Sep 17 00:00:00 2001 From: Menyin Chang Date: Wed, 13 May 2026 14:54:31 -0300 Subject: [PATCH 3/3] Update src/sv/nit.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/sv/nit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sv/nit.ts b/src/sv/nit.ts index e3c62453..631dfec2 100644 --- a/src/sv/nit.ts +++ b/src/sv/nit.ts @@ -97,7 +97,7 @@ const impl: Validator = { weights: [2, 7, 6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2], modulus: 11, })) % - 11)% + 11) % 10; }