prototype-helper 0.3.7 → 0.3.9
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/.vscode/settings.json +6 -6
- package/LICENSE +21 -21
- package/README.md +198 -198
- package/dist/extension/array.d.ts +1 -1
- package/dist/extension/array.js +103 -103
- package/dist/extension/array.js.map +1 -1
- package/dist/extension/index.d.ts +4 -4
- package/dist/extension/index.js +6 -6
- package/dist/extension/number.d.ts +1 -1
- package/dist/extension/number.js +71 -65
- package/dist/extension/number.js.map +1 -1
- package/dist/extension/number.test.d.ts +3 -3
- package/dist/extension/number.test.js +21 -21
- package/dist/extension/object.d.ts +1 -1
- package/dist/extension/object.js +12 -16
- package/dist/extension/object.js.map +1 -1
- package/dist/extension/string.d.ts +18 -18
- package/dist/extension/string.js +38 -38
- package/dist/extension/string.test.d.ts +2 -2
- package/dist/extension/string.test.js +17 -17
- package/dist/index.d.ts +3 -3
- package/dist/index.js +5 -5
- package/dist/interface/array.d.ts +19 -19
- package/dist/interface/array.js +1 -1
- package/dist/interface/index.d.ts +3 -3
- package/dist/interface/index.js +5 -5
- package/dist/interface/number.d.ts +23 -21
- package/dist/interface/number.js +1 -1
- package/dist/interface/object.d.ts +0 -4
- package/dist/interface/object.js +5 -1
- package/dist/interface/object.js.map +1 -1
- package/dist/override/console.d.ts +17 -17
- package/dist/override/console.js +70 -70
- package/dist/override/index.d.ts +3 -3
- package/dist/override/index.js +5 -5
- package/dist/override/linq.d.ts +1 -1
- package/dist/override/linq.js +2 -2
- package/dist/override/math.d.ts +10 -10
- package/dist/override/math.js +38 -38
- package/dist/test.d.ts +1 -1
- package/dist/test.js +105 -105
- package/dist/test.js.map +1 -1
- package/dist/utils/deepCopy.d.ts +2 -0
- package/dist/utils/deepCopy.js +14 -0
- package/dist/utils/deepCopy.js.map +1 -0
- package/package.json +79 -79
- package/tsconfig.json +32 -32
package/.vscode/settings.json
CHANGED
|
@@ -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,198 +1,198 @@
|
|
|
1
|
-
<img src="https://capsule-render.vercel.app/api?type=waving&color=343a40&height=210§ion=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
|
-
### mod()
|
|
50
|
-
|
|
51
|
-
Ampsand that safely handles floating point errors.
|
|
52
|
-
|
|
53
|
-
```ts
|
|
54
|
-
console.log(35 % 0.8); // 0.5999999999999981
|
|
55
|
-
console.log((35).mod(0.8)); // 0.6
|
|
56
|
-
|
|
57
|
-
console.log(39225.3 % 0.01); // 2.0938424605265737e-12
|
|
58
|
-
console.log((39225.3).mod(0.01)); // 0
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### add()
|
|
62
|
-
|
|
63
|
-
Addition to safely handling floating point errors.
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
console.log(0.1 + 0.2); // 0.30000000000000004
|
|
67
|
-
console.log((0.1).add(0.2)); // 0.3
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### sub()
|
|
71
|
-
|
|
72
|
-
Subtraction that safely handles floating point errors.
|
|
73
|
-
|
|
74
|
-
```ts
|
|
75
|
-
console.log(0.1 - 0.3); // -0.19999999999999998
|
|
76
|
-
console.log((0.1).sub(0.3)); // 0.2
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### div()
|
|
80
|
-
|
|
81
|
-
Division that safely handles floating point errors.
|
|
82
|
-
|
|
83
|
-
```ts
|
|
84
|
-
console.log(0.2 / 0.6); // 0.33333333333333337
|
|
85
|
-
console.log((0.2).div(0.6)); // 0.3333333333333333
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### mul()
|
|
89
|
-
|
|
90
|
-
Multiply that safely handles floating point errors.
|
|
91
|
-
|
|
92
|
-
```ts
|
|
93
|
-
console.log(0.1 * 0.2); // 0.020000000000000004
|
|
94
|
-
console.log((0.1).mul(0.2)); // 0.02
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### fixNumber()
|
|
98
|
-
|
|
99
|
-
Fix the number of digits to be marked.
|
|
100
|
-
|
|
101
|
-
```ts
|
|
102
|
-
console.log("3022.50380000".fixNumber(5)); // 03022.50380000
|
|
103
|
-
console.log((3022).fixNumber(7)); // 0003022
|
|
104
|
-
console.log((3222.12).fixNumber(5).toComma()); // 03,222.12
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### fixPoint()
|
|
108
|
-
|
|
109
|
-
Fix the decimal place to be marked.
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
console.log("30222.50380000".fixPoint(5)); // 30222.50380
|
|
113
|
-
console.log((30222).fixPoint(3)); // 30222.000
|
|
114
|
-
console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
## String
|
|
120
|
-
|
|
121
|
-
### toComma()
|
|
122
|
-
|
|
123
|
-
It is a function that attaches a three-digit comma.
|
|
124
|
-
|
|
125
|
-
```ts
|
|
126
|
-
let test = "123";
|
|
127
|
-
test.toComma(); // "123"
|
|
128
|
-
test = "123456";
|
|
129
|
-
test.toComma(); // "123,456"
|
|
130
|
-
//
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### fixNumber()
|
|
134
|
-
|
|
135
|
-
Fix the number of digits to be marked.
|
|
136
|
-
|
|
137
|
-
```ts
|
|
138
|
-
console.log("3022.50380000".fixNumber(5)); // 03022.50380000
|
|
139
|
-
console.log((3022).fixNumber(7)); // 0003022
|
|
140
|
-
console.log((3222.12).fixNumber(5).toComma()); // 03,222.12
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
### fixPoint()
|
|
144
|
-
|
|
145
|
-
Fix the decimal place to be marked.
|
|
146
|
-
|
|
147
|
-
```ts
|
|
148
|
-
console.log("30222.50380000".fixPoint(5)); // 30222.50380
|
|
149
|
-
console.log((30222).fixPoint(3)); // 30222.000
|
|
150
|
-
console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
## Object
|
|
154
|
-
|
|
155
|
-
## Array
|
|
156
|
-
|
|
157
|
-
---
|
|
158
|
-
|
|
159
|
-
# Extention Helper
|
|
160
|
-
|
|
161
|
-
## Math
|
|
162
|
-
|
|
163
|
-
### round10(x: number, point?: number)
|
|
164
|
-
|
|
165
|
-
### floor10(x: number, point?: number)
|
|
166
|
-
|
|
167
|
-
### ceil10(x: number, point?: number)
|
|
168
|
-
|
|
169
|
-
A function that allows you to use decimal points for discarding/rounding/round.
|
|
170
|
-
|
|
171
|
-
I used the code of the MDN below.
|
|
172
|
-
|
|
173
|
-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil#decimal_adjustment
|
|
174
|
-
|
|
175
|
-
```ts
|
|
176
|
-
console.log(Math.round10(112.5345, 3)); //112.535
|
|
177
|
-
console.log(Math.floor10(112.5345, 3)); //112.534
|
|
178
|
-
console.log(Math.ceil10(112.5345, 3)); //112.535
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### randomRange(a: number, b: number, point?: number)
|
|
182
|
-
|
|
183
|
-
Create random numbers within that range.
|
|
184
|
-
|
|
185
|
-
(Includes maximum and minimum values.)
|
|
186
|
-
|
|
187
|
-
```ts
|
|
188
|
-
console.log(Math.randomRange(112.5, 200, 1)); //135.1
|
|
189
|
-
console.log(Math.randomRange(0, 200)); //169
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### clamp(input: number, min: number, max: number)
|
|
193
|
-
|
|
194
|
-
```ts
|
|
195
|
-
console.log(Math.clamp(10, 3, 5)); // 5
|
|
196
|
-
console.log(Math.clamp(1, 3, 5)); // 3
|
|
197
|
-
console.log(Math.clamp(4, 3, 5)); // 4
|
|
198
|
-
```
|
|
1
|
+
<img src="https://capsule-render.vercel.app/api?type=waving&color=343a40&height=210§ion=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
|
+
### mod()
|
|
50
|
+
|
|
51
|
+
Ampsand that safely handles floating point errors.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
console.log(35 % 0.8); // 0.5999999999999981
|
|
55
|
+
console.log((35).mod(0.8)); // 0.6
|
|
56
|
+
|
|
57
|
+
console.log(39225.3 % 0.01); // 2.0938424605265737e-12
|
|
58
|
+
console.log((39225.3).mod(0.01)); // 0
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### add()
|
|
62
|
+
|
|
63
|
+
Addition to safely handling floating point errors.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
console.log(0.1 + 0.2); // 0.30000000000000004
|
|
67
|
+
console.log((0.1).add(0.2)); // 0.3
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### sub()
|
|
71
|
+
|
|
72
|
+
Subtraction that safely handles floating point errors.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
console.log(0.1 - 0.3); // -0.19999999999999998
|
|
76
|
+
console.log((0.1).sub(0.3)); // 0.2
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### div()
|
|
80
|
+
|
|
81
|
+
Division that safely handles floating point errors.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
console.log(0.2 / 0.6); // 0.33333333333333337
|
|
85
|
+
console.log((0.2).div(0.6)); // 0.3333333333333333
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### mul()
|
|
89
|
+
|
|
90
|
+
Multiply that safely handles floating point errors.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
console.log(0.1 * 0.2); // 0.020000000000000004
|
|
94
|
+
console.log((0.1).mul(0.2)); // 0.02
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### fixNumber()
|
|
98
|
+
|
|
99
|
+
Fix the number of digits to be marked.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
console.log("3022.50380000".fixNumber(5)); // 03022.50380000
|
|
103
|
+
console.log((3022).fixNumber(7)); // 0003022
|
|
104
|
+
console.log((3222.12).fixNumber(5).toComma()); // 03,222.12
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### fixPoint()
|
|
108
|
+
|
|
109
|
+
Fix the decimal place to be marked.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
console.log("30222.50380000".fixPoint(5)); // 30222.50380
|
|
113
|
+
console.log((30222).fixPoint(3)); // 30222.000
|
|
114
|
+
console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## String
|
|
120
|
+
|
|
121
|
+
### toComma()
|
|
122
|
+
|
|
123
|
+
It is a function that attaches a three-digit comma.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
let test = "123";
|
|
127
|
+
test.toComma(); // "123"
|
|
128
|
+
test = "123456";
|
|
129
|
+
test.toComma(); // "123,456"
|
|
130
|
+
//
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### fixNumber()
|
|
134
|
+
|
|
135
|
+
Fix the number of digits to be marked.
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
console.log("3022.50380000".fixNumber(5)); // 03022.50380000
|
|
139
|
+
console.log((3022).fixNumber(7)); // 0003022
|
|
140
|
+
console.log((3222.12).fixNumber(5).toComma()); // 03,222.12
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### fixPoint()
|
|
144
|
+
|
|
145
|
+
Fix the decimal place to be marked.
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
console.log("30222.50380000".fixPoint(5)); // 30222.50380
|
|
149
|
+
console.log((30222).fixPoint(3)); // 30222.000
|
|
150
|
+
console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Object
|
|
154
|
+
|
|
155
|
+
## Array
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
# Extention Helper
|
|
160
|
+
|
|
161
|
+
## Math
|
|
162
|
+
|
|
163
|
+
### round10(x: number, point?: number)
|
|
164
|
+
|
|
165
|
+
### floor10(x: number, point?: number)
|
|
166
|
+
|
|
167
|
+
### ceil10(x: number, point?: number)
|
|
168
|
+
|
|
169
|
+
A function that allows you to use decimal points for discarding/rounding/round.
|
|
170
|
+
|
|
171
|
+
I used the code of the MDN below.
|
|
172
|
+
|
|
173
|
+
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil#decimal_adjustment
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
console.log(Math.round10(112.5345, 3)); //112.535
|
|
177
|
+
console.log(Math.floor10(112.5345, 3)); //112.534
|
|
178
|
+
console.log(Math.ceil10(112.5345, 3)); //112.535
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### randomRange(a: number, b: number, point?: number)
|
|
182
|
+
|
|
183
|
+
Create random numbers within that range.
|
|
184
|
+
|
|
185
|
+
(Includes maximum and minimum values.)
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
console.log(Math.randomRange(112.5, 200, 1)); //135.1
|
|
189
|
+
console.log(Math.randomRange(0, 200)); //169
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### clamp(input: number, min: number, max: number)
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
console.log(Math.clamp(10, 3, 5)); // 5
|
|
196
|
+
console.log(Math.clamp(1, 3, 5)); // 3
|
|
197
|
+
console.log(Math.clamp(4, 3, 5)); // 4
|
|
198
|
+
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/dist/extension/array.js
CHANGED
|
@@ -1,104 +1,104 @@
|
|
|
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
|
-
if (!Array.prototype._deepCopy) {
|
|
94
|
-
Array.prototype._deepCopy = function () {
|
|
95
|
-
return deep_clone_1.default(this);
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
if (!Array.prototype._toJson) {
|
|
99
|
-
Array.prototype._toJson = function () {
|
|
100
|
-
return JSON.stringify(this);
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
;
|
|
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
|
+
if (!Array.prototype._deepCopy) {
|
|
94
|
+
Array.prototype._deepCopy = function () {
|
|
95
|
+
return (0, deep_clone_1.default)(this);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (!Array.prototype._toJson) {
|
|
99
|
+
Array.prototype._toJson = function () {
|
|
100
|
+
return JSON.stringify(this);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
;
|
|
104
104
|
//# sourceMappingURL=array.js.map
|