From a0d198079882cfee7c85887a181792395c0bc60c Mon Sep 17 00:00:00 2001 From: Yarchik Date: Thu, 19 Nov 2026 15:37:59 +0000 Subject: [PATCH] fix(nz/ird): format 9-digit numbers as nnn-nnn-nnn --- src/nz/ird.spec.ts | 12 ++++++++++++ src/nz/ird.ts | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/nz/ird.spec.ts b/src/nz/ird.spec.ts index 5bb073c1..117478c2 100644 --- a/src/nz/ird.spec.ts +++ b/src/nz/ird.spec.ts @@ -12,6 +12,18 @@ describe('nz/ird', () => { expect(result).toEqual('49-091-850'); }); + it('format:049091850', () => { + const result = format('049091850'); + + expect(result).toEqual('049-091-850'); + }); + + it('format:150000009', () => { + const result = format('150000009'); + + expect(result).toEqual('150-000-009'); + }); + it('validate:4909185-0', () => { const result = validate('4909185-0'); diff --git a/src/nz/ird.ts b/src/nz/ird.ts index 3fd83de7..c48a3fef 100644 --- a/src/nz/ird.ts +++ b/src/nz/ird.ts @@ -43,7 +43,7 @@ const impl: Validator = { localName: 'Te Tari Taake', abbreviation: 'IRD', examples: ['49091850'], - formats: ['nn-nnn-nnn', 'nn-nnn-nnnn'], + formats: ['nn-nnn-nnn', 'nnn-nnn-nnn'], compact(input: string): string { const [value, err] = clean(input); @@ -57,8 +57,9 @@ const impl: Validator = { format(input: string): string { const [value] = clean(input); + const front = value.length === 9 ? 3 : 2; - return strings.splitAt(value, 2, 5).join('-'); + return strings.splitAt(value, front, front + 3).join('-'); }, validate(input: string): ValidateReturn {