fi-pin 0.0.6 → 0.0.8

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 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,19 +1,101 @@
1
- ### Finnish Person ID check [![Build Status](https://travis-ci.org/mharj/hetu.svg?branch=master)](https://travis-ci.org/mharj/hetu) [![Maintainability](https://api.codeclimate.com/v1/badges/3dca350166c6d1ea4105/maintainability)](https://codeclimate.com/github/mharj/hetu/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/3dca350166c6d1ea4105/test_coverage)](https://codeclimate.com/github/mharj/hetu/test_coverage)
1
+ # Finnish Person ID Check
2
2
 
3
- ```javascript
4
- const {isFemale, isMale, isValidPersonId} = require('fi-pin');
3
+ ![github action](https://github.com/mharj/hetu/actions/workflows/main.yml/badge.svg)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/3dca350166c6d1ea4105/maintainability)](https://codeclimate.com/github/mharj/hetu/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/3dca350166c6d1ea4105/test_coverage)](https://codeclimate.com/github/mharj/hetu/test_coverage)
5
6
 
6
- if (isValidPersonId('131052-308T')) {
7
- console.log('male', isMale('131052-308T'));
8
- console.log('female', isFemale('131052-308T'));
9
- }
7
+ ## Overview
8
+
9
+ This module provides functions to validate Finnish person IDs (Henkilötunnus) and determine the gender based on the ID. A valid Finnish person ID consists of 11 characters in the format `DDMMYYCZZZQ`, where:
10
+
11
+ - `DDMMYY` represents the date of birth
12
+ - `C` is the century sign ('+' for 1800s, '-' for 1900s, 'A' for 2000s)
13
+ - `ZZZ` is an individual number (odd numbers are males, even numbers are females)
14
+ - `Q` is a checksum character
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install fi-pin
10
20
  ```
11
21
 
22
+ ## Usage
23
+
12
24
  ```typescript
13
- import {isFemale, isMale, isValidPersonId} from 'fi-pin';
25
+ const personId = '131052-308T';
14
26
 
15
- if (isValidPersonId('131052-308T')) {
16
- console.log('male', isMale('131052-308T'));
17
- console.log('female', isFemale('131052-308T'));
27
+ if (isValidPersonId(personId)) {
28
+ console.log('male', isMale(personId));
29
+ console.log('female', isFemale(personId));
18
30
  }
31
+
32
+ // functions can also be extended with branded types to narrow down the type guard of the personId (as example with zod BRAND)
33
+ if (isValidPersonId<z.BRAND<'PersonID'>>(personId)) {
34
+ // personId is typed as: string & z.BRAND<'PersonID'>
35
+ if (isMale<z.BRAND<'MalePersonID'>>(personId)) {
36
+ // personId is typed as: string & z.BRAND<'PersonID'> & z.BRAND<'MalePersonID'>
37
+ }
38
+ if (isFemale<z.BRAND<'FemalePersonID'>>(personId)) {
39
+ // personId is typed as: string & z.BRAND<'PersonID'> & z.BRAND<'FemalePersonID'>
40
+ }
41
+ }
42
+ ```
43
+
44
+ ## Functions
45
+
46
+ ### `isValidPersonId<BRAND = string>(personId: string): personId is string & BRAND`
47
+
48
+ Validates if the provided string is a valid Finnish person ID.
49
+
50
+ **Parameters:**
51
+
52
+ - `personId` - The person ID string to validate
53
+
54
+ **Returns:**
55
+
56
+ - `true` if the person ID is valid, `false` otherwise
57
+
58
+ **Example:**
59
+
60
+ ```javascript
61
+ isValidPersonId('131052-308T'); // true
62
+ isValidPersonId('131052-3082'); // false
63
+ ```
64
+
65
+ ### `isMale<BRAND = string>(personId: string): personId is string & BRAND`
66
+
67
+ Checks if the provided Finnish person ID belongs to a male.
68
+
69
+ **Parameters:**
70
+
71
+ - `personId` - The Finnish person ID string
72
+
73
+ **Returns:**
74
+
75
+ - `true` if the person ID belongs to a male, `false` otherwise
76
+
77
+ **Example:**
78
+
79
+ ```javascript
80
+ isMale('131052-309U'); // true
81
+ isMale('131052-308T'); // false
82
+ ```
83
+
84
+ ### `isFemale<BRAND = string>(personId: string): personId is string & BRAND`
85
+
86
+ Checks if the provided Finnish person ID belongs to a female.
87
+
88
+ **Parameters:**
89
+
90
+ - `personId` - The Finnish person ID string
91
+
92
+ **Returns:**
93
+
94
+ - `true` if the person ID belongs to a female, `false` otherwise
95
+
96
+ **Example:**
97
+
98
+ ```javascript
99
+ isFemale('131052-308T'); // true
100
+ isFemale('131052-309U'); // false
19
101
  ```
package/dist/index.d.mts CHANGED
@@ -1,29 +1,71 @@
1
1
  /**
2
- * Validate if string is a valid personId
3
- * @param personId - personId string
4
- * @returns true if valid, false if not
2
+ * Parse string to integer
3
+ * @throws TypeError if value is not a number
4
+ * @param value - string to parse
5
+ * @returns value as number
6
+ */
7
+ declare function parseStringToInt(value: string | undefined): number;
8
+ /**
9
+ * Validate that value is a string
10
+ * @throws TypeError if value is not a string
11
+ * @param value - value to validate
12
+ * @returns value as string
13
+ */
14
+ declare function validateString(value: unknown): string;
15
+ /**
16
+ * Get checksum for check sum index number
17
+ * @param index - index number to lookup checksum character
18
+ * @returns checksum character from checksum index map
19
+ */
20
+ declare function getCheckSum(index: number): string | undefined;
21
+ /**
22
+ * Validate if a string is a valid Finnish person ID
23
+ *
24
+ * A valid Finnish person ID consists of 11 characters in the format DDMMYYCZZZQ, where:
25
+ * - DDMMYY represents the date of birth
26
+ * - C is the century sign ('+' for 1800s, '-' for 1900s, 'A' for 2000s)
27
+ * - ZZZ is an individual number (odd numbers are males, even numbers are females)
28
+ * - Q is a checksum character
29
+ *
30
+ * The checksum character is calculated based on the first 10 characters.
31
+ * @param personId - The person ID string to validate
32
+ * @template BRAND - Optional: brand type for more strict type (i.e. use Zod branded type or custom type)
33
+ * @returns true if the person ID is valid, false otherwise
5
34
  * @example
6
35
  * isValidPersonId('131052-308T') // true
7
36
  * isValidPersonId('131052-3082') // false
37
+ * const personId = '131052-308T';
38
+ * if(isValidPersonId<z.BRAND<'PersonID'>>(personId)) { // personId type is now: string & z.BRAND<'PersonID'>
39
+ * // personId type is now: string & z.BRAND<'PersonID'>
40
+ * }
41
+ * @since v0.0.1
8
42
  */
9
- declare function isValidPersonId(personId: string): boolean;
43
+ declare function isValidPersonId<BRAND = string>(personId: string): personId is string & BRAND;
10
44
  /**
11
- * Check if personId is for male
45
+ * Check if personId belongs to a Finnish male
12
46
  * @throws TypeError if personId is not valid
13
- * @param personId - personId string
14
- * @returns true if valid, false if not
47
+ * @param personId - Finnish personId string
48
+ * @template BRAND - Optional: brand type for more strict type (i.e. use Zod branded type or custom type)
49
+ * @returns true if the personId belongs to a male, false otherwise
15
50
  * @example
51
+ * isMale('131052-309U') // true
16
52
  * isMale('131052-308T') // false
53
+ * isMale<z.BRAND<'PersonIdMale'>>(personId) // if true, personId type is now: string & z.BRAND<'PersonIdMale'>
54
+ * @since v0.0.1
17
55
  */
18
- declare function isMale(personId: string): boolean;
56
+ declare function isMale<BRAND = string>(personId: string): personId is string & BRAND;
19
57
  /**
20
- * Check if personId is for female
58
+ * Check if personId belongs to a Finnish female
21
59
  * @throws TypeError if personId is not valid
22
- * @param personId - personId string
23
- * @returns true if valid, false if not
60
+ * @param personId - Finnish personId string
61
+ * @template BRAND - Optional: brand type for more strict type (i.e. use Zod branded type or custom type)
62
+ * @returns true if the personId belongs to a female, false otherwise
24
63
  * @example
25
64
  * isFemale('131052-308T') // true
65
+ * isFemale('131052-309U') // false
66
+ * isFemale<z.BRAND<'PersonIdFemale'>>(personId) // if true, personId type is now: string & z.BRAND<'PersonIdFemale'>
67
+ * @since v0.0.1
26
68
  */
27
- declare function isFemale(personId: string): boolean;
69
+ declare function isFemale<BRAND = string>(personId: string): personId is string & BRAND;
28
70
 
29
- export { isFemale, isMale, isValidPersonId };
71
+ export { getCheckSum, isFemale, isMale, isValidPersonId, parseStringToInt, validateString };
package/dist/index.d.ts CHANGED
@@ -1,29 +1,71 @@
1
1
  /**
2
- * Validate if string is a valid personId
3
- * @param personId - personId string
4
- * @returns true if valid, false if not
2
+ * Parse string to integer
3
+ * @throws TypeError if value is not a number
4
+ * @param value - string to parse
5
+ * @returns value as number
6
+ */
7
+ declare function parseStringToInt(value: string | undefined): number;
8
+ /**
9
+ * Validate that value is a string
10
+ * @throws TypeError if value is not a string
11
+ * @param value - value to validate
12
+ * @returns value as string
13
+ */
14
+ declare function validateString(value: unknown): string;
15
+ /**
16
+ * Get checksum for check sum index number
17
+ * @param index - index number to lookup checksum character
18
+ * @returns checksum character from checksum index map
19
+ */
20
+ declare function getCheckSum(index: number): string | undefined;
21
+ /**
22
+ * Validate if a string is a valid Finnish person ID
23
+ *
24
+ * A valid Finnish person ID consists of 11 characters in the format DDMMYYCZZZQ, where:
25
+ * - DDMMYY represents the date of birth
26
+ * - C is the century sign ('+' for 1800s, '-' for 1900s, 'A' for 2000s)
27
+ * - ZZZ is an individual number (odd numbers are males, even numbers are females)
28
+ * - Q is a checksum character
29
+ *
30
+ * The checksum character is calculated based on the first 10 characters.
31
+ * @param personId - The person ID string to validate
32
+ * @template BRAND - Optional: brand type for more strict type (i.e. use Zod branded type or custom type)
33
+ * @returns true if the person ID is valid, false otherwise
5
34
  * @example
6
35
  * isValidPersonId('131052-308T') // true
7
36
  * isValidPersonId('131052-3082') // false
37
+ * const personId = '131052-308T';
38
+ * if(isValidPersonId<z.BRAND<'PersonID'>>(personId)) { // personId type is now: string & z.BRAND<'PersonID'>
39
+ * // personId type is now: string & z.BRAND<'PersonID'>
40
+ * }
41
+ * @since v0.0.1
8
42
  */
9
- declare function isValidPersonId(personId: string): boolean;
43
+ declare function isValidPersonId<BRAND = string>(personId: string): personId is string & BRAND;
10
44
  /**
11
- * Check if personId is for male
45
+ * Check if personId belongs to a Finnish male
12
46
  * @throws TypeError if personId is not valid
13
- * @param personId - personId string
14
- * @returns true if valid, false if not
47
+ * @param personId - Finnish personId string
48
+ * @template BRAND - Optional: brand type for more strict type (i.e. use Zod branded type or custom type)
49
+ * @returns true if the personId belongs to a male, false otherwise
15
50
  * @example
51
+ * isMale('131052-309U') // true
16
52
  * isMale('131052-308T') // false
53
+ * isMale<z.BRAND<'PersonIdMale'>>(personId) // if true, personId type is now: string & z.BRAND<'PersonIdMale'>
54
+ * @since v0.0.1
17
55
  */
18
- declare function isMale(personId: string): boolean;
56
+ declare function isMale<BRAND = string>(personId: string): personId is string & BRAND;
19
57
  /**
20
- * Check if personId is for female
58
+ * Check if personId belongs to a Finnish female
21
59
  * @throws TypeError if personId is not valid
22
- * @param personId - personId string
23
- * @returns true if valid, false if not
60
+ * @param personId - Finnish personId string
61
+ * @template BRAND - Optional: brand type for more strict type (i.e. use Zod branded type or custom type)
62
+ * @returns true if the personId belongs to a female, false otherwise
24
63
  * @example
25
64
  * isFemale('131052-308T') // true
65
+ * isFemale('131052-309U') // false
66
+ * isFemale<z.BRAND<'PersonIdFemale'>>(personId) // if true, personId type is now: string & z.BRAND<'PersonIdFemale'>
67
+ * @since v0.0.1
26
68
  */
27
- declare function isFemale(personId: string): boolean;
69
+ declare function isFemale<BRAND = string>(personId: string): personId is string & BRAND;
28
70
 
29
- export { isFemale, isMale, isValidPersonId };
71
+ export { getCheckSum, isFemale, isMale, isValidPersonId, parseStringToInt, validateString };
package/dist/index.js CHANGED
@@ -20,67 +20,65 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ getCheckSum: () => getCheckSum,
23
24
  isFemale: () => isFemale,
24
25
  isMale: () => isMale,
25
- isValidPersonId: () => isValidPersonId
26
+ isValidPersonId: () => isValidPersonId,
27
+ parseStringToInt: () => parseStringToInt,
28
+ validateString: () => validateString
26
29
  });
27
30
  module.exports = __toCommonJS(src_exports);
28
- var c = "0123456789ABCDEFHJKLMNPRSTUVWXY";
29
- function toInt(value) {
31
+ var checksumCharacterSet = "0123456789ABCDEFHJKLMNPRSTUVWXY";
32
+ var checkSumMapLength = checksumCharacterSet.length;
33
+ function parseStringToInt(value) {
30
34
  if (!value) {
31
- throw new TypeError("undefined");
35
+ throw new TypeError("Value is undefined");
32
36
  }
33
- const outValue = parseInt(value, 10);
34
- if (isNaN(outValue)) {
35
- throw new TypeError(`${value} not a number`);
37
+ const parsedValue = parseInt(value, 10);
38
+ if (isNaN(parsedValue)) {
39
+ throw new TypeError(`Value is not a number: ${value}`);
36
40
  }
37
- return outValue;
41
+ return parsedValue;
38
42
  }
39
- function getString(value) {
43
+ function validateString(value) {
40
44
  if (typeof value !== "string") {
41
- throw new TypeError(`${JSON.stringify(value)} not a string`);
45
+ throw new TypeError(`${String(value)} not a string`);
42
46
  }
43
47
  return value;
44
48
  }
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
- ];
49
+ function getCheckSum(index) {
50
+ if (index < 0 || index >= checkSumMapLength) {
51
+ throw new RangeError(`Index out of bounds: ${index.toString()} (valid range: 0-${String(checkSumMapLength - 1)})`);
52
+ }
53
+ return checksumCharacterSet[index];
62
54
  }
63
55
  function isValidPersonId(personId) {
64
- if (personId.length !== 11) {
56
+ if (typeof personId !== "string" || personId.length !== 11) {
57
+ return false;
58
+ }
59
+ const upperPersonId = personId.toUpperCase();
60
+ try {
61
+ return upperPersonId[10] === getCheckSum(parseStringToInt(upperPersonId.slice(0, 6) + upperPersonId.slice(7, 10)) % checkSumMapLength);
62
+ } catch (_error) {
65
63
  return false;
66
64
  }
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
65
  }
70
66
  function isMale(personId) {
71
67
  if (!isValidPersonId(personId)) {
72
- throw new TypeError("not valid person id");
68
+ throw new TypeError(`${String(personId)} is not valid person id`);
73
69
  }
74
- const d = buildCcValues(personId);
75
- return toInt(d[7] + d[8] + d[9]) % 2 === 1;
70
+ return parseStringToInt(personId.slice(7, 10)) % 2 === 1;
76
71
  }
77
72
  function isFemale(personId) {
78
73
  return !isMale(personId);
79
74
  }
80
75
  // Annotate the CommonJS export names for ESM import in node:
81
76
  0 && (module.exports = {
77
+ getCheckSum,
82
78
  isFemale,
83
79
  isMale,
84
- isValidPersonId
80
+ isValidPersonId,
81
+ parseStringToInt,
82
+ validateString
85
83
  });
86
84
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +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;AAAA;AAAA;AAAA;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,OAAwB;AAC1C,MAAI,OAAO,UAAU,UAAU;AAC9B,UAAM,IAAI,UAAU,GAAG,KAAK,UAAU,KAAK,CAAC,eAAe;AAAA,EAC5D;AACA,SAAO;AACR;AAOA,SAAS,cAAc,KAAiC;AACvD,SAAO,EAAE,GAAG;AACb;AAOA,SAAS,cAAc,UAA4G;AAClI,SAAO;AAAA,IACN,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,EAAE,CAAC;AAAA,EACvB;AACD;AAUO,SAAS,gBAAgB,UAA2B;AAC1D,MAAI,SAAS,WAAW,IAAI;AAC3B,WAAO;AAAA,EACR;AACA,QAAM,IAAI,cAAc,SAAS,YAAY,CAAC;AAC9C,SAAO,EAAE,EAAE,MAAM,cAAc,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,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":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["const checksumCharacterSet = '0123456789ABCDEFHJKLMNPRSTUVWXY';\nconst checkSumMapLength = checksumCharacterSet.length; // is always 31\n\n/**\n * Parse string to integer\n * @throws TypeError if value is not a number\n * @param value - string to parse\n * @returns value as number\n */\nexport function parseStringToInt(value: string | undefined): number {\n\tif (!value) {\n\t\tthrow new TypeError('Value is undefined');\n\t}\n\tconst parsedValue = parseInt(value, 10);\n\tif (isNaN(parsedValue)) {\n\t\tthrow new TypeError(`Value is not a number: ${value}`);\n\t}\n\treturn parsedValue;\n}\n\n/**\n * Validate that value is a string\n * @throws TypeError if value is not a string\n * @param value - value to validate\n * @returns value as string\n */\nexport function validateString(value: unknown): string {\n\tif (typeof value !== 'string') {\n\t\tthrow new TypeError(`${String(value)} not a string`);\n\t}\n\treturn value;\n}\n\n/**\n * Get checksum for check sum index number\n * @param index - index number to lookup checksum character\n * @returns checksum character from checksum index map\n */\nexport function getCheckSum(index: number): string | undefined {\n\tif (index < 0 || index >= checkSumMapLength) {\n\t\tthrow new RangeError(`Index out of bounds: ${index.toString()} (valid range: 0-${String(checkSumMapLength - 1)})`);\n\t}\n\treturn checksumCharacterSet[index];\n}\n\n/**\n * Validate if a string is a valid Finnish person ID\n *\n * A valid Finnish person ID consists of 11 characters in the format DDMMYYCZZZQ, where:\n * - DDMMYY represents the date of birth\n * - C is the century sign ('+' for 1800s, '-' for 1900s, 'A' for 2000s)\n * - ZZZ is an individual number (odd numbers are males, even numbers are females)\n * - Q is a checksum character\n *\n * The checksum character is calculated based on the first 10 characters.\n * @param personId - The person ID string to validate\n * @template BRAND - Optional: brand type for more strict type (i.e. use Zod branded type or custom type)\n * @returns true if the person ID is valid, false otherwise\n * @example\n * isValidPersonId('131052-308T') // true\n * isValidPersonId('131052-3082') // false\n * const personId = '131052-308T';\n * if(isValidPersonId<z.BRAND<'PersonID'>>(personId)) { // personId type is now: string & z.BRAND<'PersonID'>\n * // personId type is now: string & z.BRAND<'PersonID'>\n * }\n * @since v0.0.1\n */\nexport function isValidPersonId<BRAND = string>(personId: string): personId is string & BRAND {\n\tif (typeof personId !== 'string' || personId.length !== 11) {\n\t\treturn false;\n\t}\n\tconst upperPersonId = personId.toUpperCase();\n\ttry {\n\t\treturn upperPersonId[10] === getCheckSum(parseStringToInt(upperPersonId.slice(0, 6) + upperPersonId.slice(7, 10)) % checkSumMapLength);\n\t} catch (_error) {\n\t\treturn false;\n\t}\n}\n\n/**\n * Check if personId belongs to a Finnish male\n * @throws TypeError if personId is not valid\n * @param personId - Finnish personId string\n * @template BRAND - Optional: brand type for more strict type (i.e. use Zod branded type or custom type)\n * @returns true if the personId belongs to a male, false otherwise\n * @example\n * isMale('131052-309U') // true\n * isMale('131052-308T') // false\n * isMale<z.BRAND<'PersonIdMale'>>(personId) // if true, personId type is now: string & z.BRAND<'PersonIdMale'>\n * @since v0.0.1\n */\nexport function isMale<BRAND = string>(personId: string): personId is string & BRAND {\n\tif (!isValidPersonId(personId)) {\n\t\tthrow new TypeError(`${String(personId)} is not valid person id`);\n\t}\n\treturn parseStringToInt(personId.slice(7, 10)) % 2 === 1; // check if the individual number is odd\n}\n\n/**\n * Check if personId belongs to a Finnish female\n * @throws TypeError if personId is not valid\n * @param personId - Finnish personId string\n * @template BRAND - Optional: brand type for more strict type (i.e. use Zod branded type or custom type)\n * @returns true if the personId belongs to a female, false otherwise\n * @example\n * isFemale('131052-308T') // true\n * isFemale('131052-309U') // false\n * isFemale<z.BRAND<'PersonIdFemale'>>(personId) // if true, personId type is now: string & z.BRAND<'PersonIdFemale'>\n * @since v0.0.1\n */\nexport function isFemale<BRAND = string>(personId: string): personId is string & BRAND {\n\treturn !isMale(personId);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAM,uBAAuB;AAC7B,IAAM,oBAAoB,qBAAqB;AAQxC,SAAS,iBAAiB,OAAmC;AACnE,MAAI,CAAC,OAAO;AACX,UAAM,IAAI,UAAU,oBAAoB;AAAA,EACzC;AACA,QAAM,cAAc,SAAS,OAAO,EAAE;AACtC,MAAI,MAAM,WAAW,GAAG;AACvB,UAAM,IAAI,UAAU,0BAA0B,KAAK,EAAE;AAAA,EACtD;AACA,SAAO;AACR;AAQO,SAAS,eAAe,OAAwB;AACtD,MAAI,OAAO,UAAU,UAAU;AAC9B,UAAM,IAAI,UAAU,GAAG,OAAO,KAAK,CAAC,eAAe;AAAA,EACpD;AACA,SAAO;AACR;AAOO,SAAS,YAAY,OAAmC;AAC9D,MAAI,QAAQ,KAAK,SAAS,mBAAmB;AAC5C,UAAM,IAAI,WAAW,wBAAwB,MAAM,SAAS,CAAC,oBAAoB,OAAO,oBAAoB,CAAC,CAAC,GAAG;AAAA,EAClH;AACA,SAAO,qBAAqB,KAAK;AAClC;AAwBO,SAAS,gBAAgC,UAA8C;AAC7F,MAAI,OAAO,aAAa,YAAY,SAAS,WAAW,IAAI;AAC3D,WAAO;AAAA,EACR;AACA,QAAM,gBAAgB,SAAS,YAAY;AAC3C,MAAI;AACH,WAAO,cAAc,EAAE,MAAM,YAAY,iBAAiB,cAAc,MAAM,GAAG,CAAC,IAAI,cAAc,MAAM,GAAG,EAAE,CAAC,IAAI,iBAAiB;AAAA,EACtI,SAAS,QAAQ;AAChB,WAAO;AAAA,EACR;AACD;AAcO,SAAS,OAAuB,UAA8C;AACpF,MAAI,CAAC,gBAAgB,QAAQ,GAAG;AAC/B,UAAM,IAAI,UAAU,GAAG,OAAO,QAAQ,CAAC,yBAAyB;AAAA,EACjE;AACA,SAAO,iBAAiB,SAAS,MAAM,GAAG,EAAE,CAAC,IAAI,MAAM;AACxD;AAcO,SAAS,SAAyB,UAA8C;AACtF,SAAO,CAAC,OAAO,QAAQ;AACxB;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,59 +1,54 @@
1
1
  // src/index.ts
2
- var c = "0123456789ABCDEFHJKLMNPRSTUVWXY";
3
- function toInt(value) {
2
+ var checksumCharacterSet = "0123456789ABCDEFHJKLMNPRSTUVWXY";
3
+ var checkSumMapLength = checksumCharacterSet.length;
4
+ function parseStringToInt(value) {
4
5
  if (!value) {
5
- throw new TypeError("undefined");
6
+ throw new TypeError("Value is undefined");
6
7
  }
7
- const outValue = parseInt(value, 10);
8
- if (isNaN(outValue)) {
9
- throw new TypeError(`${value} not a number`);
8
+ const parsedValue = parseInt(value, 10);
9
+ if (isNaN(parsedValue)) {
10
+ throw new TypeError(`Value is not a number: ${value}`);
10
11
  }
11
- return outValue;
12
+ return parsedValue;
12
13
  }
13
- function getString(value) {
14
+ function validateString(value) {
14
15
  if (typeof value !== "string") {
15
- throw new TypeError(`${JSON.stringify(value)} not a string`);
16
+ throw new TypeError(`${String(value)} not a string`);
16
17
  }
17
18
  return value;
18
19
  }
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
- ];
20
+ function getCheckSum(index) {
21
+ if (index < 0 || index >= checkSumMapLength) {
22
+ throw new RangeError(`Index out of bounds: ${index.toString()} (valid range: 0-${String(checkSumMapLength - 1)})`);
23
+ }
24
+ return checksumCharacterSet[index];
36
25
  }
37
26
  function isValidPersonId(personId) {
38
- if (personId.length !== 11) {
27
+ if (typeof personId !== "string" || personId.length !== 11) {
28
+ return false;
29
+ }
30
+ const upperPersonId = personId.toUpperCase();
31
+ try {
32
+ return upperPersonId[10] === getCheckSum(parseStringToInt(upperPersonId.slice(0, 6) + upperPersonId.slice(7, 10)) % checkSumMapLength);
33
+ } catch (_error) {
39
34
  return false;
40
35
  }
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
36
  }
44
37
  function isMale(personId) {
45
38
  if (!isValidPersonId(personId)) {
46
- throw new TypeError("not valid person id");
39
+ throw new TypeError(`${String(personId)} is not valid person id`);
47
40
  }
48
- const d = buildCcValues(personId);
49
- return toInt(d[7] + d[8] + d[9]) % 2 === 1;
41
+ return parseStringToInt(personId.slice(7, 10)) % 2 === 1;
50
42
  }
51
43
  function isFemale(personId) {
52
44
  return !isMale(personId);
53
45
  }
54
46
  export {
47
+ getCheckSum,
55
48
  isFemale,
56
49
  isMale,
57
- isValidPersonId
50
+ isValidPersonId,
51
+ parseStringToInt,
52
+ validateString
58
53
  };
59
54
  //# sourceMappingURL=index.mjs.map
@@ -1 +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,OAAwB;AAC1C,MAAI,OAAO,UAAU,UAAU;AAC9B,UAAM,IAAI,UAAU,GAAG,KAAK,UAAU,KAAK,CAAC,eAAe;AAAA,EAC5D;AACA,SAAO;AACR;AAOA,SAAS,cAAc,KAAiC;AACvD,SAAO,EAAE,GAAG;AACb;AAOA,SAAS,cAAc,UAA4G;AAClI,SAAO;AAAA,IACN,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,CAAC,CAAC;AAAA,IACrB,UAAU,SAAS,EAAE,CAAC;AAAA,EACvB;AACD;AAUO,SAAS,gBAAgB,UAA2B;AAC1D,MAAI,SAAS,WAAW,IAAI;AAC3B,WAAO;AAAA,EACR;AACA,QAAM,IAAI,cAAc,SAAS,YAAY,CAAC;AAC9C,SAAO,EAAE,EAAE,MAAM,cAAc,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,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":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["const checksumCharacterSet = '0123456789ABCDEFHJKLMNPRSTUVWXY';\nconst checkSumMapLength = checksumCharacterSet.length; // is always 31\n\n/**\n * Parse string to integer\n * @throws TypeError if value is not a number\n * @param value - string to parse\n * @returns value as number\n */\nexport function parseStringToInt(value: string | undefined): number {\n\tif (!value) {\n\t\tthrow new TypeError('Value is undefined');\n\t}\n\tconst parsedValue = parseInt(value, 10);\n\tif (isNaN(parsedValue)) {\n\t\tthrow new TypeError(`Value is not a number: ${value}`);\n\t}\n\treturn parsedValue;\n}\n\n/**\n * Validate that value is a string\n * @throws TypeError if value is not a string\n * @param value - value to validate\n * @returns value as string\n */\nexport function validateString(value: unknown): string {\n\tif (typeof value !== 'string') {\n\t\tthrow new TypeError(`${String(value)} not a string`);\n\t}\n\treturn value;\n}\n\n/**\n * Get checksum for check sum index number\n * @param index - index number to lookup checksum character\n * @returns checksum character from checksum index map\n */\nexport function getCheckSum(index: number): string | undefined {\n\tif (index < 0 || index >= checkSumMapLength) {\n\t\tthrow new RangeError(`Index out of bounds: ${index.toString()} (valid range: 0-${String(checkSumMapLength - 1)})`);\n\t}\n\treturn checksumCharacterSet[index];\n}\n\n/**\n * Validate if a string is a valid Finnish person ID\n *\n * A valid Finnish person ID consists of 11 characters in the format DDMMYYCZZZQ, where:\n * - DDMMYY represents the date of birth\n * - C is the century sign ('+' for 1800s, '-' for 1900s, 'A' for 2000s)\n * - ZZZ is an individual number (odd numbers are males, even numbers are females)\n * - Q is a checksum character\n *\n * The checksum character is calculated based on the first 10 characters.\n * @param personId - The person ID string to validate\n * @template BRAND - Optional: brand type for more strict type (i.e. use Zod branded type or custom type)\n * @returns true if the person ID is valid, false otherwise\n * @example\n * isValidPersonId('131052-308T') // true\n * isValidPersonId('131052-3082') // false\n * const personId = '131052-308T';\n * if(isValidPersonId<z.BRAND<'PersonID'>>(personId)) { // personId type is now: string & z.BRAND<'PersonID'>\n * // personId type is now: string & z.BRAND<'PersonID'>\n * }\n * @since v0.0.1\n */\nexport function isValidPersonId<BRAND = string>(personId: string): personId is string & BRAND {\n\tif (typeof personId !== 'string' || personId.length !== 11) {\n\t\treturn false;\n\t}\n\tconst upperPersonId = personId.toUpperCase();\n\ttry {\n\t\treturn upperPersonId[10] === getCheckSum(parseStringToInt(upperPersonId.slice(0, 6) + upperPersonId.slice(7, 10)) % checkSumMapLength);\n\t} catch (_error) {\n\t\treturn false;\n\t}\n}\n\n/**\n * Check if personId belongs to a Finnish male\n * @throws TypeError if personId is not valid\n * @param personId - Finnish personId string\n * @template BRAND - Optional: brand type for more strict type (i.e. use Zod branded type or custom type)\n * @returns true if the personId belongs to a male, false otherwise\n * @example\n * isMale('131052-309U') // true\n * isMale('131052-308T') // false\n * isMale<z.BRAND<'PersonIdMale'>>(personId) // if true, personId type is now: string & z.BRAND<'PersonIdMale'>\n * @since v0.0.1\n */\nexport function isMale<BRAND = string>(personId: string): personId is string & BRAND {\n\tif (!isValidPersonId(personId)) {\n\t\tthrow new TypeError(`${String(personId)} is not valid person id`);\n\t}\n\treturn parseStringToInt(personId.slice(7, 10)) % 2 === 1; // check if the individual number is odd\n}\n\n/**\n * Check if personId belongs to a Finnish female\n * @throws TypeError if personId is not valid\n * @param personId - Finnish personId string\n * @template BRAND - Optional: brand type for more strict type (i.e. use Zod branded type or custom type)\n * @returns true if the personId belongs to a female, false otherwise\n * @example\n * isFemale('131052-308T') // true\n * isFemale('131052-309U') // false\n * isFemale<z.BRAND<'PersonIdFemale'>>(personId) // if true, personId type is now: string & z.BRAND<'PersonIdFemale'>\n * @since v0.0.1\n */\nexport function isFemale<BRAND = string>(personId: string): personId is string & BRAND {\n\treturn !isMale(personId);\n}\n"],"mappings":";AAAA,IAAM,uBAAuB;AAC7B,IAAM,oBAAoB,qBAAqB;AAQxC,SAAS,iBAAiB,OAAmC;AACnE,MAAI,CAAC,OAAO;AACX,UAAM,IAAI,UAAU,oBAAoB;AAAA,EACzC;AACA,QAAM,cAAc,SAAS,OAAO,EAAE;AACtC,MAAI,MAAM,WAAW,GAAG;AACvB,UAAM,IAAI,UAAU,0BAA0B,KAAK,EAAE;AAAA,EACtD;AACA,SAAO;AACR;AAQO,SAAS,eAAe,OAAwB;AACtD,MAAI,OAAO,UAAU,UAAU;AAC9B,UAAM,IAAI,UAAU,GAAG,OAAO,KAAK,CAAC,eAAe;AAAA,EACpD;AACA,SAAO;AACR;AAOO,SAAS,YAAY,OAAmC;AAC9D,MAAI,QAAQ,KAAK,SAAS,mBAAmB;AAC5C,UAAM,IAAI,WAAW,wBAAwB,MAAM,SAAS,CAAC,oBAAoB,OAAO,oBAAoB,CAAC,CAAC,GAAG;AAAA,EAClH;AACA,SAAO,qBAAqB,KAAK;AAClC;AAwBO,SAAS,gBAAgC,UAA8C;AAC7F,MAAI,OAAO,aAAa,YAAY,SAAS,WAAW,IAAI;AAC3D,WAAO;AAAA,EACR;AACA,QAAM,gBAAgB,SAAS,YAAY;AAC3C,MAAI;AACH,WAAO,cAAc,EAAE,MAAM,YAAY,iBAAiB,cAAc,MAAM,GAAG,CAAC,IAAI,cAAc,MAAM,GAAG,EAAE,CAAC,IAAI,iBAAiB;AAAA,EACtI,SAAS,QAAQ;AAChB,WAAO;AAAA,EACR;AACD;AAcO,SAAS,OAAuB,UAA8C;AACpF,MAAI,CAAC,gBAAgB,QAAQ,GAAG;AAC/B,UAAM,IAAI,UAAU,GAAG,OAAO,QAAQ,CAAC,yBAAyB;AAAA,EACjE;AACA,SAAO,iBAAiB,SAAS,MAAM,GAAG,EAAE,CAAC,IAAI,MAAM;AACxD;AAcO,SAAS,SAAyB,UAA8C;AACtF,SAAO,CAAC,OAAO,QAAQ;AACxB;","names":[]}
package/package.json CHANGED
@@ -1,89 +1,90 @@
1
1
  {
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"
2
+ "name": "fi-pin",
3
+ "version": "0.0.8",
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
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "import": "./dist/index.mjs"
13
+ }
14
+ },
15
+ "devDependencies": {
16
+ "@stylistic/eslint-plugin": "^2.10.0",
17
+ "@stylistic/eslint-plugin-ts": "^2.10.0",
18
+ "@types/node": "^18.19.61",
19
+ "@typescript-eslint/eslint-plugin": "^8.12.2",
20
+ "@typescript-eslint/parser": "^8.12.2",
21
+ "@vitest/coverage-v8": "^2.1.4",
22
+ "c8": "^10.1.2",
23
+ "eslint": "^8.57.1",
24
+ "eslint-config-prettier": "^9.1.0",
25
+ "eslint-config-standard": "^17.1.0",
26
+ "eslint-plugin-deprecation": "^3.0.0",
27
+ "eslint-plugin-jsdoc": "^50.4.3",
28
+ "eslint-plugin-prettier": "^5.2.1",
29
+ "eslint-plugin-sonarjs": "^0.23.0",
30
+ "source-map-support": "^0.5.21",
31
+ "tsup": "^8.3.5",
32
+ "typescript": "^5.6.3",
33
+ "vite": "^5.4.10",
34
+ "vitest": "^2.1.4",
35
+ "zod": "^3.23.8"
36
+ },
37
+ "mocha": {
38
+ "exit": true,
39
+ "extension": [
40
+ "ts",
41
+ "js"
62
42
  ],
63
- "files": [
64
- "dist"
43
+ "recursive": true,
44
+ "require": [
45
+ "ts-node/register",
46
+ "source-map-support/register"
65
47
  ],
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"
89
- }
48
+ "reporters": [
49
+ "spec",
50
+ "mocha-junit-reporter"
51
+ ]
52
+ },
53
+ "keywords": [
54
+ "pin",
55
+ "personid"
56
+ ],
57
+ "files": [
58
+ "dist"
59
+ ],
60
+ "nyc": {
61
+ "extension": [
62
+ ".ts"
63
+ ],
64
+ "include": [
65
+ "src"
66
+ ],
67
+ "reporter": [
68
+ "text",
69
+ "lcovonly"
70
+ ],
71
+ "all": true
72
+ },
73
+ "repository": {
74
+ "type": "git",
75
+ "url": "git+https://github.com/mharj/hetu.git"
76
+ },
77
+ "author": "mharj",
78
+ "license": "MIT",
79
+ "bugs": {
80
+ "url": "https://github.com/mharj/hetu/issues"
81
+ },
82
+ "homepage": "https://github.com/mharj/hetu#readme",
83
+ "scripts": {
84
+ "build": "tsup src/index.ts --sourcemap --format cjs,esm --dts --clean",
85
+ "test": "vitest test --run --no-isolate --coverage",
86
+ "coverage": "vitest test --run --no-isolate --reporter=dot --coverage --coverage.reporter=lcov",
87
+ "lint": "eslint . --ext .ts",
88
+ "validate": "tsc --noEmit"
89
+ }
90
+ }