prototype-helper 0.2.5 → 0.3.2

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.
Files changed (51) hide show
  1. package/.vscode/settings.json +6 -6
  2. package/LICENSE +21 -21
  3. package/README.md +206 -206
  4. package/dist/extension/array.d.ts +1 -0
  5. package/dist/extension/array.js +98 -84
  6. package/dist/extension/array.js.map +1 -1
  7. package/dist/extension/index.d.ts +4 -3
  8. package/dist/extension/index.js +6 -5
  9. package/dist/extension/index.js.map +1 -1
  10. package/dist/extension/number.d.ts +1 -1
  11. package/dist/extension/number.js +63 -63
  12. package/dist/extension/number.js.map +1 -1
  13. package/dist/extension/number.test.d.ts +3 -3
  14. package/dist/extension/number.test.js +21 -21
  15. package/dist/extension/object.d.ts +1 -4
  16. package/dist/extension/object.js +12 -12
  17. package/dist/extension/object.js.map +1 -1
  18. package/dist/extension/string.d.ts +18 -16
  19. package/dist/extension/string.js +38 -38
  20. package/dist/extension/string.js.map +1 -1
  21. package/dist/extension/string.test.d.ts +2 -2
  22. package/dist/extension/string.test.js +17 -17
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.js +5 -5
  25. package/dist/interface/array.d.ts +19 -17
  26. package/dist/interface/array.js +1 -1
  27. package/dist/interface/index.d.ts +3 -2
  28. package/dist/interface/index.js +5 -4
  29. package/dist/interface/index.js.map +1 -1
  30. package/dist/interface/number.d.ts +17 -17
  31. package/dist/interface/number.js +1 -1
  32. package/dist/interface/object.d.ts +4 -0
  33. package/dist/interface/object.js +2 -0
  34. package/dist/interface/object.js.map +1 -0
  35. package/dist/override/console.d.ts +17 -0
  36. package/dist/override/console.js +70 -73
  37. package/dist/override/console.js.map +1 -1
  38. package/dist/override/index.d.ts +3 -3
  39. package/dist/override/index.js +5 -5
  40. package/dist/override/linq.d.ts +1 -1
  41. package/dist/override/linq.js +2 -2
  42. package/dist/override/math.d.ts +10 -10
  43. package/dist/override/math.js +38 -38
  44. package/dist/test.d.ts +1 -1
  45. package/dist/test.js +98 -86
  46. package/dist/test.js.map +1 -1
  47. package/package.json +79 -78
  48. package/tsconfig.json +32 -32
  49. package/dist/utils/deepCopy.d.ts +0 -2
  50. package/dist/utils/deepCopy.js +0 -14
  51. package/dist/utils/deepCopy.js.map +0 -1
@@ -1,7 +1,7 @@
1
- {
2
- "editor.quickSuggestions": {
3
- "other": true,
4
- "comments": true,
5
- "strings": true
6
- }
1
+ {
2
+ "editor.quickSuggestions": {
3
+ "other": true,
4
+ "comments": true,
5
+ "strings": true
6
+ }
7
7
  }
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 ksPr
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) 2020 ksPr
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,206 +1,206 @@
1
- <img src="https://capsule-render.vercel.app/api?type=waving&color=343a40&height=210&section=header&text=Typescript Prototype Helper&fontSize=50&fontAlignY=35&fontColor=adb5bd" />
2
- <!-- <h1 align="center">Typescript Prototype Helper</h1> -->
3
-
4
- <p align="center">
5
- <a href="https://github.com/prettier/prettier">
6
- <img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge">
7
- </a>
8
- <a href="https://www.npmjs.com/package/prototype-helper">
9
- <img alt="code style: prettier" src="https://img.shields.io/npm/v/prototype-helper.svg?style=for-the-badge">
10
- </a>
11
- <a href="https://github.com/k22pr/prototype-helper/blob/master/LICENSE">
12
- <img alt="code style: prettier" src="https://img.shields.io/github/license/mashape/apistatus.svg?style=for-the-badge">
13
- </a>
14
- <img alt="npm" src="https://img.shields.io/npm/dm/prototype-helper?style=for-the-badge">
15
- <!-- <img alt="AppVeyor tests (compact)" src="https://img.shields.io/appveyor/tests/k22pr/prototype-helper?compact_message&style=for-the-badge"> -->
16
-
17
- </p>
18
- <p align="center">
19
- Adds a convenient prototype function package.
20
- </p>
21
-
22
- # Getting started
23
-
24
- Import the package to the first file you call.
25
-
26
- ```js
27
- import "prototype-helper";
28
-
29
- // and use
30
- console.log("10000".toComma()); // 10,000
31
- ```
32
-
33
- # Prototype Helper
34
-
35
- ## Number
36
-
37
- ### toComma()
38
-
39
- It is a function that attaches a three-digit comma.
40
-
41
- ```ts
42
- let test = 123;
43
- test.toComma(); // "123"
44
- test = 123456;
45
- test.toComma(); // "123,456"
46
- //
47
- ```
48
-
49
- ### ampersand()
50
-
51
- Ampsand that safely handles floating point errors.
52
-
53
- ```ts
54
- console.log(35 % 0.8); // 0.5999999999999981
55
- console.log((35).ampersand(0.8)); // 0.6
56
-
57
- console.log(39225.3 % 0.01); // 2.0938424605265737e-12
58
- console.log((39225.3).ampersand(0.01)); // 0
59
- ```
60
-
61
- ### safeAdd()
62
-
63
- Addition to safely handling floating point errors.
64
-
65
- Calculate only up to 15 decimal places.
66
-
67
- ```ts
68
- console.log(0.1 + 0.2); // 0.30000000000000004
69
- console.log((0.1).safeAdd(0.2)); // 0.3
70
- ```
71
-
72
- ### safeSubtract()
73
-
74
- Subtraction that safely handles floating point errors.
75
-
76
- Calculate only up to 15 decimal places.
77
-
78
- ```ts
79
- console.log(0.1 - 0.3); // -0.19999999999999998
80
- console.log((0.1).safeSubtract(0.3)); // 0.2
81
- ```
82
-
83
- ### safeDivision()
84
-
85
- Division that safely handles floating point errors.
86
-
87
- Calculate only up to 15 decimal places.
88
-
89
- ```ts
90
- console.log(0.2 / 0.6); // 0.33333333333333337
91
- console.log((0.2).safeDivision(0.6)); // 0.3333333333333333
92
- ```
93
-
94
- ### safeMultiply()
95
-
96
- Division that safely handles floating point errors.
97
-
98
- Calculate only up to 15 decimal places.
99
-
100
- ```ts
101
- console.log(0.1 * 0.2); // 0.020000000000000004
102
- console.log((0.1).safeMultiply(0.2)); // 0.02
103
- ```
104
-
105
- ### fixNumber()
106
-
107
- Fix the number of digits to be marked.
108
-
109
- ```ts
110
- console.log("30222.50380000".fixPoint(5)); // 30222.50380
111
- console.log((30222).fixPoint(3)); // 30222.000
112
- console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000
113
- ```
114
-
115
- ### fixPoint()
116
-
117
- Fix the decimal place to be marked.
118
-
119
- ```ts
120
- console.log("30222.50380000".fixPoint(5)); // 30222.50380
121
- console.log((30222).fixPoint(3)); // 30222.000
122
- console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000
123
- ```
124
-
125
- ---
126
-
127
- ## String
128
-
129
- ### toComma()
130
-
131
- It is a function that attaches a three-digit comma.
132
-
133
- ```ts
134
- let test = "123";
135
- test.toComma(); // "123"
136
- test = "123456";
137
- test.toComma(); // "123,456"
138
- //
139
- ```
140
-
141
- ### fixNumber()
142
-
143
- Fix the number of digits to be marked.
144
-
145
- ```ts
146
- console.log("30222".fixPoint(5)); // 30222
147
- console.log("30222".fixPoint(5)); // 30222
148
- ```
149
-
150
- ### fixPoint()
151
-
152
- Fix the decimal place to be marked.
153
-
154
- ```ts
155
- console.log("30222.50380000".fixPoint(5)); // 30222.50380
156
- console.log((30222).fixPoint(3)); // 30222.000
157
- console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000
158
- console.log("30222.50380000".fixPoint(8).fixNumber(8)); // 00030222.50380000
159
- ```
160
-
161
- ## Object
162
-
163
- ## Array
164
-
165
- ---
166
-
167
- # Extention Helper
168
-
169
- ## Math
170
-
171
- ### round10(x: number, point?: number)
172
-
173
- ### floor10(x: number, point?: number)
174
-
175
- ### ceil10(x: number, point?: number)
176
-
177
- A function that allows you to use decimal points for discarding/rounding/round.
178
-
179
- I used the code of the MDN below.
180
-
181
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil#decimal_adjustment
182
-
183
- ```ts
184
- console.log(Math.round10(112.5345, 3)); //112.535
185
- console.log(Math.floor10(112.5345, 3)); //112.534
186
- console.log(Math.ceil10(112.5345, 3)); //112.535
187
- ```
188
-
189
- ### randomRange(a: number, b: number, point?: number)
190
-
191
- Create random numbers within that range.
192
-
193
- (Includes maximum and minimum values.)
194
-
195
- ```ts
196
- console.log(Math.randomRange(112.5, 200, 1)); //135.1
197
- console.log(Math.randomRange(0, 200)); //169
198
- ```
199
-
200
- ### clamp(input: number, min: number, max: number)
201
-
202
- ```ts
203
- console.log(Math.clamp(10, 3, 5)); // 5
204
- console.log(Math.clamp(1, 3, 5)); // 3
205
- console.log(Math.clamp(4, 3, 5)); // 4
206
- ```
1
+ <img src="https://capsule-render.vercel.app/api?type=waving&color=343a40&height=210&section=header&text=Typescript Prototype Helper&fontSize=50&fontAlignY=35&fontColor=adb5bd" />
2
+ <!-- <h1 align="center">Typescript Prototype Helper</h1> -->
3
+
4
+ <p align="center">
5
+ <a href="https://github.com/prettier/prettier">
6
+ <img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge">
7
+ </a>
8
+ <a href="https://www.npmjs.com/package/prototype-helper">
9
+ <img alt="code style: prettier" src="https://img.shields.io/npm/v/prototype-helper.svg?style=for-the-badge">
10
+ </a>
11
+ <a href="https://github.com/k22pr/prototype-helper/blob/master/LICENSE">
12
+ <img alt="code style: prettier" src="https://img.shields.io/github/license/mashape/apistatus.svg?style=for-the-badge">
13
+ </a>
14
+ <img alt="npm" src="https://img.shields.io/npm/dm/prototype-helper?style=for-the-badge">
15
+ <!-- <img alt="AppVeyor tests (compact)" src="https://img.shields.io/appveyor/tests/k22pr/prototype-helper?compact_message&style=for-the-badge"> -->
16
+
17
+ </p>
18
+ <p align="center">
19
+ Adds a convenient prototype function package.
20
+ </p>
21
+
22
+ # Getting started
23
+
24
+ Import the package to the first file you call.
25
+
26
+ ```js
27
+ import "prototype-helper";
28
+
29
+ // and use
30
+ console.log("10000".toComma()); // 10,000
31
+ ```
32
+
33
+ # Prototype Helper
34
+
35
+ ## Number
36
+
37
+ ### toComma()
38
+
39
+ It is a function that attaches a three-digit comma.
40
+
41
+ ```ts
42
+ let test = 123;
43
+ test.toComma(); // "123"
44
+ test = 123456;
45
+ test.toComma(); // "123,456"
46
+ //
47
+ ```
48
+
49
+ ### ampersand()
50
+
51
+ Ampsand that safely handles floating point errors.
52
+
53
+ ```ts
54
+ console.log(35 % 0.8); // 0.5999999999999981
55
+ console.log((35).ampersand(0.8)); // 0.6
56
+
57
+ console.log(39225.3 % 0.01); // 2.0938424605265737e-12
58
+ console.log((39225.3).ampersand(0.01)); // 0
59
+ ```
60
+
61
+ ### safeAdd()
62
+
63
+ Addition to safely handling floating point errors.
64
+
65
+ Calculate only up to 15 decimal places.
66
+
67
+ ```ts
68
+ console.log(0.1 + 0.2); // 0.30000000000000004
69
+ console.log((0.1).safeAdd(0.2)); // 0.3
70
+ ```
71
+
72
+ ### safeSubtract()
73
+
74
+ Subtraction that safely handles floating point errors.
75
+
76
+ Calculate only up to 15 decimal places.
77
+
78
+ ```ts
79
+ console.log(0.1 - 0.3); // -0.19999999999999998
80
+ console.log((0.1).safeSubtract(0.3)); // 0.2
81
+ ```
82
+
83
+ ### safeDivision()
84
+
85
+ Division that safely handles floating point errors.
86
+
87
+ Calculate only up to 15 decimal places.
88
+
89
+ ```ts
90
+ console.log(0.2 / 0.6); // 0.33333333333333337
91
+ console.log((0.2).safeDivision(0.6)); // 0.3333333333333333
92
+ ```
93
+
94
+ ### safeMultiply()
95
+
96
+ Division that safely handles floating point errors.
97
+
98
+ Calculate only up to 15 decimal places.
99
+
100
+ ```ts
101
+ console.log(0.1 * 0.2); // 0.020000000000000004
102
+ console.log((0.1).safeMultiply(0.2)); // 0.02
103
+ ```
104
+
105
+ ### fixNumber()
106
+
107
+ Fix the number of digits to be marked.
108
+
109
+ ```ts
110
+ console.log("30222.50380000".fixPoint(5)); // 30222.50380
111
+ console.log((30222).fixPoint(3)); // 30222.000
112
+ console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000
113
+ ```
114
+
115
+ ### fixPoint()
116
+
117
+ Fix the decimal place to be marked.
118
+
119
+ ```ts
120
+ console.log("30222.50380000".fixPoint(5)); // 30222.50380
121
+ console.log((30222).fixPoint(3)); // 30222.000
122
+ console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000
123
+ ```
124
+
125
+ ---
126
+
127
+ ## String
128
+
129
+ ### toComma()
130
+
131
+ It is a function that attaches a three-digit comma.
132
+
133
+ ```ts
134
+ let test = "123";
135
+ test.toComma(); // "123"
136
+ test = "123456";
137
+ test.toComma(); // "123,456"
138
+ //
139
+ ```
140
+
141
+ ### fixNumber()
142
+
143
+ Fix the number of digits to be marked.
144
+
145
+ ```ts
146
+ console.log("30222".fixPoint(5)); // 30222
147
+ console.log("30222".fixPoint(5)); // 30222
148
+ ```
149
+
150
+ ### fixPoint()
151
+
152
+ Fix the decimal place to be marked.
153
+
154
+ ```ts
155
+ console.log("30222.50380000".fixPoint(5)); // 30222.50380
156
+ console.log((30222).fixPoint(3)); // 30222.000
157
+ console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000
158
+ console.log("30222.50380000".fixPoint(8).fixNumber(8)); // 00030222.50380000
159
+ ```
160
+
161
+ ## Object
162
+
163
+ ## Array
164
+
165
+ ---
166
+
167
+ # Extention Helper
168
+
169
+ ## Math
170
+
171
+ ### round10(x: number, point?: number)
172
+
173
+ ### floor10(x: number, point?: number)
174
+
175
+ ### ceil10(x: number, point?: number)
176
+
177
+ A function that allows you to use decimal points for discarding/rounding/round.
178
+
179
+ I used the code of the MDN below.
180
+
181
+ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil#decimal_adjustment
182
+
183
+ ```ts
184
+ console.log(Math.round10(112.5345, 3)); //112.535
185
+ console.log(Math.floor10(112.5345, 3)); //112.534
186
+ console.log(Math.ceil10(112.5345, 3)); //112.535
187
+ ```
188
+
189
+ ### randomRange(a: number, b: number, point?: number)
190
+
191
+ Create random numbers within that range.
192
+
193
+ (Includes maximum and minimum values.)
194
+
195
+ ```ts
196
+ console.log(Math.randomRange(112.5, 200, 1)); //135.1
197
+ console.log(Math.randomRange(0, 200)); //169
198
+ ```
199
+
200
+ ### clamp(input: number, min: number, max: number)
201
+
202
+ ```ts
203
+ console.log(Math.clamp(10, 3, 5)); // 5
204
+ console.log(Math.clamp(1, 3, 5)); // 3
205
+ console.log(Math.clamp(4, 3, 5)); // 4
206
+ ```
@@ -0,0 +1 @@
1
+ export {};
@@ -1,85 +1,99 @@
1
- "use strict";
2
- Array.prototype.where = function (predicate) {
3
- return this.filter(predicate);
4
- };
5
- Array.prototype.singleOrDefault = function (predicate, defaultValue = null) {
6
- const isset = this.where(predicate);
7
- if (isset.length >= 2)
8
- throw new Error("single:sequence contains more than one element.");
9
- return !isset ? defaultValue : isset[0];
10
- };
11
- Array.prototype.single = function (predicate) {
12
- const isset = this.singleOrDefault(predicate);
13
- if (!isset)
14
- throw new Error("single:No element satisfies the condition.");
15
- return isset;
16
- };
17
- Array.prototype.skip = function (count) {
18
- return this.slice(count, this.length);
19
- };
20
- Array.prototype.take = function (count) {
21
- return this.slice(0, count);
22
- };
23
- Array.prototype.select = function (element) {
24
- return this.map(element);
25
- };
26
- Array.prototype.any = function (predicate) {
27
- if (!predicate)
28
- predicate = () => true;
29
- return this.singleOrDefault(predicate) ? true : false;
30
- };
31
- Array.prototype.count = function (predicate) {
32
- if (!predicate)
33
- predicate = () => true;
34
- return this.where(predicate).length;
35
- };
36
- Array.prototype.max = function (predicate) {
37
- if (predicate == null)
38
- predicate = () => true;
39
- return this.select(predicate).reduce((a, b) => {
40
- return a > b ? a : b;
41
- });
42
- };
43
- Array.prototype.min = function (predicate) {
44
- if (predicate == null)
45
- predicate = () => true;
46
- return this.select(predicate).reduce((a, b) => {
47
- return a < b ? a : b;
48
- });
49
- };
50
- Array.prototype.sum = function (predicate) {
51
- if (predicate == null)
52
- predicate = () => true;
53
- return this.select(predicate).reduce((a, b) => {
54
- return a + b;
55
- }, 0);
56
- };
57
- Array.prototype.firstOrDefault = function (predicate, defaultValue = null) {
58
- if (predicate == null)
59
- predicate = () => true;
60
- const isset = this.where(predicate);
61
- return isset == null || isset.length == 0 ? defaultValue : isset[0];
62
- };
63
- Array.prototype.first = function (predicate, defaultValue = null) {
64
- if (predicate == null)
65
- predicate = () => true;
66
- const isset = this.firstOrDefault(predicate);
67
- if (isset == null)
68
- throw new Error("first:No element satisfies the condition.");
69
- return isset;
70
- };
71
- Array.prototype.lastOrDefault = function (predicate, defaultValue = null) {
72
- if (predicate == null)
73
- predicate = () => true;
74
- const isset = this.where(predicate);
75
- return isset == null || isset.length == 0 ? defaultValue : isset[isset.length - 1];
76
- };
77
- Array.prototype.last = function (predicate, defaultValue = null) {
78
- if (predicate == null)
79
- predicate = () => true;
80
- const isset = this.lastOrDefault(predicate);
81
- if (isset == null)
82
- throw new Error("last:No element satisfies the condition.");
83
- return isset;
84
- };
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const deep_clone_1 = __importDefault(require("deep-clone"));
7
+ Array.prototype.where = function (predicate) {
8
+ return this.filter(predicate);
9
+ };
10
+ Array.prototype.singleOrDefault = function (predicate, defaultValue = null) {
11
+ const isset = this.where(predicate);
12
+ if (isset.length >= 2)
13
+ throw new Error("single:sequence contains more than one element.");
14
+ return !isset ? defaultValue : isset[0];
15
+ };
16
+ Array.prototype.single = function (predicate) {
17
+ const isset = this.singleOrDefault(predicate);
18
+ if (!isset)
19
+ throw new Error("single:No element satisfies the condition.");
20
+ return isset;
21
+ };
22
+ Array.prototype.skip = function (count) {
23
+ return this.slice(count, this.length);
24
+ };
25
+ Array.prototype.take = function (count) {
26
+ return this.slice(0, count);
27
+ };
28
+ Array.prototype.select = function (element) {
29
+ return this.map(element);
30
+ };
31
+ Array.prototype.any = function (predicate) {
32
+ if (!predicate)
33
+ predicate = () => true;
34
+ return this.singleOrDefault(predicate) ? true : false;
35
+ };
36
+ Array.prototype.count = function (predicate) {
37
+ if (!predicate)
38
+ predicate = () => true;
39
+ return this.where(predicate).length;
40
+ };
41
+ Array.prototype.max = function (predicate) {
42
+ if (predicate == null)
43
+ predicate = () => true;
44
+ return this.select(predicate).reduce((a, b) => {
45
+ return a > b ? a : b;
46
+ });
47
+ };
48
+ Array.prototype.min = function (predicate) {
49
+ if (predicate == null)
50
+ predicate = () => true;
51
+ return this.select(predicate).reduce((a, b) => {
52
+ return a < b ? a : b;
53
+ });
54
+ };
55
+ Array.prototype.sum = function (predicate) {
56
+ if (predicate == null)
57
+ predicate = () => true;
58
+ return this.select(predicate).reduce((a, b) => {
59
+ return a + b;
60
+ }, 0);
61
+ };
62
+ Array.prototype.firstOrDefault = function (predicate, defaultValue = null) {
63
+ if (predicate == null)
64
+ predicate = () => true;
65
+ const isset = this.where(predicate);
66
+ return isset == null || isset.length == 0 ? defaultValue : isset[0];
67
+ };
68
+ Array.prototype.first = function (predicate, defaultValue = null) {
69
+ if (predicate == null)
70
+ predicate = () => true;
71
+ const isset = this.firstOrDefault(predicate);
72
+ if (isset == null)
73
+ throw new Error("first:No element satisfies the condition.");
74
+ return isset;
75
+ };
76
+ Array.prototype.lastOrDefault = function (predicate, defaultValue = null) {
77
+ if (predicate == null)
78
+ predicate = () => true;
79
+ const isset = this.where(predicate);
80
+ return isset == null || isset.length == 0 ? defaultValue : isset[isset.length - 1];
81
+ };
82
+ Array.prototype.last = function (predicate, defaultValue = null) {
83
+ if (predicate == null)
84
+ predicate = () => true;
85
+ const isset = this.lastOrDefault(predicate);
86
+ if (isset == null)
87
+ throw new Error("last:No element satisfies the condition.");
88
+ return isset;
89
+ };
90
+ // Array.prototype.deepClone = function (camelcase: boolean = false) {
91
+ // return deepClone(this, camelcase ? camelCase : undefined);
92
+ // }
93
+ Array.prototype.deepClone = function () {
94
+ return deep_clone_1.default(this);
95
+ };
96
+ Array.prototype.toJson = function () {
97
+ return JSON.stringify(this);
98
+ };
85
99
  //# sourceMappingURL=array.js.map