diff --git a/README.md b/README.md index d8a5d72..907cd2c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# A JavaScript module of validation functions - -A validation function returns true or false. +# A JavaScript module of validation functions Validation functions are used to verify data integrity, but are not relied upon to verify data authenticity. -In other words: a validation function is primarily a safeguard against simple user errors or random input. -It is designed to protect against accidental errors, not malicious attacks. +In other words: a validation function is primarily a safeguard against simple human transcription errors +or random input. It is designed to protect against accidental errors, not malicious attacks. + +A validation function returns true or false. ## Validation functions @@ -21,9 +21,8 @@ This module contains several validation functions: - National Insurance number (NI) - Numéro d'inscription au Répertoire (NIR) - Canadian Social Insurance Number (SIN) -- Social Security Number (SSN) - Österreichische Sozialversicherungsnummer (ÖVSNR) -- Deutscher Personalausweis +- Personalausweis-ID oder Pass-ID (PID) - Deutsche Rentenversicherungsnummer (VSNR) - Payment card numbers like VISA or Mastercard (PAN) diff --git a/package.json b/package.json index 27d4177..a4b70de 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,18 @@ { "name": "@e2n/validators", - "version": "1.0.0", "description": "A module of common validation functions.", + "version": "1.0.0", "keywords": [ "validation", "validators", "predicates" ], + "repository": { + "type": "git", + "url": "https://github.com/E2N/validators.git" + }, "homepage": "https://github.com/E2N/validators", - "license": "Unlicense", + "license": "MIT", "type": "commonjs", "devDependencies": { "jest": "^29.7.0", diff --git a/validators.js b/validators.js index fcff208..58b7c4e 100644 --- a/validators.js +++ b/validators.js @@ -19,7 +19,9 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. -/* + */ + +"use strict"; /* IBAN REGISTRY Release 95 – Jul 2023 */ const iban_registry = new Map(Object.entries({ @@ -595,6 +597,30 @@ function sin(input) { return sum % 10 === 0; } +function pid(input) { + /* Null, undefined and blank check */ + if (!input) { + return false; + } + + /* Type check */ + if (typeof input !== "string") { + return false; + } + + /* Length check */ + if (input.length !== 10) { + return false; + } + + let check_digit= parseInt(input.charAt(9)); + const weights = [7, 3, 1]; + + /* https://de.wikipedia.org/wiki/Ausweisnummer#Berechnung_der_Prüfziffern */ + + return false; +} + module.exports = { bbnr, cf, @@ -606,6 +632,7 @@ module.exports = { nhs, nir, pan, + pid, sin, vsnr } \ No newline at end of file diff --git a/validators.test.js b/validators.test.js index 12fb1fb..85e6b4b 100644 --- a/validators.test.js +++ b/validators.test.js @@ -302,4 +302,11 @@ describe("Canadian Social Insurance Number (SIN)", function() { test.each([ ["046454286", true] ])("%s", (input, expected) => expect(validators.sin(input)).toBe(expected)); +}); + +describe("Personalausweis-ID oder Pass-ID (PID)", function() { + test.each([ + ["T220001293", true], + ["1220001297", true] + ])("%s", (input, expected) => expect(validators.pid(input)).toBe(expected)); }); \ No newline at end of file