fi-pin 0.0.5 → 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 CHANGED
File without changes
package/README.md CHANGED
@@ -1,19 +1,19 @@
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)
2
-
3
- ```javascript
4
- const {isFemale, isMale, isValidPersonId} = require('fi-pin');
5
-
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'));
18
- }
19
- ```
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)
2
+
3
+ ```javascript
4
+ const {isFemale, isMale, isValidPersonId} = require('fi-pin');
5
+
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'));
18
+ }
19
+ ```
@@ -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
- export declare const isValidPersonId: (hetu: string) => boolean;
2
- export declare const isMale: (hetu: string) => boolean;
3
- export declare const isFemale: (hetu: string) => boolean;
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,24 +1,86 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFemale = exports.isMale = exports.isValidPersonId = void 0;
4
- var c = '0123456789ABCDEFHJKLMNPRSTUVWXY';
5
- var getCC = function (num) {
6
- return c[num] ? c[num] : null;
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 });
7
9
  };
8
- exports.isValidPersonId = function (hetu) {
9
- if (hetu.length !== 11) {
10
- return false;
11
- }
12
- var d = hetu.toUpperCase();
13
- return d[10] === getCC(parseInt(d[0] + d[1] + d[2] + d[3] + d[4] + d[5] + d[7] + d[8] + d[9], 10) % 31);
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;
14
17
  };
15
- exports.isMale = function (hetu) {
16
- if (!exports.isValidPersonId(hetu)) {
17
- throw new Error('not valid person id');
18
- }
19
- return parseInt(hetu[7] + hetu[8] + hetu[9], 10) % 2 === 1 ? true : false;
20
- };
21
- exports.isFemale = function (hetu) {
22
- return !exports.isMale(hetu);
23
- };
24
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiLi9zcmMvIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxJQUFNLENBQUMsR0FBRyxpQ0FBaUMsQ0FBQztBQUU1QyxJQUFNLEtBQUssR0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DEwKSAlIDIgPT09IDEgPyB0cnVlIDogZmFsc2U7XG59O1xuXG5leHBvcnQgY29uc3QgaXNGZW1hbGUgPSAoaGV0dTogc3RyaW5nKTogYm9vbGVhbiA9PiB7XG5cdHJldHVybiAhaXNNYWxlKGhldHUpO1xufTtcbiJdfQ==
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;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":[]}
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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,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/package.json CHANGED
@@ -1,67 +1,89 @@
1
1
  {
2
- "name": "fi-pin",
3
- "version": "0.0.5",
4
- "description": "Finnish Personal Identification Number validate + gender check",
5
- "main": "dist/index.js",
6
- "devDependencies": {
7
- "@types/chai": "^4.2.11",
8
- "@types/mocha": "^7.0.2",
9
- "@types/node": "^12.12.44",
10
- "chai": "^4.2.0",
11
- "mocha": "^7.2.0",
12
- "mocha-junit-reporter": "^1.23.3",
13
- "nyc": "^15.1.0",
14
- "source-map-support": "^0.5.19",
15
- "ts-node": "^8.10.2",
16
- "tslint": "^6.1.2",
17
- "tslint-config-prettier": "^1.18.0",
18
- "typescript": "^3.9.5"
19
- },
20
- "scripts": {
21
- "build": "tsc",
22
- "prepublishOnly": "npm run test && npm run build",
23
- "test": "nyc mocha test/*.ts"
24
- },
25
- "mocha": {
26
- "exit": true,
27
- "recursive": true,
28
- "require": [
29
- "ts-node/register",
30
- "source-map-support/register"
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"
31
62
  ],
32
- "reporters": [
33
- "spec",
34
- "mocha-junit-reporter"
35
- ]
36
- },
37
- "keywords": [
38
- "pin",
39
- "personid"
40
- ],
41
- "files": [
42
- "dist"
43
- ],
44
- "nyc": {
45
- "extension": [
46
- ".ts"
63
+ "files": [
64
+ "dist"
47
65
  ],
48
- "include": [
49
- "src"
50
- ],
51
- "reporter": [
52
- "text",
53
- "lcovonly"
54
- ],
55
- "all": true
56
- },
57
- "repository": {
58
- "type": "git",
59
- "url": "git+https://github.com/mharj/hetu.git"
60
- },
61
- "author": "mharj",
62
- "license": "MIT",
63
- "bugs": {
64
- "url": "https://github.com/mharj/hetu/issues"
65
- },
66
- "homepage": "https://github.com/mharj/hetu#readme"
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"
67
89
  }