feat(isISO6391): add ISO 639-1 validator by braaar · Pull Request #1892 · validatorjs/validator.js

I suppose a more complete implementation of this could be isISO639(str, versions) where you can specify which versions of ISO639 you wish to validate against (perhaps just 1 through 5, since version 6 was withdrawn).

The default behaviour without any options specified should match any of the 5 official and current versions of the standard.

Here's how I would implement that:

// declare 5 different sets with all the language codes in them

const sets = [isISO6391Set, isISO6392Set, isISO6393Set, isISO6394Set, isISO6395Set];

export default function isISO639(str, versions = [1, 2, 3, 4, 5]) {
  assertString(str);

  return versions.reduce((result, version) => {
    const currentSet = sets[version - 1];
    return currentSet.has(str) || result;
  }, false);
}