From 0af45b96f82fba13e5cccaf193ae13571a3a5809 Mon Sep 17 00:00:00 2001 From: Pradeep Chand Date: Tue, 9 Jul 2024 11:48:43 +0545 Subject: [PATCH 1/3] feat(postcode-regexes.ts,postcode-types.ts): added aditional supported countries Added 22 new countries and their postal code regexes for validation --- src/postcode-regexes.ts | 22 ++++++++++++++++++++++ src/postcode-types.ts | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/postcode-regexes.ts b/src/postcode-regexes.ts index 59b9bb2..ea560aa 100644 --- a/src/postcode-regexes.ts +++ b/src/postcode-regexes.ts @@ -172,5 +172,27 @@ export const POSTCODE_REGEXES: Map = new Map([ [CountryCode.XK, /^\d{5}$/], [CountryCode.YT, /^976\d{2}$/], [CountryCode.PE, /^\d{5}$/], + [CountryCode.GI, /^GX11 1AA/], + [CountryCode.BT, /^\d{5}/], + [CountryCode.AL, /^\d{4}/], + [CountryCode.CU, /^\d{5}/], + [CountryCode.UM, /^96898/], + [CountryCode.AI, /^(?:AI-)?2640/], + [CountryCode.AF, /^\d{4}/], + [CountryCode.SD, /^\d{5}/], + [CountryCode.VC, /^VC\d{4}/], + [CountryCode.TA, /^TDCU 1ZZ/], + [CountryCode.NA, /^\d{5}/], + [CountryCode.EH, /^\d{5}/], + [CountryCode.BL, /^9[78][01]\d{2}/], + [CountryCode.TZ, /^\d{4,5}/], + [CountryCode.AC, /^ASCN 1ZZ/], + [CountryCode.VG, /^VG\d{4}/], + [CountryCode.MZ, /^\d{4}/], + [CountryCode.MF, /^9[78][01]\d{2}/], + [CountryCode.MM, /^\d{5}/], + [CountryCode.SV, /^CP [1-3][1-7][0-2]\d/], + [CountryCode.CO, /^\d{6}/], + [CountryCode.IR, /^\d{5}-?\d{5}/], [CountryCode.INTL, /^(?:[A-Z0-9]+([- ]?[A-Z0-9]+)*)?$/i], ]); diff --git a/src/postcode-types.ts b/src/postcode-types.ts index 5ded85e..8a1f354 100644 --- a/src/postcode-types.ts +++ b/src/postcode-types.ts @@ -163,5 +163,27 @@ export enum CountryCode { XK = 'XK', YT = 'YT', PE = 'PE', + GI = "GI", + BT = "BT", + AL = "AL", + CU = "CU", + UM = "UM", + AI = "AI", + AF = "AF", + SD = "SD", + VC = "VC", + TA = "TA", + NA = "NA", + EH = "EH", + BL = "BL", + TZ = "TZ", + AC = "AC", + VG = "VG", + MZ = "MZ", + MF = "MF", + MM = "MM", + SV = "SV", + CO = "CO", + IR = "IR", INTL = 'INTL', } From 3903542bf34953ec31aeedda508e40c7d6ccd08d Mon Sep 17 00:00:00 2001 From: Pradeep Chand Date: Tue, 9 Jul 2024 14:30:21 +0545 Subject: [PATCH 2/3] test(main.spec.ts): added new country data added new country regex data for validation --- test/main.spec.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/main.spec.ts b/test/main.spec.ts index 4dd6e23..2882814 100644 --- a/test/main.spec.ts +++ b/test/main.spec.ts @@ -22,6 +22,7 @@ describe('postcodeValidator', () => { { postcode: '01000', country: 'PE' }, { postcode: '12345', country: 'TW' }, { postcode: '123456', country: 'TW' }, + { postcode: '12341-12213', country: 'IR' }, ]; expect.assertions(validPostcodes.length); @@ -47,6 +48,7 @@ describe('postcodeValidator', () => { { postcode: '0100', country: 'PE' }, { postcode: '010000', country: 'PE' }, { postcode: '0A000', country: 'PE' }, + { postcode: '1121234', country: 'IR' }, ]; expect.assertions(invalidPostcodes.length); @@ -63,12 +65,13 @@ describe('postcodeValidator', () => { describe('postcodeValidatorExistsForCountry', () => { test('should return true for valid country code', () => { - expect.assertions(5); + expect.assertions(6); expect(postcodeValidatorExistsForCountry('PR')).toBeTruthy(); expect(postcodeValidatorExistsForCountry('AU')).toBeTruthy(); expect(postcodeValidatorExistsForCountry('DE')).toBeTruthy(); expect(postcodeValidatorExistsForCountry('KY')).toBeTruthy(); expect(postcodeValidatorExistsForCountry('PE')).toBeTruthy(); + expect(postcodeValidatorExistsForCountry('IR')).toBeTruthy(); }); test('should return false for invalid country code', () => { From d8c4150dbb468a491676ecc9c9e3e50d677f8207 Mon Sep 17 00:00:00 2001 From: Pradeep Chand Date: Tue, 10 Sep 2024 08:16:21 +0545 Subject: [PATCH 3/3] removed duplicate from types file --- src/postcode-types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/postcode-types.ts b/src/postcode-types.ts index d1e69d7..7cc25e4 100644 --- a/src/postcode-types.ts +++ b/src/postcode-types.ts @@ -183,7 +183,6 @@ export enum CountryCode { MF = "MF", MM = "MM", SV = "SV", - CO = "CO", IR = "IR", INTL = 'INTL', CO = 'CO'