@util.js/numbers 0.39.2 → 0.41.1
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/dist/Numbers.js +67 -33
- package/index.js +1 -0
- package/lib/Numbers.js +3 -5
- package/package.json +4 -4
- package/test/NumbersTest.js +7 -7
package/dist/Numbers.js
CHANGED
|
@@ -1,32 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _acosh = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/acosh"));
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _asinh = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/asinh"));
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _atanh = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/atanh"));
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _cbrt = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/cbrt"));
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _clz = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/clz32"));
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _cosh = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/cosh"));
|
|
16
16
|
|
|
17
|
-
var
|
|
17
|
+
var _expm = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/expm1"));
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var _fround = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/fround"));
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _hypot = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/hypot"));
|
|
22
22
|
|
|
23
|
-
var
|
|
23
|
+
var _imul = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/imul"));
|
|
24
24
|
|
|
25
|
-
var
|
|
25
|
+
var _isFinite = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/is-finite"));
|
|
26
26
|
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
var _isInteger = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/is-integer"));
|
|
28
|
+
|
|
29
|
+
var _isNan = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/is-nan"));
|
|
30
|
+
|
|
31
|
+
var _isSafeInteger = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/is-safe-integer"));
|
|
32
|
+
|
|
33
|
+
var _log = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/log10"));
|
|
34
|
+
|
|
35
|
+
var _log1p = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/log1p"));
|
|
36
|
+
|
|
37
|
+
var _log2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/log2"));
|
|
38
|
+
|
|
39
|
+
var _parseFloat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/parse-float"));
|
|
40
|
+
|
|
41
|
+
var _parseInt = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/parse-int"));
|
|
42
|
+
|
|
43
|
+
var _sign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/sign"));
|
|
44
|
+
|
|
45
|
+
var _sinh = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/sinh"));
|
|
46
|
+
|
|
47
|
+
var _tanh = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/tanh"));
|
|
48
|
+
|
|
49
|
+
var _trunc = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/math/trunc"));
|
|
50
|
+
|
|
51
|
+
var _epsilon = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/epsilon"));
|
|
52
|
+
|
|
53
|
+
var _maxSafeInteger = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/max-safe-integer"));
|
|
54
|
+
|
|
55
|
+
var _minSafeInteger = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/min-safe-integer"));
|
|
56
|
+
|
|
57
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
|
|
58
|
+
|
|
59
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
|
|
60
|
+
|
|
61
|
+
var Numbers = /*#__PURE__*/function () {
|
|
30
62
|
function Numbers() {
|
|
31
63
|
(0, _classCallCheck2["default"])(this, Numbers);
|
|
32
64
|
}
|
|
@@ -44,7 +76,7 @@ function () {
|
|
|
44
76
|
}, {
|
|
45
77
|
key: "acosh",
|
|
46
78
|
value: function acosh() {
|
|
47
|
-
return
|
|
79
|
+
return _acosh["default"].apply(Math, arguments);
|
|
48
80
|
}
|
|
49
81
|
}, {
|
|
50
82
|
key: "ascendingComparator",
|
|
@@ -68,7 +100,7 @@ function () {
|
|
|
68
100
|
}, {
|
|
69
101
|
key: "asinh",
|
|
70
102
|
value: function asinh() {
|
|
71
|
-
return
|
|
103
|
+
return _asinh["default"].apply(Math, arguments);
|
|
72
104
|
}
|
|
73
105
|
}, {
|
|
74
106
|
key: "atan",
|
|
@@ -83,12 +115,12 @@ function () {
|
|
|
83
115
|
}, {
|
|
84
116
|
key: "atanh",
|
|
85
117
|
value: function atanh() {
|
|
86
|
-
return
|
|
118
|
+
return _atanh["default"].apply(Math, arguments);
|
|
87
119
|
}
|
|
88
120
|
}, {
|
|
89
121
|
key: "cbrt",
|
|
90
122
|
value: function cbrt() {
|
|
91
|
-
return
|
|
123
|
+
return _cbrt["default"].apply(Math, arguments);
|
|
92
124
|
}
|
|
93
125
|
}, {
|
|
94
126
|
key: "ceil",
|
|
@@ -98,7 +130,7 @@ function () {
|
|
|
98
130
|
}, {
|
|
99
131
|
key: "clz32",
|
|
100
132
|
value: function clz32() {
|
|
101
|
-
return
|
|
133
|
+
return _clz["default"].apply(Math, arguments);
|
|
102
134
|
}
|
|
103
135
|
}, {
|
|
104
136
|
key: "cos",
|
|
@@ -108,7 +140,7 @@ function () {
|
|
|
108
140
|
}, {
|
|
109
141
|
key: "cosh",
|
|
110
142
|
value: function cosh() {
|
|
111
|
-
return
|
|
143
|
+
return _cosh["default"].apply(Math, arguments);
|
|
112
144
|
}
|
|
113
145
|
}, {
|
|
114
146
|
key: "descendingComparator",
|
|
@@ -132,7 +164,7 @@ function () {
|
|
|
132
164
|
}, {
|
|
133
165
|
key: "expm1",
|
|
134
166
|
value: function expm1() {
|
|
135
|
-
return
|
|
167
|
+
return _expm["default"].apply(Math, arguments);
|
|
136
168
|
}
|
|
137
169
|
}, {
|
|
138
170
|
key: "floor",
|
|
@@ -142,17 +174,17 @@ function () {
|
|
|
142
174
|
}, {
|
|
143
175
|
key: "fround",
|
|
144
176
|
value: function fround() {
|
|
145
|
-
return
|
|
177
|
+
return _fround["default"].apply(Math, arguments);
|
|
146
178
|
}
|
|
147
179
|
}, {
|
|
148
180
|
key: "hypot",
|
|
149
181
|
value: function hypot() {
|
|
150
|
-
return
|
|
182
|
+
return _hypot["default"].apply(Math, arguments);
|
|
151
183
|
}
|
|
152
184
|
}, {
|
|
153
185
|
key: "imul",
|
|
154
186
|
value: function imul() {
|
|
155
|
-
return
|
|
187
|
+
return _imul["default"].apply(Math, arguments);
|
|
156
188
|
}
|
|
157
189
|
}, {
|
|
158
190
|
key: "isFinite",
|
|
@@ -163,7 +195,9 @@ function () {
|
|
|
163
195
|
}, {
|
|
164
196
|
key: "isInt",
|
|
165
197
|
value: function isInt(value) {
|
|
166
|
-
|
|
198
|
+
if (this.isNaN(value)) return false;
|
|
199
|
+
var x = this.parseFloat(value);
|
|
200
|
+
return (x | 0) === x;
|
|
167
201
|
}
|
|
168
202
|
}, {
|
|
169
203
|
key: "isInteger",
|
|
@@ -188,17 +222,17 @@ function () {
|
|
|
188
222
|
}, {
|
|
189
223
|
key: "log10",
|
|
190
224
|
value: function log10() {
|
|
191
|
-
return
|
|
225
|
+
return _log["default"].apply(Math, arguments);
|
|
192
226
|
}
|
|
193
227
|
}, {
|
|
194
228
|
key: "log1p",
|
|
195
229
|
value: function log1p() {
|
|
196
|
-
return
|
|
230
|
+
return _log1p["default"].apply(Math, arguments);
|
|
197
231
|
}
|
|
198
232
|
}, {
|
|
199
233
|
key: "log2",
|
|
200
234
|
value: function log2() {
|
|
201
|
-
return
|
|
235
|
+
return _log2["default"].apply(Math, arguments);
|
|
202
236
|
}
|
|
203
237
|
}, {
|
|
204
238
|
key: "max",
|
|
@@ -238,7 +272,7 @@ function () {
|
|
|
238
272
|
}, {
|
|
239
273
|
key: "sign",
|
|
240
274
|
value: function sign() {
|
|
241
|
-
return
|
|
275
|
+
return _sign["default"].apply(Math, arguments);
|
|
242
276
|
}
|
|
243
277
|
}, {
|
|
244
278
|
key: "sin",
|
|
@@ -248,7 +282,7 @@ function () {
|
|
|
248
282
|
}, {
|
|
249
283
|
key: "sinh",
|
|
250
284
|
value: function sinh() {
|
|
251
|
-
return
|
|
285
|
+
return _sinh["default"].apply(Math, arguments);
|
|
252
286
|
}
|
|
253
287
|
}, {
|
|
254
288
|
key: "sqrt",
|
|
@@ -263,12 +297,12 @@ function () {
|
|
|
263
297
|
}, {
|
|
264
298
|
key: "tanh",
|
|
265
299
|
value: function tanh() {
|
|
266
|
-
return
|
|
300
|
+
return _tanh["default"].apply(Math, arguments);
|
|
267
301
|
}
|
|
268
302
|
}, {
|
|
269
303
|
key: "trunc",
|
|
270
304
|
value: function trunc() {
|
|
271
|
-
return
|
|
305
|
+
return _trunc["default"].apply(Math, arguments);
|
|
272
306
|
}
|
|
273
307
|
}, {
|
|
274
308
|
key: "E",
|
package/index.js
CHANGED
package/lib/Numbers.js
CHANGED
|
@@ -109,11 +109,9 @@ class Numbers {
|
|
|
109
109
|
|
|
110
110
|
// http://stackoverflow.com/questions/14636536/how-to-check-if-a-variable-is-an-integer-in-javascript
|
|
111
111
|
isInt(value) {
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
!this.isNaN(this.parseInt(value, 10))
|
|
116
|
-
);
|
|
112
|
+
if (this.isNaN(value)) return false;
|
|
113
|
+
const x = this.parseFloat(value);
|
|
114
|
+
return (x | 0) === x;
|
|
117
115
|
}
|
|
118
116
|
|
|
119
117
|
isInteger() {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Chris Topher <c@creemama.com>",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@babel/runtime-
|
|
4
|
+
"@babel/runtime-corejs3": "7.16.0"
|
|
5
5
|
},
|
|
6
6
|
"dependencies-comments": [
|
|
7
|
-
"@babel/runtime-
|
|
7
|
+
"@babel/runtime-corejs3 is required by files in the dist directory to ",
|
|
8
8
|
"work in https://npm.runkit.com."
|
|
9
9
|
],
|
|
10
10
|
"description": "JavaScript utility methods for numbers",
|
|
@@ -32,6 +32,6 @@
|
|
|
32
32
|
"type": "git",
|
|
33
33
|
"url": "https://github.com/creemama/utiljs/tree/master/packages/utiljs-numbers"
|
|
34
34
|
},
|
|
35
|
-
"version": "0.
|
|
36
|
-
"gitHead": "
|
|
35
|
+
"version": "0.41.1",
|
|
36
|
+
"gitHead": "d67c89b352539700b681a5bbfaed634cd29052c0"
|
|
37
37
|
}
|
package/test/NumbersTest.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const { expect } = require("chai")
|
|
4
|
-
|
|
3
|
+
const { expect } = require("chai");
|
|
4
|
+
const numbers = require("..");
|
|
5
5
|
|
|
6
6
|
describe("Numbers#abs(x)", () => {
|
|
7
7
|
it("should calculate correctly", () => {
|
|
@@ -27,7 +27,7 @@ describe("Numbers", () => {
|
|
|
27
27
|
33.33,
|
|
28
28
|
numbers.POSITIVE_INFINITY,
|
|
29
29
|
numbers.NaN,
|
|
30
|
-
numbers.NaN
|
|
30
|
+
numbers.NaN,
|
|
31
31
|
];
|
|
32
32
|
const actual = [
|
|
33
33
|
numbers.POSITIVE_INFINITY,
|
|
@@ -36,7 +36,7 @@ describe("Numbers", () => {
|
|
|
36
36
|
numbers.NEGATIVE_INFINITY,
|
|
37
37
|
-33,
|
|
38
38
|
numbers.NaN,
|
|
39
|
-
33.33
|
|
39
|
+
33.33,
|
|
40
40
|
].sort(numbers.ascendingComparator());
|
|
41
41
|
expect(actual).to.deep.equal(expected);
|
|
42
42
|
});
|
|
@@ -52,7 +52,7 @@ describe("Numbers", () => {
|
|
|
52
52
|
33.33,
|
|
53
53
|
0,
|
|
54
54
|
-33,
|
|
55
|
-
numbers.NEGATIVE_INFINITY
|
|
55
|
+
numbers.NEGATIVE_INFINITY,
|
|
56
56
|
];
|
|
57
57
|
const actual = [
|
|
58
58
|
numbers.NaN,
|
|
@@ -62,7 +62,7 @@ describe("Numbers", () => {
|
|
|
62
62
|
numbers.NEGATIVE_INFINITY,
|
|
63
63
|
-33,
|
|
64
64
|
numbers.NaN,
|
|
65
|
-
33.33
|
|
65
|
+
33.33,
|
|
66
66
|
].sort(numbers.descendingComparator());
|
|
67
67
|
expect(actual).to.deep.equal(expected);
|
|
68
68
|
});
|
|
@@ -81,6 +81,7 @@ describe("Numbers", () => {
|
|
|
81
81
|
});
|
|
82
82
|
it("should return true for objects whose #toString evaluates to an integer", () => {
|
|
83
83
|
expect(numbers.isInt([5])).to.be.true;
|
|
84
|
+
expect(numbers.isInt([5, 6])).to.be.true;
|
|
84
85
|
expect(numbers.isInt({ toString: () => "5" })).to.be.true;
|
|
85
86
|
});
|
|
86
87
|
it("should return false for numbers with a nonzero fractional part", () => {
|
|
@@ -97,7 +98,6 @@ describe("Numbers", () => {
|
|
|
97
98
|
it("should return false for objects whose #toString does not evaluate to an integer", () => {
|
|
98
99
|
expect(numbers.isInt([])).to.be.false;
|
|
99
100
|
expect(numbers.isInt({})).to.be.false;
|
|
100
|
-
expect(numbers.isInt([5, 5])).to.be.false;
|
|
101
101
|
expect(numbers.isInt([5.5, 5])).to.be.false;
|
|
102
102
|
expect(numbers.isInt({ toString: () => "5.5" })).to.be.false;
|
|
103
103
|
});
|