Skip to content

Commit

Permalink
use strict
Browse files Browse the repository at this point in the history
  • Loading branch information
raupach-e2n committed Nov 11, 2023
1 parent 28b3ec4 commit 1eff4ee
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
29 changes: 28 additions & 1 deletion validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand All @@ -606,6 +632,7 @@ module.exports = {
nhs,
nir,
pan,
pid,
sin,
vsnr
}
7 changes: 7 additions & 0 deletions validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});

0 comments on commit 1eff4ee

Please # to comment.