-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit eecb282
Showing
15 changed files
with
5,586 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "8" | ||
} | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# gatsby files | ||
.cache/ | ||
public | ||
|
||
# Mac files | ||
.DS_Store | ||
|
||
# Yarn | ||
yarn-error.log | ||
.pnp/ | ||
.pnp.js | ||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# Builds | ||
dist | ||
|
||
# Webpack | ||
.awcache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
12.14.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"useTabs": false, | ||
"semi": true, | ||
"tabWidth": 4, | ||
"trailingComma": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: node_js | ||
|
||
cache: | ||
yarn: true | ||
directories: | ||
- node_modules | ||
|
||
before_install: | ||
- npm install -g yarn | ||
|
||
install: | ||
- yarn --silent | ||
|
||
script: | ||
- yarn run tscheck | ||
- yarn run tslint | ||
- yarn run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Luit Hollander | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Elfproef | ||
|
||
[![Travis CI](https://img.shields.io/travis/com/MrLuit/elfproef.svg?style=flat-square)](https://travis-ci.com/MrLuit/elfproef) | ||
[![Version](https://img.shields.io/npm/v/elfproef.svg?style=flat-square)](https://www.npmjs.com/package/elfproef) | ||
[![Dependencies](https://img.shields.io/david/MrLuit/elfproef.svg?style=flat-square)](https://david-dm.org/MrLuit/elfproef) | ||
[![License](https://img.shields.io/github/license/MrLuit/elfproef.svg?style=flat-square)](https://github.com/MrLuit/elfproef/blob/master/LICENSE) | ||
|
||
------ | ||
|
||
Implementation of the 11-proof, a mathematical test used by the Dutch government for various digital identification numbers | ||
|
||
------ | ||
|
||
## Description | ||
|
||
### Explanation | ||
Elfproef is Dutch for **11-proof** (`elf` means `11`, `proef` means `test`). It was originally designed to prevent people from trying to transfer money to a mistyped account number, specifically where either **one digit is incorrect**, or **2 digits were swapped**. | ||
|
||
The principle is very simple. First of all, a given number is split into its individual digits. Secondly, those digits are multiplied by their **"weight"**, a multiplier which is based on the position of the digit. Finally, the sum of all multiplied numbers is calculated. | ||
|
||
If the result is **divisible by 11** and **greater than 0**, the 11-proof is _valid_. | ||
|
||
### Example | ||
A Dutch social security number (**BSN**) consists of 9 digits and must suffice the 11-proof with weights `[9, 8, 7, 6, 5, 4, 3, 2, -1]`. | ||
|
||
For a given BSN `ABCDEFGHI`, the outcome of the following formula must be divisble by 11 and greater than 0. | ||
|
||
``` | ||
(9 × A) + (8 × B) + (7 × C) + (6 × D) + (5 × E) + (4 × F) + (3 × G) + (2 × H) + (-1 × I) | ||
``` | ||
|
||
A valid BSN would be `111222333`. | ||
``` | ||
(9 × 1) + (8 × 1) + (7 × 1) + (6 × 2) + (5 × 2) + (4 × 2) + (3 × 3) + (2 × 3) + (-1 × 3) = 66 | ||
``` | ||
|
||
The result is greater than 0 and divisible by 11: | ||
|
||
`66 > 0 66 ∧ 66 mod 11 = 0` | ||
|
||
## Usage | ||
|
||
### Installation | ||
`yarn add elfproef -E` | ||
|
||
### Example | ||
``` | ||
import { validateBSN } from 'elfproef'; | ||
const BSN = "111222333"; | ||
const validBSN = validateBSN(BSN); | ||
console.log(validBSN); | ||
``` | ||
|
||
## References | ||
- https://nl.wikipedia.org/wiki/Elfproef | ||
- https://nl.wikipedia.org/wiki/Burgerservicenummer | ||
- https://www.rijksoverheid.nl/onderwerpen/privacy-en-persoonsgegevens/vraag-en-antwoord/wat-is-het-burgerservicenummer-bsn | ||
|
||
## License | ||
|
||
This project is licensed under the [MIT License](https://github.com/MrLuit/elfproef/blob/master/LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"name": "elfproef", | ||
"description": "Implementation of the 11-proof, a mathematical test used by the Dutch government for various digital identification numbers", | ||
"version": "1.0.0", | ||
"author": "Luit Hollander <[email protected]> (https://luit.me)", | ||
"repository": "https://github.com/MrLuit/elfproef.git", | ||
"license": "MIT", | ||
"main": "./dist/elfproef.node.js", | ||
"module": "./dist/elfproef.js", | ||
"typings": "./typings/src/index.d.ts", | ||
"keywords": [ | ||
"elfproef", | ||
"11-proef", | ||
"negenproef", | ||
"9-proef", | ||
"check digit", | ||
"bsn" | ||
], | ||
"scripts": { | ||
"tscheck": "tsc --noEmit --project tsconfig.json", | ||
"tslint": "tslint --project .", | ||
"build": "cross-env NODE_ENV=production webpack --config ./webpack/config.ts", | ||
"clean": "rimraf ./dist && rimraf ./typings", | ||
"test": "mocha -r ts-node/register ./tests/**/*.ts", | ||
"prettier:diff": "prettier --write --config ./.prettierrc --list-different \"src/**/*.ts\" \"tests/**/*.ts\" \"webpack/**/*.ts\"" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@babel/core": "7.8.3", | ||
"@babel/preset-env": "7.8.3", | ||
"@types/chai": "4.2.7", | ||
"@types/mocha": "5.2.7", | ||
"@types/node": "13.1.7", | ||
"@types/webpack": "4.41.2", | ||
"@types/webpack-merge": "4.1.5", | ||
"@types/webpack-node-externals": "1.7.0", | ||
"awesome-typescript-loader": "5.2.1", | ||
"chai": "4.2.0", | ||
"cross-env": "6.0.3", | ||
"husky": "4.0.10", | ||
"lint-staged": "9.5.0", | ||
"mocha": "7.0.0", | ||
"prettier": "1.19.1", | ||
"rimraf": "3.0.0", | ||
"ts-node": "8.6.2", | ||
"tslint": "5.20.1", | ||
"tslint-config-prettier": "1.18.0", | ||
"tslint-microsoft-contrib": "6.2.0", | ||
"typescript": "3.7.4", | ||
"webpack": "4.41.5", | ||
"webpack-cli": "3.3.10", | ||
"webpack-merge": "4.2.2", | ||
"webpack-node-externals": "1.7.2" | ||
}, | ||
"lint-staged": { | ||
"*.ts": [ | ||
"prettier --write --config ./.prettierrc --config-precedence file-override", | ||
"tslint --project .", | ||
"git add" | ||
] | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"post-commit": "git update-index --again", | ||
"pre-commit": "lint-staged", | ||
"pre-push": "npm run tslint && npm run tscheck && npm run test" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export const elfProef = (input: string | number, weights: number[]): boolean => { | ||
if (typeof input === 'number') { | ||
input = input.toString(); | ||
} | ||
if (input.length !== weights.length) { | ||
throw new Error('Amount of weights must be equal to length of input'); | ||
} | ||
const numbers = input.split(''); | ||
const sum = numbers | ||
.map((value: string, index: number) => { | ||
const number = parseInt(value, 10); | ||
const weight = weights[index]; | ||
return number * weight; | ||
}) | ||
.reduce((a, b) => a + b); | ||
return sum > 0 && sum % 11 === 0; | ||
}; | ||
|
||
export const validateBSN = (input: string | number): boolean => { | ||
if (typeof input === 'number') { | ||
input = input.toString(); | ||
} | ||
const validFormat = /^[\d]{9}$/.test(input); | ||
if (validFormat) { | ||
const validElfProef = elfProef(input, [9, 8, 7, 6, 5, 4, 3, 2, -1]); | ||
return validElfProef; | ||
} else { | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { validateBSN } from '../src/index'; | ||
import { expect } from 'chai'; | ||
|
||
describe('BSN', () => { | ||
it('string 111222333 should be valid', () => { | ||
const result = validateBSN('111222333'); | ||
expect(result).to.be.true; | ||
}); | ||
it('string 123456782 should be valid', () => { | ||
const result = validateBSN('123456782'); | ||
expect(result).to.be.true; | ||
}); | ||
it('string 000000000 should be invalid', () => { | ||
const result = validateBSN('000000000'); | ||
expect(result).to.be.false; | ||
}); | ||
it('string 999999999 should be invalid', () => { | ||
const result = validateBSN('999999999'); | ||
expect(result).to.be.false; | ||
}); | ||
it('number 111222333 should be valid', () => { | ||
const result = validateBSN(111222333); | ||
expect(result).to.be.true; | ||
}); | ||
it('number 999999999 should be invalid', () => { | ||
const result = validateBSN(999999999); | ||
expect(result).to.be.false; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "./src/", | ||
"sourceMap": true, | ||
"strictNullChecks": true, | ||
"allowSyntheticDefaultImports": true, | ||
"module": "commonjs", | ||
"lib": ["dom", "es2017"], | ||
"declaration": true, | ||
"declarationDir": "typings", | ||
"outDir": "./dist", | ||
"target": "es2017", | ||
"noEmitOnError": true, | ||
"strict": true, | ||
"experimentalDecorators": true, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"resolveJsonModule": true | ||
}, | ||
"include": [ | ||
"./src/**/*", | ||
"./tests/**/*", | ||
"./webpack/**/*", | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
Oops, something went wrong.