bsn-js 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -34
- package/lib/generator.d.ts +2 -1
- package/lib/generator.d.ts.map +1 -0
- package/lib/generator.js +8 -8
- package/lib/generator.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -2
- package/lib/index.js.map +1 -1
- package/lib/validator.d.ts +1 -0
- package/lib/validator.d.ts.map +1 -0
- package/lib/validator.js +6 -8
- package/lib/validator.js.map +1 -1
- package/package.json +50 -55
package/README.md
CHANGED
|
@@ -1,62 +1,45 @@
|
|
|
1
|
-
[](https://github.com/willemverbuyst/bsn-js/actions/workflows/lint-test-build.yml)
|
|
2
|
-
[](https://github.com/willemverbuyst/bsn-js/actions/workflows/pages/pages-build-deployment)
|
|
3
|
-
|
|
4
1
|
# bsn-js
|
|
5
2
|
|
|
6
|
-
bsn-js
|
|
7
|
-
|
|
8
|
-
works for JavaScript and TypeScript (type definitions included)
|
|
3
|
+
[](https://github.com/willemverbuyst/bsn-js/actions/workflows/code-checks.yml) [](https://github.com/willemverbuyst/bsn-js/actions/workflows/tests.yml) [](https://github.com/willemverbuyst/bsn-js/actions/workflows/code-ql.yml)
|
|
9
4
|
|
|
10
|
-
##
|
|
5
|
+
## what is this?
|
|
11
6
|
|
|
12
|
-
|
|
7
|
+
The bsn-js package can be used to generate a test BSN (burger service nummer) or to validate an existing BSN.
|
|
13
8
|
|
|
14
|
-
|
|
9
|
+
It works for JavaScript and TypeScript (type definitions included).
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
## installation
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
> npm install bsn-js
|
|
19
14
|
|
|
20
15
|
## usage
|
|
21
16
|
|
|
22
|
-
|
|
17
|
+
### validate existing BSN
|
|
23
18
|
|
|
24
19
|
`import { isValidBSN } from 'bsn-js'`
|
|
25
20
|
|
|
26
|
-
or
|
|
27
|
-
|
|
28
|
-
`const { isValidBSN } = require('bsn-js')`
|
|
29
|
-
|
|
30
|
-
pass the BSN (string) to the function and it will return `true` or `false`
|
|
21
|
+
Pass the BSN (string) to the function and it will return `true` or `false`.
|
|
31
22
|
|
|
32
|
-
|
|
23
|
+
Example: `const validBSN = isValidBSN('12312312') // false`
|
|
33
24
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
#### generate BSN for testing
|
|
25
|
+
### generate BSN for testing
|
|
37
26
|
|
|
38
27
|
`import { generateBSN } from 'bsn-js'`
|
|
39
28
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
`const { generateBSN } = require('bsn-js)`
|
|
43
|
-
|
|
44
|
-
test BSNs will consist of 9 characters
|
|
29
|
+
The test BSNs will consist of 9 characters. The Dutch authority has reserved BSNs starting with 0000 and 99999 for testing.
|
|
45
30
|
|
|
46
|
-
|
|
31
|
+
The generated BSN will start with 99999 by default.
|
|
47
32
|
|
|
48
|
-
|
|
33
|
+
`const bsn = generateBSN() // 999999400`
|
|
49
34
|
|
|
50
|
-
|
|
35
|
+
When the function generateBSN is given true as argument, it will return a BSN starting with 0000.
|
|
51
36
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
`const bsn = generateBSN(true) # 000078840`
|
|
55
|
-
|
|
56
|
-
<br>
|
|
37
|
+
`const bsn = generateBSN(true) // 000078840`
|
|
57
38
|
|
|
58
39
|
## information BSN
|
|
59
40
|
|
|
60
41
|
[official docs](https://www.government.nl/topics/personal-data/citizen-service-number-bsn)
|
|
61
42
|
|
|
62
43
|
[11 check](https://en.wikipedia.org/wiki/Check_digit)
|
|
44
|
+
|
|
45
|
+
[bsn-tool](https://willemverbuyst.github.io/bsn-tool/)
|
package/lib/generator.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare const generateBSN: (withLeadingZeroes?: boolean
|
|
1
|
+
export declare const generateBSN: (withLeadingZeroes?: boolean) => string;
|
|
2
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"/","sources":["generator.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,WAAW,GAAI,oBAAoB,OAAO,KAAG,MAgCzD,CAAC"}
|
package/lib/generator.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateBSN = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
leading:
|
|
4
|
+
const generateBSN = (withLeadingZeroes) => {
|
|
5
|
+
const bsn = {
|
|
6
|
+
leading: "9999",
|
|
7
7
|
i4: 9,
|
|
8
8
|
i5: Math.floor(Math.random() * 10),
|
|
9
9
|
i6: Math.floor(Math.random() * 10),
|
|
10
10
|
i7: Math.floor(Math.random() * 10),
|
|
11
|
-
i8: 0
|
|
11
|
+
i8: 0,
|
|
12
12
|
};
|
|
13
13
|
if (withLeadingZeroes)
|
|
14
|
-
bsn.leading =
|
|
15
|
-
|
|
14
|
+
bsn.leading = "0000";
|
|
15
|
+
const sum = Array.from(String(bsn.leading), Number).reduce((a, b, i) => b * (9 - i) + a, 0) +
|
|
16
16
|
5 * bsn.i4 +
|
|
17
17
|
4 * bsn.i5 +
|
|
18
18
|
3 * bsn.i6 +
|
|
@@ -26,7 +26,7 @@ var generateBSN = function (withLeadingZeroes) {
|
|
|
26
26
|
bsn.i7 += 1;
|
|
27
27
|
bsn.i8 = 1;
|
|
28
28
|
}
|
|
29
|
-
return
|
|
29
|
+
return `${bsn.leading}${bsn.i4}${bsn.i5}${bsn.i6}${bsn.i7}${bsn.i8}`;
|
|
30
30
|
};
|
|
31
31
|
exports.generateBSN = generateBSN;
|
|
32
32
|
//# sourceMappingURL=generator.js.map
|
package/lib/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"/","sources":["generator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"/","sources":["generator.ts"],"names":[],"mappings":";;;AASO,MAAM,WAAW,GAAG,CAAC,iBAA2B,EAAU,EAAE;IACjE,MAAM,GAAG,GAAQ;QACf,OAAO,EAAE,MAAM;QACf,EAAE,EAAE,CAAC;QACL,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC;QAClC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC;QAClC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC;QAClC,EAAE,EAAE,CAAC;KACN,CAAC;IAEF,IAAI,iBAAiB;QAAE,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC;IAE5C,MAAM,GAAG,GACP,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC/E,CAAC,GAAG,GAAG,CAAC,EAAE;QACV,CAAC,GAAG,GAAG,CAAC,EAAE;QACV,CAAC,GAAG,GAAG,CAAC,EAAE;QACV,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC;IAEb,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IAErD,IAAI,GAAG,CAAC,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;QAC7B,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;QACZ,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IACb,CAAC;IAED,IAAI,GAAG,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;QAChC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;QACZ,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IACb,CAAC;IAED,OAAO,GAAG,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE,CAAC;AACvE,CAAC,CAAC;AAhCW,QAAA,WAAW,eAgCtB"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./generator";
|
|
2
|
+
export * from "./validator";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -9,7 +13,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
9
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
17
|
__exportStar(require("./generator"), exports);
|
|
14
18
|
__exportStar(require("./validator"), exports);
|
|
15
19
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,8CAA4B"}
|
package/lib/validator.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"/","sources":["validator.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OAkBxC,CAAC"}
|
package/lib/validator.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isValidBSN = void 0;
|
|
4
|
-
|
|
4
|
+
const isValidBSN = (bsn) => {
|
|
5
5
|
if (bsn.length < 8 || bsn.length > 9) {
|
|
6
6
|
return false;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (typeof lastNumber ===
|
|
11
|
-
return ((numbers
|
|
12
|
-
.slice(0, -1)
|
|
13
|
-
.reduce(function (a, b, i, arr) { return b * (arr.length + 1 - i) + a; }, 0) -
|
|
8
|
+
const numbers = Array.from(String(bsn), Number);
|
|
9
|
+
const lastNumber = numbers[numbers.length - 1];
|
|
10
|
+
if (typeof lastNumber === "number" && !numbers.includes(NaN)) {
|
|
11
|
+
return ((numbers.slice(0, -1).reduce((a, b, i, arr) => b * (arr.length + 1 - i) + a, 0) -
|
|
14
12
|
lastNumber) %
|
|
15
13
|
11 ===
|
|
16
14
|
0);
|
package/lib/validator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"/","sources":["validator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"/","sources":["validator.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,GAAW,EAAW,EAAE;IACjD,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE/C,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7D,OAAO,CACL,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC7E,UAAU,CAAC;YACX,EAAE;YACJ,CAAC,CACF,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAlBW,QAAA,UAAU,cAkBrB"}
|
package/package.json
CHANGED
|
@@ -1,57 +1,52 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"ts-jest": "^27.1.3",
|
|
53
|
-
"ts-node": "^10.4.0",
|
|
54
|
-
"typedoc": "^0.22.11",
|
|
55
|
-
"typescript": "^4.5.5"
|
|
56
|
-
}
|
|
2
|
+
"name": "bsn-js",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Generator/validator for (Dutch) BSNs",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"BSN",
|
|
7
|
+
"Burger Service Nummer",
|
|
8
|
+
"Dutch",
|
|
9
|
+
"generate",
|
|
10
|
+
"validate"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Willem Verbuyst",
|
|
14
|
+
"repository": "https://github.com/willemverbuyst/bsn-js",
|
|
15
|
+
"files": [
|
|
16
|
+
"lib/**/*"
|
|
17
|
+
],
|
|
18
|
+
"main": "./lib/index.js",
|
|
19
|
+
"types": "./lib/index.d.ts",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"fmt": "oxfmt",
|
|
22
|
+
"fmt:check": "oxfmt --check",
|
|
23
|
+
"knip:check": "knip",
|
|
24
|
+
"lint:check": "oxlint",
|
|
25
|
+
"lint:fix": "oxlint --fix",
|
|
26
|
+
"size:check": "size-limit",
|
|
27
|
+
"test:unit": "vitest run",
|
|
28
|
+
"type:check": "tsc --noEmit",
|
|
29
|
+
"build": "tsc -p tsconfig.json",
|
|
30
|
+
"clean": "rm -rf ./lib",
|
|
31
|
+
"prepare": "npm run clean && npm run build",
|
|
32
|
+
"prepublishOnly": "npm run test:unit && npm run lint:check",
|
|
33
|
+
"preversion": "npm run lint:check",
|
|
34
|
+
"version": "npm run fmt:check && git add -A src",
|
|
35
|
+
"postversion": "git push && git push --tags"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@size-limit/preset-small-lib": "^12.0.1",
|
|
39
|
+
"@types/node": "^25.5.0",
|
|
40
|
+
"knip": "^5.86.0",
|
|
41
|
+
"oxfmt": "^0.40.0",
|
|
42
|
+
"oxlint": "^1.55.0",
|
|
43
|
+
"size-limit": "^12.0.1",
|
|
44
|
+
"typescript": "^5.9.3",
|
|
45
|
+
"vitest": "^4.1.0"
|
|
46
|
+
},
|
|
47
|
+
"size-limit": [
|
|
48
|
+
{
|
|
49
|
+
"path": "./lib/index.js"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
57
52
|
}
|