fi-pin 0.0.4 → 0.0.6
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/LICENSE +21 -21
- package/README.md +15 -5
- package/dist/index.d.mts +29 -0
- package/dist/index.d.ts +29 -3
- package/dist/index.js +86 -23
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +59 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +85 -51
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2017 Marko Harjula
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Marko Harjula
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
### Finnish Person ID check [](https://travis-ci.org/mharj/hetu)
|
|
1
|
+
### Finnish Person ID check [](https://travis-ci.org/mharj/hetu) [](https://codeclimate.com/github/mharj/hetu/maintainability) [](https://codeclimate.com/github/mharj/hetu/test_coverage)
|
|
2
|
+
|
|
2
3
|
```javascript
|
|
3
4
|
const {isFemale, isMale, isValidPersonId} = require('fi-pin');
|
|
4
5
|
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
if (isValidPersonId('131052-308T')) {
|
|
7
|
+
console.log('male', isMale('131052-308T'));
|
|
8
|
+
console.log('female', isFemale('131052-308T'));
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import {isFemale, isMale, isValidPersonId} from 'fi-pin';
|
|
14
|
+
|
|
15
|
+
if (isValidPersonId('131052-308T')) {
|
|
16
|
+
console.log('male', isMale('131052-308T'));
|
|
17
|
+
console.log('female', isFemale('131052-308T'));
|
|
8
18
|
}
|
|
9
|
-
```
|
|
19
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate if string is a valid personId
|
|
3
|
+
* @param personId - personId string
|
|
4
|
+
* @returns true if valid, false if not
|
|
5
|
+
* @example
|
|
6
|
+
* isValidPersonId('131052-308T') // true
|
|
7
|
+
* isValidPersonId('131052-3082') // false
|
|
8
|
+
*/
|
|
9
|
+
declare function isValidPersonId(personId: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Check if personId is for male
|
|
12
|
+
* @throws TypeError if personId is not valid
|
|
13
|
+
* @param personId - personId string
|
|
14
|
+
* @returns true if valid, false if not
|
|
15
|
+
* @example
|
|
16
|
+
* isMale('131052-308T') // false
|
|
17
|
+
*/
|
|
18
|
+
declare function isMale(personId: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Check if personId is for female
|
|
21
|
+
* @throws TypeError if personId is not valid
|
|
22
|
+
* @param personId - personId string
|
|
23
|
+
* @returns true if valid, false if not
|
|
24
|
+
* @example
|
|
25
|
+
* isFemale('131052-308T') // true
|
|
26
|
+
*/
|
|
27
|
+
declare function isFemale(personId: string): boolean;
|
|
28
|
+
|
|
29
|
+
export { isFemale, isMale, isValidPersonId };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Validate if string is a valid personId
|
|
3
|
+
* @param personId - personId string
|
|
4
|
+
* @returns true if valid, false if not
|
|
5
|
+
* @example
|
|
6
|
+
* isValidPersonId('131052-308T') // true
|
|
7
|
+
* isValidPersonId('131052-3082') // false
|
|
8
|
+
*/
|
|
9
|
+
declare function isValidPersonId(personId: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Check if personId is for male
|
|
12
|
+
* @throws TypeError if personId is not valid
|
|
13
|
+
* @param personId - personId string
|
|
14
|
+
* @returns true if valid, false if not
|
|
15
|
+
* @example
|
|
16
|
+
* isMale('131052-308T') // false
|
|
17
|
+
*/
|
|
18
|
+
declare function isMale(personId: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Check if personId is for female
|
|
21
|
+
* @throws TypeError if personId is not valid
|
|
22
|
+
* @param personId - personId string
|
|
23
|
+
* @returns true if valid, false if not
|
|
24
|
+
* @example
|
|
25
|
+
* isFemale('131052-308T') // true
|
|
26
|
+
*/
|
|
27
|
+
declare function isFemale(personId: string): boolean;
|
|
28
|
+
|
|
29
|
+
export { isFemale, isMale, isValidPersonId };
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,86 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
isFemale: () => isFemale,
|
|
24
|
+
isMale: () => isMale,
|
|
25
|
+
isValidPersonId: () => isValidPersonId
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
var c = "0123456789ABCDEFHJKLMNPRSTUVWXY";
|
|
29
|
+
function toInt(value) {
|
|
30
|
+
if (!value) {
|
|
31
|
+
throw new TypeError("undefined");
|
|
32
|
+
}
|
|
33
|
+
const outValue = parseInt(value, 10);
|
|
34
|
+
if (isNaN(outValue)) {
|
|
35
|
+
throw new TypeError(`${value} not a number`);
|
|
36
|
+
}
|
|
37
|
+
return outValue;
|
|
38
|
+
}
|
|
39
|
+
function getString(value) {
|
|
40
|
+
if (typeof value !== "string") {
|
|
41
|
+
throw new TypeError(`${JSON.stringify(value)} not a string`);
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
function buildCheckSum(num) {
|
|
46
|
+
return c[num];
|
|
47
|
+
}
|
|
48
|
+
function buildCcValues(personId) {
|
|
49
|
+
return [
|
|
50
|
+
getString(personId[0]),
|
|
51
|
+
getString(personId[1]),
|
|
52
|
+
getString(personId[2]),
|
|
53
|
+
getString(personId[3]),
|
|
54
|
+
getString(personId[4]),
|
|
55
|
+
getString(personId[5]),
|
|
56
|
+
getString(personId[6]),
|
|
57
|
+
getString(personId[7]),
|
|
58
|
+
getString(personId[8]),
|
|
59
|
+
getString(personId[9]),
|
|
60
|
+
getString(personId[10])
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
function isValidPersonId(personId) {
|
|
64
|
+
if (personId.length !== 11) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const d = buildCcValues(personId.toUpperCase());
|
|
68
|
+
return d[10] === buildCheckSum(toInt(d[0] + d[1] + d[2] + d[3] + d[4] + d[5] + d[7] + d[8] + d[9]) % 31);
|
|
69
|
+
}
|
|
70
|
+
function isMale(personId) {
|
|
71
|
+
if (!isValidPersonId(personId)) {
|
|
72
|
+
throw new TypeError("not valid person id");
|
|
73
|
+
}
|
|
74
|
+
const d = buildCcValues(personId);
|
|
75
|
+
return toInt(d[7] + d[8] + d[9]) % 2 === 1;
|
|
76
|
+
}
|
|
77
|
+
function isFemale(personId) {
|
|
78
|
+
return !isMale(personId);
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
isFemale,
|
|
83
|
+
isMale,
|
|
84
|
+
isValidPersonId
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["const c = '0123456789ABCDEFHJKLMNPRSTUVWXY';\n\n/**\n * Parse string to integer\n * @throws TypeError if value is not a number\n * @param value\n * @returns value as number\n */\nfunction toInt(value: string | undefined): number {\n\tif (!value) {\n\t\tthrow new TypeError('undefined');\n\t}\n\tconst outValue = parseInt(value, 10);\n\tif (isNaN(outValue)) {\n\t\tthrow new TypeError(`${value} not a number`);\n\t}\n\treturn outValue;\n}\n\n/**\n * Validate that value is a string\n * @throws TypeError if value is not a string\n * @param value\n * @returns value as string\n */\nfunction getString(value: unknown): string {\n\tif (typeof value !== 'string') {\n\t\tthrow new TypeError(`${JSON.stringify(value)} not a string`);\n\t}\n\treturn value;\n}\n\n/**\n * Build checksum for personId (last character)\n * @param num - number to build checksum from\n * @returns checksum character\n */\nfunction buildCheckSum(num: number): string | undefined {\n\treturn c[num];\n}\n\n/**\n * Construct array of string values from personId string\n * @param personId - personId string\n * @returns\n */\nfunction buildCcValues(personId: string): [string, string, string, string, string, string, string, string, string, string, string] {\n\treturn [\n\t\tgetString(personId[0]),\n\t\tgetString(personId[1]),\n\t\tgetString(personId[2]),\n\t\tgetString(personId[3]),\n\t\tgetString(personId[4]),\n\t\tgetString(personId[5]),\n\t\tgetString(personId[6]),\n\t\tgetString(personId[7]),\n\t\tgetString(personId[8]),\n\t\tgetString(personId[9]),\n\t\tgetString(personId[10]),\n\t];\n}\n\n/**\n * Validate if string is a valid personId\n * @param personId - personId string\n * @returns true if valid, false if not\n * @example\n * isValidPersonId('131052-308T') // true\n * isValidPersonId('131052-3082') // false\n */\nexport function isValidPersonId(personId: string): boolean {\n\tif (personId.length !== 11) {\n\t\treturn false;\n\t}\n\tconst d = buildCcValues(personId.toUpperCase());\n\treturn d[10] === buildCheckSum(toInt(d[0] + d[1] + d[2] + d[3] + d[4] + d[5] + d[7] + d[8] + d[9]) % 31);\n}\n\n/**\n * Check if personId is for male\n * @throws TypeError if personId is not valid\n * @param personId - personId string\n * @returns true if valid, false if not\n * @example\n * isMale('131052-308T') // false\n */\nexport function isMale(personId: string): boolean {\n\tif (!isValidPersonId(personId)) {\n\t\tthrow new TypeError('not valid person id');\n\t}\n\tconst d = buildCcValues(personId);\n\treturn toInt(d[7] + d[8] + d[9]) % 2 === 1;\n}\n\n/**\n * Check if personId is for female\n * @throws TypeError if personId is not valid\n * @param personId - personId string\n * @returns true if valid, false if not\n * @example\n * isFemale('131052-308T') // true\n */\nexport function isFemale(personId: string): boolean {\n\treturn !isMale(personId);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;A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AAC,CAAC,IAAI,EAAE;AACxG;AAUO,SAAS,OAAO,UAA2B;AACjD,MAAI,CAAC,gBAAgB,QAAQ,GAAG;AAC/B,UAAM,IAAI,UAAU,qBAAqB;AAAA,EAC1C;AACA,QAAM,IAAI,cAAc,QAAQ;AAChC,SAAO,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,MAAM;AAC1C;AAUO,SAAS,SAAS,UAA2B;AACnD,SAAO,CAAC,OAAO,QAAQ;AACxB;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var c = "0123456789ABCDEFHJKLMNPRSTUVWXY";
|
|
3
|
+
function toInt(value) {
|
|
4
|
+
if (!value) {
|
|
5
|
+
throw new TypeError("undefined");
|
|
6
|
+
}
|
|
7
|
+
const outValue = parseInt(value, 10);
|
|
8
|
+
if (isNaN(outValue)) {
|
|
9
|
+
throw new TypeError(`${value} not a number`);
|
|
10
|
+
}
|
|
11
|
+
return outValue;
|
|
12
|
+
}
|
|
13
|
+
function getString(value) {
|
|
14
|
+
if (typeof value !== "string") {
|
|
15
|
+
throw new TypeError(`${JSON.stringify(value)} not a string`);
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function buildCheckSum(num) {
|
|
20
|
+
return c[num];
|
|
21
|
+
}
|
|
22
|
+
function buildCcValues(personId) {
|
|
23
|
+
return [
|
|
24
|
+
getString(personId[0]),
|
|
25
|
+
getString(personId[1]),
|
|
26
|
+
getString(personId[2]),
|
|
27
|
+
getString(personId[3]),
|
|
28
|
+
getString(personId[4]),
|
|
29
|
+
getString(personId[5]),
|
|
30
|
+
getString(personId[6]),
|
|
31
|
+
getString(personId[7]),
|
|
32
|
+
getString(personId[8]),
|
|
33
|
+
getString(personId[9]),
|
|
34
|
+
getString(personId[10])
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
function isValidPersonId(personId) {
|
|
38
|
+
if (personId.length !== 11) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const d = buildCcValues(personId.toUpperCase());
|
|
42
|
+
return d[10] === buildCheckSum(toInt(d[0] + d[1] + d[2] + d[3] + d[4] + d[5] + d[7] + d[8] + d[9]) % 31);
|
|
43
|
+
}
|
|
44
|
+
function isMale(personId) {
|
|
45
|
+
if (!isValidPersonId(personId)) {
|
|
46
|
+
throw new TypeError("not valid person id");
|
|
47
|
+
}
|
|
48
|
+
const d = buildCcValues(personId);
|
|
49
|
+
return toInt(d[7] + d[8] + d[9]) % 2 === 1;
|
|
50
|
+
}
|
|
51
|
+
function isFemale(personId) {
|
|
52
|
+
return !isMale(personId);
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
isFemale,
|
|
56
|
+
isMale,
|
|
57
|
+
isValidPersonId
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["const c = '0123456789ABCDEFHJKLMNPRSTUVWXY';\n\n/**\n * Parse string to integer\n * @throws TypeError if value is not a number\n * @param value\n * @returns value as number\n */\nfunction toInt(value: string | undefined): number {\n\tif (!value) {\n\t\tthrow new TypeError('undefined');\n\t}\n\tconst outValue = parseInt(value, 10);\n\tif (isNaN(outValue)) {\n\t\tthrow new TypeError(`${value} not a number`);\n\t}\n\treturn outValue;\n}\n\n/**\n * Validate that value is a string\n * @throws TypeError if value is not a string\n * @param value\n * @returns value as string\n */\nfunction getString(value: unknown): string {\n\tif (typeof value !== 'string') {\n\t\tthrow new TypeError(`${JSON.stringify(value)} not a string`);\n\t}\n\treturn value;\n}\n\n/**\n * Build checksum for personId (last character)\n * @param num - number to build checksum from\n * @returns checksum character\n */\nfunction buildCheckSum(num: number): string | undefined {\n\treturn c[num];\n}\n\n/**\n * Construct array of string values from personId string\n * @param personId - personId string\n * @returns\n */\nfunction buildCcValues(personId: string): [string, string, string, string, string, string, string, string, string, string, string] {\n\treturn [\n\t\tgetString(personId[0]),\n\t\tgetString(personId[1]),\n\t\tgetString(personId[2]),\n\t\tgetString(personId[3]),\n\t\tgetString(personId[4]),\n\t\tgetString(personId[5]),\n\t\tgetString(personId[6]),\n\t\tgetString(personId[7]),\n\t\tgetString(personId[8]),\n\t\tgetString(personId[9]),\n\t\tgetString(personId[10]),\n\t];\n}\n\n/**\n * Validate if string is a valid personId\n * @param personId - personId string\n * @returns true if valid, false if not\n * @example\n * isValidPersonId('131052-308T') // true\n * isValidPersonId('131052-3082') // false\n */\nexport function isValidPersonId(personId: string): boolean {\n\tif (personId.length !== 11) {\n\t\treturn false;\n\t}\n\tconst d = buildCcValues(personId.toUpperCase());\n\treturn d[10] === buildCheckSum(toInt(d[0] + d[1] + d[2] + d[3] + d[4] + d[5] + d[7] + d[8] + d[9]) % 31);\n}\n\n/**\n * Check if personId is for male\n * @throws TypeError if personId is not valid\n * @param personId - personId string\n * @returns true if valid, false if not\n * @example\n * isMale('131052-308T') // false\n */\nexport function isMale(personId: string): boolean {\n\tif (!isValidPersonId(personId)) {\n\t\tthrow new TypeError('not valid person id');\n\t}\n\tconst d = buildCcValues(personId);\n\treturn toInt(d[7] + d[8] + d[9]) % 2 === 1;\n}\n\n/**\n * Check if personId is for female\n * @throws TypeError if personId is not valid\n * @param personId - personId string\n * @returns true if valid, false if not\n * @example\n * isFemale('131052-308T') // true\n */\nexport function isFemale(personId: string): boolean {\n\treturn !isMale(personId);\n}\n"],"mappings":";AAAA,IAAM,IAAI;AAQV,SAAS,MAAM,OAAmC;AACjD,MAAI,CAAC,OAAO;AACX,UAAM,IAAI,UAAU,WAAW;AAAA,EAChC;AACA,QAAM,WAAW,SAAS,OAAO,EAAE;AACnC,MAAI,MAAM,QAAQ,GAAG;AACpB,UAAM,IAAI,UAAU,GAAG,KAAK,eAAe;AAAA,EAC5C;AACA,SAAO;AACR;AAQA,SAAS,UAAU,OA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A2B;AACnD,SAAO,CAAC,OAAO,QAAQ;AACxB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,55 +1,89 @@
|
|
|
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
|
-
|
|
2
|
+
"name": "fi-pin",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"description": "Finnish Personal Identification Number validate + gender check",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/chai": "^4.3.16",
|
|
17
|
+
"@types/mocha": "^9.1.1",
|
|
18
|
+
"@types/node": "^14.18.63",
|
|
19
|
+
"@typescript-eslint/eslint-plugin": "^7.8.0",
|
|
20
|
+
"@typescript-eslint/parser": "^7.8.0",
|
|
21
|
+
"chai": "^4.4.1",
|
|
22
|
+
"eslint": "^8.57.0",
|
|
23
|
+
"eslint-config-prettier": "^9.1.0",
|
|
24
|
+
"eslint-config-standard": "^17.1.0",
|
|
25
|
+
"eslint-plugin-deprecation": "^2.0.0",
|
|
26
|
+
"eslint-plugin-jsdoc": "^48.2.3",
|
|
27
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
28
|
+
"eslint-plugin-sonarjs": "^0.23.0",
|
|
29
|
+
"mocha": "^10.4.0",
|
|
30
|
+
"mocha-junit-reporter": "^2.2.1",
|
|
31
|
+
"nyc": "^15.1.0",
|
|
32
|
+
"source-map-support": "^0.5.21",
|
|
33
|
+
"ts-node": "^10.9.2",
|
|
34
|
+
"tsup": "^8.0.2",
|
|
35
|
+
"typescript": "^5.4.5"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup src/index.ts --sourcemap --format cjs,esm --dts --clean",
|
|
39
|
+
"prepublishOnly": "npm run test && npm run build",
|
|
40
|
+
"test": "nyc mocha",
|
|
41
|
+
"lint": "eslint src/ test/"
|
|
42
|
+
},
|
|
43
|
+
"mocha": {
|
|
44
|
+
"exit": true,
|
|
45
|
+
"extension": [
|
|
46
|
+
"ts",
|
|
47
|
+
"js"
|
|
48
|
+
],
|
|
49
|
+
"recursive": true,
|
|
50
|
+
"require": [
|
|
51
|
+
"ts-node/register",
|
|
52
|
+
"source-map-support/register"
|
|
53
|
+
],
|
|
54
|
+
"reporters": [
|
|
55
|
+
"spec",
|
|
56
|
+
"mocha-junit-reporter"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"keywords": [
|
|
60
|
+
"pin",
|
|
61
|
+
"personid"
|
|
35
62
|
],
|
|
36
|
-
"
|
|
37
|
-
|
|
63
|
+
"files": [
|
|
64
|
+
"dist"
|
|
38
65
|
],
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
66
|
+
"nyc": {
|
|
67
|
+
"extension": [
|
|
68
|
+
".ts"
|
|
69
|
+
],
|
|
70
|
+
"include": [
|
|
71
|
+
"src"
|
|
72
|
+
],
|
|
73
|
+
"reporter": [
|
|
74
|
+
"text",
|
|
75
|
+
"lcovonly"
|
|
76
|
+
],
|
|
77
|
+
"all": true
|
|
78
|
+
},
|
|
79
|
+
"repository": {
|
|
80
|
+
"type": "git",
|
|
81
|
+
"url": "git+https://github.com/mharj/hetu.git"
|
|
82
|
+
},
|
|
83
|
+
"author": "mharj",
|
|
84
|
+
"license": "MIT",
|
|
85
|
+
"bugs": {
|
|
86
|
+
"url": "https://github.com/mharj/hetu/issues"
|
|
87
|
+
},
|
|
88
|
+
"homepage": "https://github.com/mharj/hetu#readme"
|
|
55
89
|
}
|