mielk-fn 1.0.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/.babelrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "presets": ["@babel/preset-env"]
3
+ }
@@ -0,0 +1,93 @@
1
+ {
2
+ "arrays": {
3
+ "toIndexedArray": {
4
+ "summary": "Creates a new array where items are placed at their corresponding indices determined by a callback function.",
5
+ "signature": "const toIndexedArray = (items: any[], callback: CallbackFunction): any[]",
6
+ "parameters": [
7
+ {
8
+ "name": "items",
9
+ "type": "any[]",
10
+ "description": "The input array of items to be indexed."
11
+ },
12
+ {
13
+ "name": "callback",
14
+ "type": "CallbackFunction",
15
+ "description": "The function that determines the index at which each item should be placed in the resulting array."
16
+ }
17
+ ],
18
+ "returns": {
19
+ "type": "any[]",
20
+ "description": "A new array where items are placed at their corresponding indices, as determined by the callback function."
21
+ },
22
+ "examples": [
23
+ [
24
+ "<span class=\"keyword\">const</span> items = [ { name: <span class=\"string\">'Adam'</span>, id: <span class=\"number\">1</span> }, { name: <span class=\"string\">'Bartek'</span>, id: <span class=\"number\">4</span> }, { name: <span class=\"string\">'Czesiek'</span>, id: <span class=\"number\">5</span> }];",
25
+ "<span class=\"keyword\">const</span> callback = (item) => item.id;",
26
+ "<span class=\"keyword\">const</span> result = <span class=\"function\">toIndexedArray</span>(items, callback);",
27
+ "<span class=\"comment\">// result: [ { name: 'Adam', id: 1 }, , , { name: 'Bartek', id: 4 }, { name: 'Czesiek', id: 5 } ]</span>"
28
+ ],
29
+ [
30
+ "<span class=\"keyword\">class</span> Person {",
31
+ " <span class=\"keyword\">constructor</span>(public name: <span class=\"keyword\">string</span>, public age: <span class=\"keyword\">number</span>) {}",
32
+ " <span class=\"function\">getAge</span>() { <span class=\"keyword\">return</span> <span class=\"keyword\">this</span>.age; }",
33
+ "}",
34
+ "<span class=\"keyword\">const</span> people = [<span class=\"keyword\">new</span> Person(<span class=\"string\">'John'</span>, <span class=\"number\">20</span>), <span class=\"keyword\">new</span> Person(<span class=\"string\">'Jane'</span>, <span class=\"number\">25</span>), <span class=\"keyword\">new</span> Person(<span class=\"string\">'Alice'</span>, <span class=\"number\">30</span>)];",
35
+ "<span class=\"keyword\">const</span> callback = (person) => person.<span class=\"function\">getAge</span>();",
36
+ "<span class=\"keyword\">const</span> result = <span class=\"function\">toIndexedArray</span>(people, callback);",
37
+ "<span class=\"comment\">// result: [ , { name: 'John', age: 20 }, , , { name: 'Jane', age: 25 }, { name: 'Alice', age: 30 } ]</span>"
38
+ ]
39
+ ]
40
+ },
41
+ "toMap": {
42
+ "summary": "Converts an array of items into a Map object, using a key callback function to determine the keys and an optional value function to determine the values.",
43
+ "signature": "function toMap(items: any[], keyCallback: StringNumberFunction, valueFn: ValueFunction = (item) => item, ignoreDuplicates = true): Map<any, any>",
44
+ "parameters": [
45
+ {
46
+ "name": "items",
47
+ "type": "any[]",
48
+ "description": "The array of items to convert to a Map."
49
+ },
50
+ {
51
+ "name": "keyCallback",
52
+ "type": "StringNumberFunction",
53
+ "description": "A callback function that accepts an item and returns a string or number that will be used as the key in the Map."
54
+ },
55
+ {
56
+ "name": "valueFn",
57
+ "type": "ValueFunction",
58
+ "description": "An optional callback function that accepts an item and returns the value to be associated with the key in the Map. Defaults to the item itself."
59
+ },
60
+ {
61
+ "name": "ignoreDuplicates",
62
+ "type": "boolean",
63
+ "description": "An optional boolean value that determines whether to ignore items with duplicate keys. Defaults to `true`."
64
+ }
65
+ ],
66
+ "returns": {
67
+ "type": "Map<any, any>",
68
+ "description": "Returns a new Map object containing the key-value pairs."
69
+ },
70
+ "examples": [
71
+ [
72
+ "<span class=\"keyword\">const</span> items = [<span class=\"json\">{</span> id: <span class=\"number\">1</span>, name: <span class=\"string\">'John'</span> }, <span class=\"json\">{</span> id: <span class=\"number\">2</span>, name: <span class=\"string\">'Jane'</span> }, <span class=\"json\">{</span> id: <span class=\"number\">3</span>, name: <span class=\"string\">'Bob'</span> }];",
73
+ "<span class=\"keyword\">const</span> keyCallback = (item) => item.id;",
74
+ "<span class=\"keyword\">const</span> map = <span class=\"function\">toMap</span>(items, keyCallback);",
75
+ "console.log(map); <span class=\"comment\">// Output: Map(3) { 1 => { id: 1, name: 'John' }, 2 => { id: 2, name: 'Jane' }, 3 => { id: 3, name: 'Bob' } }</span>"
76
+ ],
77
+ [
78
+ "<span class=\"keyword\">const</span> items = [<span class=\"json\">{</span> id: <span class=\"number\">1</span>, name: <span class=\"string\">'John'</span> }, <span class=\"json\">{</span> id: <span class=\"number\">2</span>, name: <span class=\"string\">'Jane'</span> }, <span class=\"json\">{</span> id: <span class=\"number\">3</span>, name: <span class=\"string\">'Bob'</span> }];",
79
+ "<span class=\"keyword\">const</span> keyCallback = (item) => item.name;",
80
+ "<span class=\"keyword\">const</span> valueFn = (item) => item.id;",
81
+ "<span class=\"keyword\">const</span> map = <span class=\"function\">toMap</span>(items, keyCallback, valueFn);",
82
+ "console.log(map); <span class=\"comment\">// Output: Map(3) { 'John' => 1, 'Jane' => 2, 'Bob' => 3 }</span>"
83
+ ],
84
+ [
85
+ "<span class=\"keyword\">const</span> items = [<span class=\"json\">{</span> id: <span class=\"number\">1</span>, name: <span class=\"string\">'John'</span> }, <span class=\"json\">{</span> id: <span class=\"number\">2</span>, name: <span class=\"string\">'Jane'</span> }, <span class=\"json\">{</span> id: <span class=\"number\">2</span>, name: <span class=\"string\">'Bob'</span> }];",
86
+ "<span class=\"keyword\">const</span> keyCallback = (item) => item.id;",
87
+ "<span class=\"keyword\">const</span> map = <span class=\"function\">toMap</span>(items, keyCallback, undefined, false);",
88
+ "console.log(map); <span class=\"comment\">// Output: Map(2) { 1 => { id: 1, name: 'John' }, 2 => { id: 2, name: 'Bob' } }</span>"
89
+ ]
90
+ ]
91
+ }
92
+ }
93
+ }
package/help/help.js ADDED
File without changes
@@ -0,0 +1,90 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>isObject Function Documentation</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ }
11
+ h1,
12
+ h2 {
13
+ color: #333;
14
+ }
15
+ h2 {
16
+ margin-top: 1.5em;
17
+ margin-bottom: 0.5em;
18
+ }
19
+ code {
20
+ background-color: #f0f0f0;
21
+ padding: 2px 4px;
22
+ font-family: 'Courier New', monospace;
23
+ }
24
+ pre {
25
+ background-color: #1e1e1e;
26
+ padding: 16px;
27
+ overflow-x: auto;
28
+ color: #d4d4d4;
29
+ font-family: 'Courier New', monospace;
30
+ border-radius: 4px;
31
+ font-size: 14px;
32
+ }
33
+ .keyword {
34
+ color: #c586c0;
35
+ }
36
+ .number {
37
+ color: #b5cea8;
38
+ }
39
+ .function {
40
+ color: #dcdcaa;
41
+ }
42
+ .comment {
43
+ color: #6a9955;
44
+ }
45
+ p {
46
+ margin-top: 0;
47
+ }
48
+ </style>
49
+ </head>
50
+ <body>
51
+ <div class="header">Documentation mielk-fn</div>
52
+ <div class="menu"></div>
53
+ <div class="content">
54
+ <h1 class="name"></h1>
55
+
56
+ <h2>Summary</h2>
57
+ <p class="summary"></p>
58
+
59
+ <h2>Signature</h2>
60
+ <pre class="signature">
61
+ function isObject(value: unknown): boolean
62
+ </pre
63
+ >
64
+
65
+ <h2>Parameters</h2>
66
+ <dl class="parameters">
67
+ <dt><code>value: unknown</code></dt>
68
+ <dd>The value to be checked for being an object.</dd>
69
+ </dl>
70
+
71
+ <h2>Returns</h2>
72
+ <p><code class="type"></code>: <span class="returns"></span>.</p>
73
+
74
+ <h2>Examples</h2>
75
+ <pre class="examples">
76
+ <span class="comment">// Example 1:</span>
77
+ <span class="keyword">const</span> obj = { key: <span class="string">'value'</span> };
78
+ console.log(<span class="function">isObject</span>(obj)); <span class="comment">// Output: true</span>
79
+
80
+ <span class="comment">// Example 2:</span>
81
+ <span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
82
+ console.log(<span class="function">isObject</span>(arr)); <span class="comment">// Output: false</span>
83
+
84
+ <span class="comment">// Example 3:</span>
85
+ console.log(<span class="function">isObject</span>(<span class="keyword">null</span>)); <span class="comment">// Output: false</span>
86
+ </pre>
87
+ </div>
88
+ <script src="help.js"></script>
89
+ </body>
90
+ </html>
@@ -0,0 +1,221 @@
1
+ {
2
+ "objects": {
3
+ "invert": {
4
+ "summary": "Swaps keys and values for a given JavaScript object.",
5
+ "signature": "function invert(obj: Record<string | number, string | number>): Record<string | number, string | number>",
6
+ "parameters": [
7
+ {
8
+ "name": "obj",
9
+ "type": "Record<string | number, string | number>",
10
+ "description": "The object for which keys and values should be swapped."
11
+ }
12
+ ],
13
+ "returns": {
14
+ "type": "Record<string | number, string | number>",
15
+ "description": "Returns a new object with the keys and values of the input object swapped."
16
+ },
17
+ "restrictions": [
18
+ "The input object must have keys and values of type string or number."
19
+ ],
20
+ "examples": [
21
+ [
22
+ "const input = { key1: <span class=\"string\">'value1'</span>, key2: <span class=\"string\">'value2'</span> };",
23
+ "const result = <span class=\"function\">invert</span>(input);",
24
+ "console.log(result); <span class=\"comment\">// Output: { value1: 'key1', value2: 'key2' }</span>"
25
+ ],
26
+ [
27
+ "const input = { [<span class=\"number\">1</span>]: <span class=\"number\">2</span>, [<span class=\"number\">3</span>]: <span class=\"number\">4</span> };",
28
+ "const result = <span class=\"function\">invert</span>(input);",
29
+ "console.log(result); <span class=\"comment\">// Output: { 2: '1', 4: '3' }</span>"
30
+ ],
31
+ [
32
+ "const input = { key1: <span class=\"number\">1</span>, [<span class=\"number\">2</span>]: <span class=\"string\">'value2'</span> };",
33
+ "const result = <span class=\"function\">invert</span>(input);",
34
+ "console.log(result); <span class=\"comment\">// Output: { 1: 'key1', value2: '2' }</span>"
35
+ ],
36
+ [
37
+ "const input = {};",
38
+ "const result = <span class=\"function\">invert</span>(input);",
39
+ "console.log(result); <span class=\"comment\">// Output: {}</span>"
40
+ ]
41
+ ]
42
+ },
43
+ "isObject": {
44
+ "summary": "Determines if the given value is an object, excluding arrays and null values.",
45
+ "signature": "function isObject(value: unknown): boolean",
46
+ "parameters": [
47
+ {
48
+ "name": "value",
49
+ "type": "unknown",
50
+ "description": "The value to be checked for being an object."
51
+ }
52
+ ],
53
+ "returns": {
54
+ "type": "boolean",
55
+ "description": "Returns <code>true</code> if the input value is an object (excluding arrays and null values), and <code>false</code> otherwise."
56
+ },
57
+ "examples": [
58
+ [
59
+ "<span class=\"keyword\">const</span> obj = { key: <span class=\"string\">'value'</span> };",
60
+ "console.log(<span class=\"function\">isObject</span>(obj)); <span class=\"comment\">// Output: true</span>"
61
+ ],
62
+ [
63
+ "<span class=\"keyword\">const</span> arr = [<span class=\"number\">1</span>, <span class=\"number\">2</span>, <span class=\"number\">3</span>];",
64
+ "console.log(<span class=\"function\">isObject</span>(arr)); <span class=\"comment\">// Output: false</span>"
65
+ ],
66
+ [
67
+ "console.log(<span class=\"function\">isObject</span>(<span class=\"keyword\">null</span>)); <span class=\"comment\">// Output: false</span>"
68
+ ]
69
+ ]
70
+ },
71
+ "isPlainObject": {
72
+ "summary": "Checks if a value is a plain JavaScript object.",
73
+ "signature": "(value: unknown) => boolean",
74
+ "parameters": [
75
+ {
76
+ "name": "value",
77
+ "type": "unknown",
78
+ "description": "The value to check."
79
+ }
80
+ ],
81
+ "returns": {
82
+ "type": "boolean",
83
+ "description": "Returns `true` if the value is a plain JavaScript object, `false` otherwise."
84
+ },
85
+ "examples": [
86
+ [
87
+ "<span class=\"keyword\">const</span> obj = { id: 1, name: 'John' };",
88
+ "<span class=\"function\">console.log</span>(<span class=\"function\">isPlainObject</span>(obj)); <span class=\"comment\">// Output: true</span>"
89
+ ],
90
+ [
91
+ "<span class=\"keyword\">const</span> date = <span class=\"keyword\">new</span> <span class=\"class\">Date</span>();",
92
+ "<span class=\"function\">console.log</span>(<span class=\"function\">isPlainObject</span>(date)); <span class=\"comment\">// Output: false</span>"
93
+ ],
94
+ [
95
+ "<span class=\"keyword\">class</span> <span class=\"class\">Person</span> {",
96
+ " <span class=\"keyword\">constructor</span>(<span class=\"keyword\">public</span> name: <span class=\"keyword\">string</span>) {}",
97
+ "}",
98
+ "<span class=\"keyword\">const</span> person = <span class=\"keyword\">new</span> <span class=\"class\">Person</span>('Jane');",
99
+ "<span class=\"function\">console.log</span>(<span class=\"function\">isPlainObject</span>(person)); <span class=\"comment\">// Output: false</span>"
100
+ ],
101
+ [
102
+ "<span class=\"keyword\">const</span> user = { name: 'Alice', age: 25, isAdmin: <span class=\"literal\">false</span> };",
103
+ "<span class=\"function\">console.log</span>(<span class=\"function\">isPlainObject</span>(user)); <span class=\"comment\">// Output: true</span>"
104
+ ],
105
+ [
106
+ "<span class=\"keyword\">const</span> arr = [<span class=\"string\">'apple'</span>, <span class=\"string\">'banana'</span>, <span class=\"string\">'orange'</span>];",
107
+ "<span class=\"function\">console.log</span>(<span class=\"function\">isPlainObject</span>(arr)); <span class=\"comment\">// Output: false</span>"
108
+ ]
109
+ ]
110
+ },
111
+ "merge": {
112
+ "summary": "Merges two or more objects and returns an object that has properties of all those input objects.",
113
+ "signature": "function merge(objects: AnyObject[], override: boolean = false): AnyObject",
114
+ "parameters": [
115
+ {
116
+ "name": "objects",
117
+ "type": "AnyObject[]",
118
+ "description": "An array of JavaScript objects to be merged."
119
+ },
120
+ {
121
+ "name": "override",
122
+ "type": "boolean",
123
+ "description": "An optional parameter that determines which value should be assigned to the returned object if there is a conflict (more than one input objects have the same property). If this value is set to true, the last found value of the given property will be assigned to the returned object, otherwise the first found value."
124
+ }
125
+ ],
126
+ "returns": {
127
+ "type": "AnyObject",
128
+ "description": "Returns an object that has properties of all the input objects, merged according to the 'override' parameter."
129
+ },
130
+ "examples": [
131
+ [
132
+ "<span class=\"keyword\">const</span> obj = { a: 1, b: 2, c: 3 };",
133
+ "<span class=\"keyword\">const</span> callback = (key) => key.toUpperCase();",
134
+ "<span class=\"keyword\">const</span> result = <span class=\"function\">modifyKeys</span>(obj, callback);",
135
+ "console.log(result); <span class=\"comment\">// Output: { A: 1, B: 2, C: 3 }</span>"
136
+ ],
137
+ [
138
+ "<span class=\"keyword\">const</span> obj = { a: 1, b: 2, c: 3 };",
139
+ "<span class=\"keyword\">const</span> callback = (key) => key + '_new';",
140
+ "<span class=\"keyword\">const</span> result = <span class=\"function\">modifyKeys</span>(obj, callback);",
141
+ "console.log(result); <span class=\"comment\">// Output: { a_new: 1, b_new: 2, c_new: 3 }</span>"
142
+ ],
143
+ [
144
+ "<span class=\"keyword\">const</span> obj = { 1: 'a', 2: 'b', 3: 'c' };",
145
+ "<span class=\"keyword\">const</span> callback = (key) => parseInt(key) + 1;",
146
+ "<span class=\"keyword\">const</span> result = <span class=\"function\">modifyKeys</span>(obj, callback);",
147
+ "console.log(result); <span class=\"comment\">// Output: { 2: 'a', 3: 'b', 4: 'c' }</span>"
148
+ ],
149
+ [
150
+ "<span class=\"keyword\">const</span> obj = { a: 1, b: 2, c: 3 };",
151
+ "<span class=\"keyword\">const</span> callback = (key) => key;",
152
+ "<span class=\"keyword\">const</span> result = <span class=\"function\">modifyKeys</span>(obj, callback, false);",
153
+ "console.log(result); <span class=\"comment\">// Output: { a: 1, b: 2, c: 3 }</span>"
154
+ ],
155
+ [
156
+ "<span class=\"keyword\">const</span> obj = { a: 1, b: 2, c: 3, 1: 'd' };",
157
+ "<span class=\"keyword\">const</span> callback = (key) => key;",
158
+ "<span class=\"keyword\">const</span> result = <span class=\"function\">modifyKeys</span>(obj, callback, true);",
159
+ "console.log(result); <span class=\"comment\">// Output: { a: 1, b: 2, c: 3 }</span>"
160
+ ]
161
+ ]
162
+ },
163
+ "modifyKeys": {
164
+ "name": "modifyKeys",
165
+ "description": "Modifies an object's keys based on a callback function.",
166
+ "params": [
167
+ {
168
+ "name": "obj",
169
+ "type": "Object",
170
+ "description": "The object to modify the keys for."
171
+ },
172
+ {
173
+ "name": "callback",
174
+ "type": "Function",
175
+ "description": "The callback function to determine the new keys for each object."
176
+ },
177
+ {
178
+ "name": "ignoreDuplicates",
179
+ "type": "boolean",
180
+ "description": "An optional boolean value that determines whether to ignore objects with duplicate keys. Defaults to `true`."
181
+ }
182
+ ],
183
+ "returns": {
184
+ "type": "Object",
185
+ "description": "The modified object with new keys."
186
+ },
187
+ "examples": [
188
+ [
189
+ "<span class=\"keyword\">const</span> obj = { a: 1, b: 2, c: 3 };",
190
+ "<span class=\"keyword\">const</span> callback = (key) => key.toUpperCase();",
191
+ "<span class=\"keyword\">const</span> result = <span class=\"function\">modifyKeys</span>(obj, callback);",
192
+ "console.log(result); <span class=\"comment\">// Output: { A: 1, B: 2, C: 3 }</span>"
193
+ ],
194
+ [
195
+ "<span class=\"keyword\">const</span> obj = { a: 1, b: 2, c: 3 };",
196
+ "<span class=\"keyword\">const</span> callback = (key) => key + '_new';",
197
+ "<span class=\"keyword\">const</span> result = <span class=\"function\">modifyKeys</span>(obj, callback);",
198
+ "console.log(result); <span class=\"comment\">// Output: { a_new: 1, b_new: 2, c_new: 3 }</span>"
199
+ ],
200
+ [
201
+ "<span class=\"keyword\">const</span> obj = { 1: 'a', 2: 'b', 3: 'c' };",
202
+ "<span class=\"keyword\">const</span> callback = (key) => parseInt(key) + 1;",
203
+ "<span class=\"keyword\">const</span> result = <span class=\"function\">modifyKeys</span>(obj, callback);",
204
+ "console.log(result); <span class=\"comment\">// Output: { 2: 'a', 3: 'b', 4: 'c' }</span>"
205
+ ],
206
+ [
207
+ "<span class=\"keyword\">const</span> obj = { a: 1, b: 2, c: 3 };",
208
+ "<span class=\"keyword\">const</span> callback = (key) => key;",
209
+ "<span class=\"keyword\">const</span> result = <span class=\"function\">modifyKeys</span>(obj, callback, false);",
210
+ "console.log(result); <span class=\"comment\">// Output: { a: 1, b: 2, c: 3 }</span>"
211
+ ],
212
+ [
213
+ "<span class=\"keyword\">const</span> obj = { a: 1, b: 2, c: 3, 1: 'd' };",
214
+ "<span class=\"keyword\">const</span> callback = (key) => key;",
215
+ "<span class=\"keyword\">const</span> result = <span class=\"function\">modifyKeys</span>(obj, callback, true);",
216
+ "console.log(result); <span class=\"comment\">// Output: { a: 1, b: 2, c: 3 }</span>"
217
+ ]
218
+ ]
219
+ }
220
+ }
221
+ }
package/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ // import arrays from './lib/arrays.js';
2
+ import objects from './src/objects';
3
+ // import routing from './lib/routing.js';
4
+
5
+ // export { arrays, objects, routing };
6
+ export { objects };
@@ -0,0 +1,8 @@
1
+ type NumberFunction = (item: any) => number;
2
+ type StringNumberFunction = (item: any) => string | number;
3
+ type AnyFunction = (item: any) => any;
4
+ declare const _default: {
5
+ toMap: (items: any[], keyCallback: StringNumberFunction, valueFn?: AnyFunction, ignoreDuplicates?: boolean) => Map<any, any>;
6
+ toIndexedArray: (items: any[], callback: NumberFunction) => any[];
7
+ };
8
+ export default _default;
package/lib/arrays.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const toMap = (items, keyCallback, valueFn = (item) => item, ignoreDuplicates = true) => {
4
+ const map = new Map();
5
+ items.forEach((item) => {
6
+ const key = keyCallback(item);
7
+ const value = valueFn ? valueFn(item) : item;
8
+ if (ignoreDuplicates && map.has(key)) {
9
+ }
10
+ else {
11
+ map.set(key, value);
12
+ }
13
+ });
14
+ return map;
15
+ };
16
+ const toIndexedArray = (items, callback) => {
17
+ const arr = [];
18
+ items.forEach((item) => {
19
+ // Check if item is an object and has a function named callback
20
+ if (typeof item === 'object' && item !== null) {
21
+ const index = callback(item);
22
+ if (typeof index !== 'number') {
23
+ throw new TypeError('Callback should return a number.');
24
+ }
25
+ arr[index] = item;
26
+ }
27
+ });
28
+ return arr;
29
+ };
30
+ exports.default = { toMap, toIndexedArray };
@@ -0,0 +1,12 @@
1
+ type AnyObject = {
2
+ [key: string]: any;
3
+ };
4
+ type NumberStringFunction = (key: string, item: any) => number | string;
5
+ declare const _default: {
6
+ isObject: (value: unknown) => boolean;
7
+ isPlainObject: (value: unknown) => boolean;
8
+ merge: (objects: AnyObject[], override?: boolean) => AnyObject;
9
+ invert: (obj: Record<string | number, string | number>) => Record<string | number, string | number>;
10
+ modifyKeys: (obj: AnyObject, callback: NumberStringFunction, ignoreDuplicates?: boolean) => AnyObject;
11
+ };
12
+ export default _default;
package/lib/objects.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const isObject = (value) => typeof value === 'object' && !Array.isArray(value) && value !== null;
4
+ const isPlainObject = (value) => (value === null || value === void 0 ? void 0 : value.constructor.name) === 'Object';
5
+ const merge = (objects, override = false) => {
6
+ const merged = {};
7
+ objects.forEach((obj) => {
8
+ if (isObject(obj)) {
9
+ const entries = Object.entries(obj);
10
+ entries.forEach(([key, value]) => {
11
+ if (!merged[key] || override)
12
+ merged[key] = value;
13
+ });
14
+ }
15
+ });
16
+ return merged;
17
+ };
18
+ const invert = (obj) => {
19
+ if (!isObject(obj)) {
20
+ throw new Error('Invalid input: the input must be an object.');
21
+ }
22
+ const inverted = {};
23
+ for (const [key, value] of Object.entries(obj)) {
24
+ if (typeof value !== 'string' && typeof value !== 'number') {
25
+ throw new Error('Invalid value type: the value must be a string or a number.');
26
+ }
27
+ inverted[value] = key;
28
+ }
29
+ return inverted;
30
+ };
31
+ const modifyKeys = (obj, callback, ignoreDuplicates = true) => {
32
+ if (!isPlainObject(obj))
33
+ throw new TypeError(`Invalid type of ${obj === null || obj === void 0 ? void 0 : obj.constructor.name}. Expected JavaScript object`);
34
+ const entries = Object.entries(obj || {});
35
+ const result = {};
36
+ entries.forEach(([key, value]) => {
37
+ const newKey = callback(key, value);
38
+ if (!result.hasOwnProperty(newKey) || !ignoreDuplicates) {
39
+ result[newKey] = value;
40
+ }
41
+ });
42
+ return result;
43
+ };
44
+ exports.default = { isObject, isPlainObject, merge, invert, modifyKeys };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "mielk-fn",
3
+ "version": "1.0.0",
4
+ "description": "Set of helpful functions",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/mielk/mielk-fn.git"
13
+ },
14
+ "author": "Tomasz Mielniczek",
15
+ "license": "ISC",
16
+ "bugs": {
17
+ "url": "https://github.com/mielk/mielk-fn/issues"
18
+ },
19
+ "homepage": "https://github.com/mielk/mielk-fn#readme",
20
+ "devDependencies": {
21
+ "@babel/cli": "^7.21.5",
22
+ "@babel/core": "^7.21.8",
23
+ "@babel/node": "^7.20.7",
24
+ "@babel/preset-env": "^7.21.5",
25
+ "@types/jest": "^29.5.1",
26
+ "@types/node": "^20.1.2",
27
+ "babel-jest": "^29.5.0",
28
+ "jest": "^29.5.0",
29
+ "jest-html-reporters": "^3.1.4",
30
+ "ts-jest": "^29.1.0",
31
+ "typescript": "^5.0.4"
32
+ },
33
+ "jest": {
34
+ "transform": {
35
+ "^.+\\.(t|j)sx?$": "ts-jest"
36
+ },
37
+ "moduleFileExtensions": [
38
+ "ts",
39
+ "tsx",
40
+ "js",
41
+ "jsx",
42
+ "json",
43
+ "node"
44
+ ],
45
+ "globals": {
46
+ "ts-jest": {
47
+ "tsconfig": "tsconfig.json"
48
+ }
49
+ },
50
+ "reporters": [
51
+ "default",
52
+ [
53
+ "jest-html-reporters",
54
+ {
55
+ "publicPath": "./reports/html-report",
56
+ "filename": "report.html",
57
+ "pageTitle": "My Project - Test Report",
58
+ "expand": true,
59
+ "openReport": true,
60
+ "groupBy": [
61
+ "describe"
62
+ ]
63
+ }
64
+ ]
65
+ ]
66
+ }
67
+ }
package/src/arrays.ts ADDED
@@ -0,0 +1,38 @@
1
+ type NumberFunction = (item: any) => number;
2
+ type StringNumberFunction = (item: any) => string | number;
3
+ type AnyFunction = (item: any) => any;
4
+
5
+ const toMap = (
6
+ items: any[],
7
+ keyCallback: StringNumberFunction,
8
+ valueFn: AnyFunction = (item) => item,
9
+ ignoreDuplicates = true
10
+ ) => {
11
+ const map = new Map();
12
+ items.forEach((item) => {
13
+ const key = keyCallback(item);
14
+ const value = valueFn ? valueFn(item) : item;
15
+ if (ignoreDuplicates && map.has(key)) {
16
+ } else {
17
+ map.set(key, value);
18
+ }
19
+ });
20
+ return map;
21
+ };
22
+
23
+ const toIndexedArray = (items: any[], callback: NumberFunction): any[] => {
24
+ const arr: any[] = [];
25
+ items.forEach((item) => {
26
+ // Check if item is an object and has a function named callback
27
+ if (typeof item === 'object' && item !== null) {
28
+ const index = callback(item);
29
+ if (typeof index !== 'number') {
30
+ throw new TypeError('Callback should return a number.');
31
+ }
32
+ arr[index] = item;
33
+ }
34
+ });
35
+ return arr;
36
+ };
37
+
38
+ export default { toMap, toIndexedArray };
package/src/objects.ts ADDED
@@ -0,0 +1,57 @@
1
+ import { isDate } from 'util/types';
2
+
3
+ type AnyObject = { [key: string]: any };
4
+ type NumberStringFunction = (key: string, item: any) => number | string;
5
+
6
+ const isObject = (value: unknown) => typeof value === 'object' && !Array.isArray(value) && value !== null;
7
+
8
+ const isPlainObject = (value: unknown) => value?.constructor.name === 'Object';
9
+
10
+ const merge = (objects: AnyObject[], override: boolean = false): AnyObject => {
11
+ const merged: AnyObject = {};
12
+ objects.forEach((obj) => {
13
+ if (isObject(obj)) {
14
+ const entries = Object.entries(obj);
15
+ entries.forEach(([key, value]) => {
16
+ if (!merged[key] || override) merged[key] = value;
17
+ });
18
+ }
19
+ });
20
+ return merged;
21
+ };
22
+
23
+ const invert = (
24
+ obj: Record<string | number, string | number>
25
+ ): Record<string | number, string | number> => {
26
+ if (!isObject(obj)) {
27
+ throw new Error('Invalid input: the input must be an object.');
28
+ }
29
+
30
+ const inverted: Record<string | number, string | number> = {};
31
+
32
+ for (const [key, value] of Object.entries(obj)) {
33
+ if (typeof value !== 'string' && typeof value !== 'number') {
34
+ throw new Error('Invalid value type: the value must be a string or a number.');
35
+ }
36
+
37
+ inverted[value] = key;
38
+ }
39
+
40
+ return inverted;
41
+ };
42
+
43
+ const modifyKeys = (obj: AnyObject, callback: NumberStringFunction, ignoreDuplicates = true) => {
44
+ if (!isPlainObject(obj))
45
+ throw new TypeError(`Invalid type of ${obj?.constructor.name}. Expected JavaScript object`);
46
+ const entries = Object.entries(obj || {});
47
+ const result: AnyObject = {};
48
+ entries.forEach(([key, value]) => {
49
+ const newKey: string | number = callback(key, value);
50
+ if (!result.hasOwnProperty(newKey) || !ignoreDuplicates) {
51
+ result[newKey] = value;
52
+ }
53
+ });
54
+ return result;
55
+ };
56
+
57
+ export default { isObject, isPlainObject, merge, invert, modifyKeys };
@@ -0,0 +1,118 @@
1
+ import arrays from '../src/arrays';
2
+
3
+ /**
4
+ * Unit tests for toMap function
5
+ */
6
+ describe('toMap', () => {
7
+ const { toMap } = arrays;
8
+ const objects = [
9
+ { name: 'Adam', id: 1 },
10
+ { name: 'Bartek', id: 4 },
11
+ { name: 'Czesiek', id: 5 },
12
+ ];
13
+ const primitives = ['Adam', 'Bartek', 'Czesiek'];
14
+
15
+ it('should create a map from an array of objects', () => {
16
+ const map = toMap(objects, (obj) => obj.id);
17
+ expect(map.size).toBe(3);
18
+ expect(map.get(1)).toEqual(objects[0]);
19
+ expect(map.get(4)).toEqual(objects[1]);
20
+ expect(map.get(5)).toEqual(objects[2]);
21
+ });
22
+
23
+ it('should create a map from an array of primitives', () => {
24
+ const map = toMap(primitives, (str) => str.charAt(0));
25
+ expect(map.size).toBe(3);
26
+ expect(map.get('A')).toEqual(primitives[0]);
27
+ expect(map.get('B')).toEqual(primitives[1]);
28
+ expect(map.get('C')).toEqual(primitives[2]);
29
+ });
30
+
31
+ it('should allow custom value callback', () => {
32
+ const map = toMap(
33
+ objects,
34
+ (obj) => obj.id,
35
+ (obj) => obj.name
36
+ );
37
+ expect(map.size).toBe(3);
38
+ expect(map.get(1)).toBe('Adam');
39
+ expect(map.get(4)).toBe('Bartek');
40
+ expect(map.get(5)).toBe('Czesiek');
41
+ });
42
+
43
+ it('should ignore duplicate keys by default', () => {
44
+ const objectsWithDuplicate = [
45
+ { name: 'Adam', id: 1 },
46
+ { name: 'Bartek', id: 4 },
47
+ { name: 'Czesiek', id: 4 },
48
+ ];
49
+ const map = toMap(objectsWithDuplicate, (obj) => obj.id);
50
+ expect(map.size).toBe(2);
51
+ expect(map.get(1)).toEqual(objectsWithDuplicate[0]);
52
+ expect(map.get(4)).toEqual(objectsWithDuplicate[1]);
53
+ });
54
+ });
55
+
56
+ describe('toIndexedArray', () => {
57
+ const { toIndexedArray } = arrays;
58
+ it('should return an indexed array with basic objects', () => {
59
+ const items = [
60
+ { name: 'Adam', id: 1 },
61
+ { name: 'Bartek', id: 4 },
62
+ { name: 'Czesiek', id: 5 },
63
+ ];
64
+
65
+ const callback = (item: any) => item.id;
66
+ const result = toIndexedArray(items, callback);
67
+
68
+ expect(result[1]).toEqual({ name: 'Adam', id: 1 });
69
+ expect(result[4]).toEqual({ name: 'Bartek', id: 4 });
70
+ expect(result[5]).toEqual({ name: 'Czesiek', id: 5 });
71
+ });
72
+
73
+ it('should handle custom class instances', () => {
74
+ class Person {
75
+ fullName: string;
76
+ id: number;
77
+
78
+ constructor(fullName: string, id: number) {
79
+ this.fullName = fullName;
80
+ this.id = id;
81
+ }
82
+ }
83
+
84
+ const items = [new Person('Adam', 1), new Person('Bartek', 4), new Person('Czesiek', 5)];
85
+
86
+ const callback = (item: unknown) => {
87
+ if (typeof item === 'object' && item !== null && 'id' in item) {
88
+ return (item as Person).id;
89
+ }
90
+ return -1;
91
+ };
92
+ const result = toIndexedArray(items, callback);
93
+
94
+ expect(result[1]).toEqual(new Person('Adam', 1));
95
+ expect(result[4]).toEqual(new Person('Bartek', 4));
96
+ expect(result[5]).toEqual(new Person('Czesiek', 5));
97
+ });
98
+
99
+ it('should throw an error when the callback returns a non-number value', () => {
100
+ const items = [
101
+ { name: 'Adam', id: '1' },
102
+ { name: 'Bartek', id: '4' },
103
+ { name: 'Czesiek', id: '5' },
104
+ ];
105
+
106
+ const callback = (item: any) => item.id;
107
+ expect(() => toIndexedArray(items, callback)).toThrow(
108
+ new TypeError('Callback should return a number.')
109
+ );
110
+ });
111
+
112
+ it('should handle an empty array', () => {
113
+ const items: any[] = [];
114
+ const callback = (item: any) => item.id;
115
+ const result = toIndexedArray(items, callback);
116
+ expect(result).toEqual([]);
117
+ });
118
+ });
@@ -0,0 +1,259 @@
1
+ import objects from '../src/objects';
2
+
3
+ describe('isObject', () => {
4
+ const isObject = objects.isObject;
5
+ test('returns true for non-empty object', () => {
6
+ const obj = { value: 123 };
7
+ expect(isObject(obj)).toEqual(true);
8
+ });
9
+
10
+ test('returns true for empty object', () => {
11
+ expect(isObject({})).toEqual(true);
12
+ });
13
+ test('should return true for an object', () => {
14
+ const obj = { key: 'value' };
15
+ expect(isObject(obj)).toBe(true);
16
+ });
17
+
18
+ test('should return false for an array', () => {
19
+ const arr = [1, 2, 3];
20
+ expect(isObject(arr)).toBe(false);
21
+ });
22
+
23
+ test('should return false for null', () => {
24
+ expect(isObject(null)).toBe(false);
25
+ });
26
+
27
+ test('should return false for undefined', () => {
28
+ expect(isObject(undefined)).toBe(false);
29
+ });
30
+
31
+ test('should return false for a string', () => {
32
+ expect(isObject('string')).toBe(false);
33
+ });
34
+
35
+ test('should return false for a number', () => {
36
+ expect(isObject(42)).toBe(false);
37
+ });
38
+
39
+ test('should return false for a boolean', () => {
40
+ expect(isObject(true)).toBe(false);
41
+ expect(isObject(false)).toBe(false);
42
+ });
43
+
44
+ test('should return false for a function', () => {
45
+ const func = () => {};
46
+ expect(isObject(func)).toBe(false);
47
+ });
48
+ });
49
+
50
+ describe('isPlainObject', () => {
51
+ const { isPlainObject } = objects;
52
+ it('should return true for plain JavaScript objects', () => {
53
+ expect(isPlainObject({})).toBe(true);
54
+ expect(isPlainObject({ key: 'value' })).toBe(true);
55
+ });
56
+
57
+ it('should return false for non-plain JavaScript objects', () => {
58
+ expect(isPlainObject([])).toBe(false);
59
+ expect(isPlainObject(new Date())).toBe(false);
60
+ expect(isPlainObject(null)).toBe(false);
61
+ expect(isPlainObject(undefined)).toBe(false);
62
+ expect(isPlainObject(123)).toBe(false);
63
+ expect(isPlainObject('string')).toBe(false);
64
+ expect(isPlainObject(true)).toBe(false);
65
+ expect(isPlainObject(() => {})).toBe(false);
66
+ class CustomClass {}
67
+ expect(isPlainObject(new CustomClass())).toBe(false);
68
+ });
69
+ });
70
+
71
+ describe('merge', () => {
72
+ const merge = objects.merge;
73
+ test('Empty array', () => {
74
+ const result = merge([]);
75
+ expect(result).toEqual({});
76
+ });
77
+
78
+ it('Array with non-objects', () => {
79
+ const input = ['string1', 42, true] as unknown as Array<object>;
80
+ const result = merge(input);
81
+ expect(result).toEqual({});
82
+ });
83
+
84
+ it('Array with objects and non-objects', () => {
85
+ const obj1 = { key1: 'value1' };
86
+ const obj2 = { key2: 'value2' };
87
+ const input = [obj1, 'string1', 42, obj2, true] as unknown as Array<object>;
88
+ const result = merge(input);
89
+ expect(result).toEqual({ key1: 'value1', key2: 'value2' });
90
+ });
91
+
92
+ test('Array with empty objects', () => {
93
+ const result = merge([{}, {}, {}]);
94
+ expect(result).toEqual({});
95
+ });
96
+
97
+ test('Array with objects without duplicated properties', () => {
98
+ const result = merge([{ a: 1 }, { b: 2 }, { c: 3 }]);
99
+ expect(result).toEqual({ a: 1, b: 2, c: 3 });
100
+ });
101
+
102
+ test('Array with objects with duplicated properties and override=false', () => {
103
+ const result = merge([{ a: 1 }, { a: 2 }, { a: 3 }], false);
104
+ expect(result).toEqual({ a: 1 });
105
+ });
106
+
107
+ test('Array with objects with duplicated properties and override=true', () => {
108
+ const result = merge([{ a: 1 }, { a: 2 }, { a: 3 }], true);
109
+ expect(result).toEqual({ a: 3 });
110
+ });
111
+ });
112
+
113
+ describe('invert', () => {
114
+ const invert = objects.invert;
115
+ it('Basic case', () => {
116
+ const input = { key1: 'value1', key2: 'value2' };
117
+ const result = invert(input);
118
+ expect(result).toEqual({ value1: 'key1', value2: 'key2' });
119
+ });
120
+
121
+ it('Number keys and values', () => {
122
+ const input = { 1: 2, 3: 4 };
123
+ const result = invert(input);
124
+ expect(result).toEqual({ 2: '1', 4: '3' });
125
+ });
126
+
127
+ it('Mixed keys and values', () => {
128
+ const input = { key1: 1, 2: 'value2' };
129
+ const result = invert(input);
130
+ expect(result).toEqual({ 1: 'key1', value2: '2' });
131
+ });
132
+
133
+ it('Empty object', () => {
134
+ const input = {};
135
+ const result = invert(input);
136
+ expect(result).toEqual({});
137
+ });
138
+
139
+ it('Non-object input', () => {
140
+ const input = 'string' as unknown as Record<string | number, string | number>;
141
+ expect(() => invert(input)).toThrowError('Invalid input: the input must be an object.');
142
+ });
143
+
144
+ it('Invalid value type', () => {
145
+ const input = { key1: true } as unknown as Record<string | number, string | number>;
146
+ expect(() => invert(input)).toThrowError(
147
+ 'Invalid value type: the value must be a string or a number.'
148
+ );
149
+ });
150
+ });
151
+
152
+ describe('modifyKeys function', () => {
153
+ const { modifyKeys } = objects;
154
+ type NumberStringFunction = (key: number | string) => number | string;
155
+ describe('modifyKeys', () => {
156
+ it('should modify the keys of the object', () => {
157
+ const input = { id: 1, name: 'John' };
158
+ const callback: NumberStringFunction = (key) => ('' + key).toUpperCase();
159
+ const result = modifyKeys(input, callback);
160
+ expect(result).toEqual({ ID: 1, NAME: 'John' });
161
+ });
162
+
163
+ it('should handle an empty object', () => {
164
+ const input = {};
165
+ const callback: NumberStringFunction = (key) => ('' + key).toUpperCase();
166
+ const result = modifyKeys(input, callback);
167
+ expect(result).toEqual({});
168
+ });
169
+
170
+ it('should handle an object with non-string keys', () => {
171
+ const input = { 1: 'one', 2: 'two', 3: 'three' };
172
+ const callback: NumberStringFunction = (key) => key + '_new';
173
+ const result = modifyKeys(input, callback);
174
+ expect(result).toEqual({ '1_new': 'one', '2_new': 'two', '3_new': 'three' });
175
+ });
176
+
177
+ it('should modify the keys based on the callback function', () => {
178
+ const input = { id: 1, name: 'John', age: 30 };
179
+ const callback: NumberStringFunction = (key) => key + '_new';
180
+ const result = modifyKeys(input, callback);
181
+ expect(result).toEqual({ id_new: 1, name_new: 'John', age_new: 30 });
182
+ });
183
+
184
+ it('should not modify the original object', () => {
185
+ const input = { id: 1, name: 'John' };
186
+ const callback: NumberStringFunction = (key) => ('' + key).toUpperCase();
187
+ const result = modifyKeys(input, callback);
188
+ expect(result).toEqual({ ID: 1, NAME: 'John' });
189
+ expect(input).toEqual({ id: 1, name: 'John' });
190
+ });
191
+ it('should modify the keys of an object', () => {
192
+ const obj = { a: 1, b: 2, c: 3 };
193
+ const callback: NumberStringFunction = (key) => ('' + key).toUpperCase();
194
+ const result = modifyKeys(obj, callback);
195
+ expect(result).toEqual({ A: 1, B: 2, C: 3 });
196
+ });
197
+
198
+ it('should handle an empty object', () => {
199
+ const obj = {};
200
+ const callback: NumberStringFunction = (key) => ('' + key).toUpperCase();
201
+ const result = modifyKeys(obj, callback);
202
+ expect(result).toEqual({});
203
+ });
204
+
205
+ it('should throw an error if the second argument is not a function', () => {
206
+ const obj = { a: 1, b: 2, c: 3 };
207
+ const callback = 'not a function';
208
+ expect(() => modifyKeys(obj, callback as unknown as NumberStringFunction)).toThrow(TypeError);
209
+ });
210
+
211
+ it('should handle an object with duplicate modified keys', () => {
212
+ const obj = { a: 1, b: 2, c: 3 };
213
+ const callback: NumberStringFunction = (key) => 'new_key';
214
+ const result = modifyKeys(obj, callback, true);
215
+ expect(result).toEqual({ new_key: 1 });
216
+ });
217
+
218
+ it('should handle an object with duplicate modified keys if ignoreDuplicates is false', () => {
219
+ const obj = { a: 1, b: 2, c: 3 };
220
+ const callback: NumberStringFunction = (key) => 'new_key';
221
+ const result = modifyKeys(obj, callback, false);
222
+ expect(result).toEqual({ new_key: 3 });
223
+ });
224
+
225
+ it('should throw an error in strict mode if given a non-object value', () => {
226
+ 'use strict';
227
+ const callback: NumberStringFunction = (key: number | string) => 'new_key';
228
+ const fn = () => {};
229
+ expect(() => modifyKeys(undefined as any, callback)).toThrow(
230
+ new TypeError('Invalid type of undefined. Expected JavaScript object')
231
+ );
232
+ expect(() => modifyKeys(123 as any, callback)).toThrow(
233
+ new TypeError('Invalid type of Number. Expected JavaScript object')
234
+ );
235
+ expect(() => modifyKeys('string' as any, callback)).toThrow(
236
+ new TypeError('Invalid type of String. Expected JavaScript object')
237
+ );
238
+ expect(() => modifyKeys(Symbol() as any, callback)).toThrow(
239
+ new TypeError('Invalid type of Symbol. Expected JavaScript object')
240
+ );
241
+ expect(() => modifyKeys(true as any, callback)).toThrow(
242
+ new TypeError('Invalid type of Boolean. Expected JavaScript object')
243
+ );
244
+ expect(() => modifyKeys(fn as any, callback)).toThrow(
245
+ new TypeError('Invalid type of Function. Expected JavaScript object')
246
+ );
247
+ expect(() => modifyKeys([] as any, callback)).toThrow(
248
+ new TypeError('Invalid type of Array. Expected JavaScript object')
249
+ );
250
+ expect(() => modifyKeys(new Date() as any, callback)).toThrow(
251
+ new TypeError(`Invalid type of Date. Expected JavaScript object`)
252
+ );
253
+ class MyClass {}
254
+ expect(() => modifyKeys(new MyClass() as any, callback)).toThrow(
255
+ new TypeError(`Invalid type of MyClass. Expected JavaScript object`)
256
+ );
257
+ });
258
+ });
259
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "ES6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
+
27
+ /* Modules */
28
+ "module": "commonjs" /* Specify what module code is generated. */,
29
+ // "rootDir": "./", /* Specify the root folder within your source files. */
30
+ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
31
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38
+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
39
+ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
40
+ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
41
+ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42
+ // "resolveJsonModule": true, /* Enable importing .json files. */
43
+ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
44
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
45
+
46
+ /* JavaScript Support */
47
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
48
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
49
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
50
+
51
+ /* Emit */
52
+ "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
53
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
54
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
55
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
56
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
57
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
58
+ "outDir": "lib" /* Specify an output folder for all emitted files. */,
59
+ // "removeComments": true, /* Disable emitting comments. */
60
+ // "noEmit": true, /* Disable emitting files from a compilation. */
61
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
62
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
63
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
64
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
65
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
66
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
67
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
68
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
69
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
70
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
71
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
72
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
73
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
74
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
75
+
76
+ /* Interop Constraints */
77
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
78
+ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
79
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
80
+ "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
81
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
82
+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
83
+
84
+ /* Type Checking */
85
+ "strict": true /* Enable all strict type-checking options. */,
86
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
87
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
88
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
89
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
90
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
91
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
92
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
93
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
94
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
95
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
96
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
97
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
98
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
99
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
100
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
101
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
102
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
103
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
104
+
105
+ /* Completeness */
106
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
108
+ },
109
+ "include": ["src/**/*"]
110
+ }