Skip to content

feat(isISO31661Alpha2/3): Add support for Kosovo (XK / XXK)#2663

Merged
rubiin merged 2 commits intovalidatorjs:masterfrom
johanpoirier-d4:feat/kosovo-alpha-codes
Feb 6, 2026
Merged

feat(isISO31661Alpha2/3): Add support for Kosovo (XK / XXK)#2663
rubiin merged 2 commits intovalidatorjs:masterfrom
johanpoirier-d4:feat/kosovo-alpha-codes

Conversation

@johanpoirier-d4
Copy link
Contributor

Summary

Add ISO 3166-1 Alpha 2 and 3 codes for Kosovo.

Details

ISO 3166-1 Alpha 2 code: XK
ISO 3166-1 Alpha 3 code: XXK

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c3dc37c) to head (96b36d6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2663   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2572      2590   +18     
  Branches       651       659    +8     
=========================================
+ Hits          2572      2590   +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@WikiRik
Copy link
Member

WikiRik commented Feb 5, 2026

I believe there are in the user assigned space, not the actual standard. I'm not sure we should accept this change.

Do you have any sources that mention that this is the country code that Kosovo will keep when they get more international recognition?

@johanpoirier-d4
Copy link
Contributor Author

Yes you're absolutely right. In the future Kosovo won't be able to keep this one because it is temporary.

But for now, it is used and for us at Decathlon, we need it. Is it possible to add it and change it when Kosovo will be assigned with an official code?

@WikiRik
Copy link
Member

WikiRik commented Feb 6, 2026

I'm not really a fan of that. What we could do is add support for an options object where users can specify other codes that are supported

@johanpoirier-d4
Copy link
Contributor Author

const alpha2CountryCodeRegexp = /^[a-zA-Z]{2}$/;

export default function isISO31661Alpha2(str, userAssignedCodes) {
  if (userAssignedCodes) {
    userAssignedCodes.forEach((code) => {
      if (alpha2CountryCodeRegexp.test(code)) {
        validISO31661Alpha2CountriesCodes.add(code.toUpperCase());
      }
    });
  }
  assertString(str);
  return validISO31661Alpha2CountriesCodes.has(str.toUpperCase());
}

Something like that?

@WikiRik
Copy link
Member

WikiRik commented Feb 6, 2026

Yeah, something like that indeed. We'd prefer using an options object like str: string, options?: { userAssignedCodes?: string[] } (even though we're not shipping our own types yet)

@johanpoirier-d4
Copy link
Contributor Author

const alpha2CountryCode = /^[a-zA-Z]{2}$/;

export default function isISO31661Alpha2(str, options = {}) {
  const { userAssignedCodes } = options;
  (userAssignedCodes ?? []).forEach((code) => {
    if (alpha2CountryCode.test(code)) {
      validISO31661Alpha2CountriesCodes.add(code.toUpperCase());
    }
  });

  assertString(str);
  return validISO31661Alpha2CountriesCodes.has(str.toUpperCase());
}

Better?

@johanpoirier-d4 johanpoirier-d4 force-pushed the feat/kosovo-alpha-codes branch 2 times, most recently from aec2119 to 93cf435 Compare February 6, 2026 10:28
@johanpoirier-d4 johanpoirier-d4 force-pushed the feat/kosovo-alpha-codes branch from 93cf435 to 2c70f3f Compare February 6, 2026 10:41
@johanpoirier-d4
Copy link
Contributor Author

I added the options parameter to the functions.
I also added tests and completed the README.

@WikiRik
Copy link
Member

WikiRik commented Feb 6, 2026

Can you move the existing tests from https://github.com/validatorjs/validator.js/blob/master/test/validators.test.js to the new files as well?

And add tests for if the options object is empty and if the options object has the userAssignedCodes object but with an empty array

@johanpoirier-d4 johanpoirier-d4 force-pushed the feat/kosovo-alpha-codes branch from 437e0ff to 96b36d6 Compare February 6, 2026 13:55
@johanpoirier-d4
Copy link
Contributor Author

And add tests for if the options object is empty and if the options object has the userAssignedCodes object but with an empty array

It's done.

I had to change the implementation to avoid the mutation of the Set.

Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, even with the additional whitespace changes in the README

@WikiRik WikiRik requested a review from rubiin February 6, 2026 15:30
@rubiin rubiin merged commit 88e0d3d into validatorjs:master Feb 6, 2026
12 checks passed
@johanpoirier-d4 johanpoirier-d4 deleted the feat/kosovo-alpha-codes branch February 7, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants