@util.js/numbers 0.41.0 → 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 CHANGED
@@ -195,7 +195,9 @@ var Numbers = /*#__PURE__*/function () {
195
195
  }, {
196
196
  key: "isInt",
197
197
  value: function isInt(value) {
198
- return !this.isNaN(value) && this.parseInt(Number(value)) == value && !this.isNaN(this.parseInt(value, 10));
198
+ if (this.isNaN(value)) return false;
199
+ var x = this.parseFloat(value);
200
+ return (x | 0) === x;
199
201
  }
200
202
  }, {
201
203
  key: "isInteger",
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
2
 
3
+ // eslint-disable-next-line no-var
3
4
  var Numbers = require("./dist/Numbers");
4
5
  module.exports = new Numbers();
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
- !this.isNaN(value) &&
114
- this.parseInt(Number(value)) == value &&
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,7 +1,7 @@
1
1
  {
2
2
  "author": "Chris Topher <c@creemama.com>",
3
3
  "dependencies": {
4
- "@babel/runtime-corejs3": "7.14.0"
4
+ "@babel/runtime-corejs3": "7.16.0"
5
5
  },
6
6
  "dependencies-comments": [
7
7
  "@babel/runtime-corejs3 is required by files in the dist directory to ",
@@ -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.41.0",
36
- "gitHead": "1ae0fda34e06ffbc546c5ba0025b0b59a0c7727d"
35
+ "version": "0.41.1",
36
+ "gitHead": "d67c89b352539700b681a5bbfaed634cd29052c0"
37
37
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
- const { expect } = require("chai"),
4
- numbers = require("..");
3
+ const { expect } = require("chai");
4
+ const numbers = require("..");
5
5
 
6
6
  describe("Numbers#abs(x)", () => {
7
7
  it("should calculate correctly", () => {
@@ -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
  });