feat(isISO31661Alpha2/3): Add support for Kosovo (XK / XXK)#2663
feat(isISO31661Alpha2/3): Add support for Kosovo (XK / XXK)#2663rubiin merged 2 commits intovalidatorjs:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
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? |
|
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? |
|
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 |
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? |
|
Yeah, something like that indeed. We'd prefer using an options object like |
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? |
aec2119 to
93cf435
Compare
…er assigned codes"
93cf435 to
2c70f3f
Compare
|
I added the |
|
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 |
437e0ff to
96b36d6
Compare
It's done. I had to change the implementation to avoid the mutation of the Set. |
WikiRik
left a comment
There was a problem hiding this comment.
LGTM, even with the additional whitespace changes in the README
Summary
Add ISO 3166-1 Alpha 2 and 3 codes for Kosovo.
Details
ISO 3166-1 Alpha 2 code:
XKISO 3166-1 Alpha 3 code:
XXKChecklist