Skip to content

Commit dd99347

Browse files
authored
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`
1 parent 55ca773 commit dd99347

File tree

4 files changed

+1584
-7
lines changed

4 files changed

+1584
-7
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Validator | Description
152152
**isUppercase(str)** | check if the string is uppercase.
153153
**isSlug** | Check if the string is of type slug. `Options` allow a single hyphen between string. e.g. [`cn-cn`, `cn-c-c`]
154154
**isStrongPassword(str [, options])** | Check if a password is strong or not. Allows for custom requirements or scoring rules. If `returnScore` is true, then the function returns an integer score for the password rather than a boolean.<br/>Default options: <br/>`{ minLength: 8, minLowercase: 1, minUppercase: 1, minNumbers: 1, minSymbols: 1, returnScore: false, pointsPerUnique: 1, pointsPerRepeat: 0.5, pointsForContainingLower: 10, pointsForContainingUpper: 10, pointsForContainingNumber: 10, pointsForContainingSymbol: 10 }`
155-
**isTaxID(str, locale)** | Check if the given value is a valid Tax Identification Number. Default locale is `en-US`
155+
**isTaxID(str, locale)** | Check if the given value is a valid Tax Identification Number. Default locale is `en-US`.<br/><br/>More info about exact TIN support can be found in `src/lib/isTaxID.js`<br/><br/>Supported locales: `[ 'bg-BG', 'cs-CZ', 'de-AT', 'de-DE', 'dk-DK', 'el-CY', 'el-GR', 'en-GB', 'en-IE', 'en-US', 'es-ES', 'et-EE', 'fi-FI', 'fr-BE', 'fr-FR', 'fr-LU', 'hr-HR', 'hu-HU', 'it-IT', 'lb-LU', 'lt-LT', 'lv-LV' 'mt-MT', 'nl-BE', 'nl-NL', 'pl-PL', 'pt-PT', 'ro-RO', 'sk-SK', 'sl-SI', 'sv-SE' ]`
156156
**isURL(str [, options])** | check if the string is an URL.<br/><br/>`options` is an object which defaults to `{ protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, require_host: true, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, disallow_auth: false }`.<br/><br/>require_protocol - if set as true isURL will return false if protocol is not present in the URL.<br/>require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.<br/>protocols - valid protocols can be modified with this option.<br/>require_host - if set as false isURL will not check if host is present in the URL.<br/>require_port - if set as true isURL will check if port is present in the URL.<br/>allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed.<br/>validate_length - if set as false isURL will skip string length validation (2083 characters is IE max URL length).
157157
**isUUID(str [, version])** | check if the string is a UUID (version 3, 4 or 5).
158158
**isVariableWidth(str)** | check if the string contains a mixture of full and half-width chars.

0 commit comments

Comments
 (0)