Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(isTaxID): new validator 🎉 (#1446)
* feat(isTaxID): Added de-AT locale * Added TIN validation for Austrian numbers * Added source of validation algorithms to header * test(isTaxID): Added unit tests for de-AT TINs * Refactored TIN unit tests to support more locales * Added unit tests for de-AT TINs * Added comments to isTaxID.js to explain behaviour of deAtCheck(tin) * feat(isTaxID): Added el-GR locale * Added TIN validation for Greek numbers * Added relevant tests * feat(isTaxID): Added en-GB locale * Added TIN validation for UK numbers * Added relevant tests * fix(isTaxID): Sanitize TINs before validity testing * Certain EU TINs might be entered with special characters which should not affect their validity/be omitted according to the specification. Such TINs are now sanitized before running checks in isTaxID(str, locale). * Removed en-GB validity check function (not needed, case already covered in isTaxID(str, locale). * Updated/simplified structure of regexes * Updated de-AT tests as some previously invalid TINs are now considered valid in line with the specification. * feat(isTaxID): Added fr/nl-BE locales * Added TIN validation for Belgian numbers * Added relevant tests * Added local TIN names and validation scope (person/entity) to comments * refactor(isTaxID): Added locale aliases * Countries with more than one locale should now have only one entry in the taxIdFormat and taxIdCheck objects, all others added as aliases below the objects. This should help avoid repetition. * Refactored nl-BE as alias to fr-BE * Renamed frNlBeCheck to frNlCheck to reflect changes. * feat(isTaxID): Added fr-FR locale * Added validation for French TINs * Added relevant tests * feat(isTaxID): Added el-CY locale * Added validation for Cypriot TINs * Added relevant tests * Added tests for previously uncovered cases (calling isTaxID without a locale, frBeCheck invalid checksum) * feat(isTaxID): Added hu-HU locale * Added validation for Hungarian TINs * Added relevant tests * Refactored return statements to be one-liners where possible * refactor(isTaxID): Prepare to support more sanitization regexes Different locales might have specific needs wrt acceptable symbols in TINs- in some all are omitted during validation, while others only allow to skip a subset. A new object `sanitizeRegexes` has replaced the previous array, where locale-specific skippable symbol classes are to be placed. When all symbols can be omitted the new variable `allsymbols` is referenced. Aliases have also been added for the new object in line with the others and the isTaxID function checks for the locale's inclusion in `sanitizeRegexes`. * feat(isTaxID): Add de-DE locale * Add TIN validation for German numbers * Add relevant tests * feat(isTaxID): Add hr-HR locale * Moved de-DE check digit calculation routine to new function `iso7064Check()` to be used for other conforming locales. * Add TIN validation for Croatian numbers * Add relevant tests * Refactor deDeCheck() to use iso7064Check() * feat(isTaxID): Add bg-BG locale * Add TIN validation for Bulgarian numbers * Add relevant tests * feat(isTaxID): Add cs-CZ locale * Add TIN validation for Czech numbers * Add relevant tests * fix(isTaxID): Add el-GR first digit validation * Add validation for first digit of Greek TINs * Refactor el-GR tests * Add info for testable en-GB TINs * feat(isTaxID): Add sk-SK locale * Add TIN validation for Slovakian numbers * Add relevant tests * feat(isTaxID): Add dk-DK locale * Add TIN validation for Danish numbers * Add relevant tests * feat(isTaxID): Add et-EE locale * Add TIN validation for Estonian numbers * Add relevant tests * feat(isTaxID): Add lt-LT locale * Add TIN validation for Lithuanian numbers (as alias of et-EE) * Add relevant tests * feat(isTaxID): Add fi-FI locale * Add TIN validation for Finnish numbers * Add relevant tests * feat(isTaxID): Add it-IT locale * Add TIN validation for Italian numbers * Add relevant tests * feat(isTaxID): Add en-IE locale * Add TIN validation for Irish numbers * Add relevant tests * feat(isTaxID): Add lv-LV locale * Add TIN validation for Latvian numbers * Add relevant tests * refactor(isTaxID): Remove unneeded parseInt() calls * Remove parseInt() calls in year extraction procedures of functions to improve performance and readability * refactor(isTaxID): Add Luhn validation function * Add luhnCheck() to be used by conforming locale TINs * Refactor deAtCheck() to use luhnCheck() * refactor(isTaxID): Add reverse multiplication function * Add reverseMultiplyAndSum() to support new locale check functions * feat(isTaxID): Add sv-SE locale * Add TIN validation for Swedish numbers * Add relevant tests * feat(isTaxID): Add nl-NL locale * Add TIN validation for Dutch numbers * Add relevant tests * Refactor enIeCheck() to use reverseMultiplyAndSum() * feat(isTaxID): Add pt-PT locale * Add TIN validation for Portugese numbers * Add relevant tests * feat(isTaxID): Add sl-SI locale * Add TIN validation for Slovenian numbers * Add relevant tests * feat(isTaxID): Add es-ES locale * Add TIN validation for Spanish numbers * Add relevant tests * feat(isTaxID): Add ro-RO locale * Add TIN validation for Romanian numbers * Add relevant tests * feat(isTaxID): Add mt-MT locale * Add TIN validation for Maltese numbers * Add relevant tests * feat(isTaxID): Add pl-PL locale * Add TIN validation for Polish numbers * Add relevant tests * refactor(isTaxID): Add any case support * Add support for both uppercase and lowercase letters where not specifically defined in the DG TAXUD document * chore(isTaxID): Add Verhoeff validation function * Add verhoeffCheck() to be used by future locale TINs * feat(isTaxID): Add fr/lb-LU locale * Add TIN validation for Luxembourgish numbers * Add relevant tests * docs(README): Update isTaxID() description * Add supported locale list and info message to isTaxID() description * remove(isTaxID): Remove codice catastale validation * Remove codice catastale validation subroutine from it-IT (to be included in another upstream PR) for further review. * refactor(isTaxID): Move helper validation algorithms * General-purpose validation algorithms have benn moved to `src/lib/util/algoritms.js` to support further use. * Validation algorithms have been refactored to use strings as input * isTaxID has been refactored to use `algorithms.js`
- Loading branch information