Repository: char0n/ramda-adjunct
Pull request #1826 (2021-03-28 11:52:57)

Add isInteger32
This PR adds a predicate to determine if an integer is 32 bits. #1282 


skShekhar: @char0n Can you review this PR
char0n: Thanks for contributing. I'll get to core review ASAP.
skShekhar: @char0n I've added missing typescript typing and tests for `isInteger32`. The review comments have also been addressed

Patch:
diff --git a/src/index.js b/src/index.js
index 254e065558..7314de6b5c 100644
--- a/src/index.js
+++ b/src/index.js
@@ -61,6 +61,8 @@ export { default as isNotNaN } from './isNotNaN';
 export { default as isFinite } from './isFinite';
 export { default as isNotFinite } from './isNotFinite';
 export { default as isInteger } from './isInteger';
+export { default as isInteger32 } from './isInteger32';
+export { default as isInt32 } from './isInteger32'; // alias of isInteger32
 export { default as isNotInteger } from './isNotInteger';
 export { default as isBigInt } from './isBigInt';
 export { default as isFloat } from './isFloat';
diff --git a/src/isInteger32.js b/src/isInteger32.js
new file mode 100644
index 0000000000..b5f521e679
--- /dev/null
+++ b/src/isInteger32.js
@@ -0,0 +1,28 @@
+import { curryN } from 'ramda';
+
+import toInteger32 from './toInteger32';
+
+/**
+ * Checks whether the passed value is a signed 32 bit integer.
+ *
+ * @func isInteger32
+ * @aliases isInt32
+ * @memberOf RA
+ * @since {@link https://char0n.github.io/ramda-adjunct/2.32.0|v2.32.0}
+ * @category Type
+ * @sig * -> Boolean
+ * @param {*} val The value to test
+ * @return {boolean}
+ * @see {@link RA.toInteger32|toInteger32}
+ * @example
+ *
+ * RA.isInteger32(0); //=> true
+ * RA.isInteger32((-2) ** 31); //=> true
+ *
+ * RA.isInteger32(Infinity); //=> false
+ * RA.isInteger32(NaN); //=> false
+ * RA.isInteger32(2 ** 31); //=> false
+ */
+const isInteger32 = curryN(1, (val) => toInteger32(val) === val);
+
+export default isInteger32;
diff --git a/types/index.d.ts b/types/index.d.ts
index 624d474d6e..fa1714a14f 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -355,6 +355,11 @@ declare namespace RamdaAdjunct {
          */
         isInteger(val: any): val is number;
 
+        /**
+         * Checks whether the passed value is a signed 32 bit `integer`.
+         */
+        isInteger32(val: any): boolean;
+
         /**
          * Checks whether the passed value is complement of `integer`.
          */


Test patch:
diff --git a/test/isInteger32.js b/test/isInteger32.js
new file mode 100644
index 0000000000..cf7ff7e694
--- /dev/null
+++ b/test/isInteger32.js
@@ -0,0 +1,42 @@
+import * as R from 'ramda';
+import { assert } from 'chai';
+
+import * as RA from '../src';
+import MAX_SAFE_INTEGER from '../src/internal/ponyfills/Number.MAX_SAFE_INTEGER';
+import MIN_SAFE_INTEGER from '../src/internal/ponyfills/Number.MIN_SAFE_INTEGER';
+
+describe('isInteger32', function () {
+  it('should return true for 32 bit integers', function () {
+    assert.isTrue(RA.isInteger32(0));
+    assert.isTrue(RA.isInteger32(100000));
+    assert.isTrue(RA.isInteger32(-100000));
+    assert.isTrue(RA.isInteger32(2 ** 31 - 1));
+    assert.isTrue(RA.isInteger32((-2) ** 31));
+  });
+
+  it('should return false for 64 bit integers', function () {
+    assert.isFalse(RA.isInteger32(2 ** 31));
+    assert.isFalse(RA.isInteger32((-2) ** 31 - 1));
+    assert.isFalse(RA.isInteger32(MIN_SAFE_INTEGER));
+    assert.isFalse(RA.isInteger32(MAX_SAFE_INTEGER));
+  });
+
+  it('should return false for non integers', function () {
+    assert.isFalse(RA.isInteger32(null));
+    assert.isFalse(RA.isInteger32(undefined));
+    assert.isFalse(RA.isInteger32(NaN));
+    assert.isFalse(RA.isInteger32(Infinity));
+    assert.isFalse(RA.isInteger32(-Infinity));
+    assert.isFalse(RA.isInteger32(0.1));
+    assert.isFalse(RA.isInteger32(Math.E));
+    assert.isFalse(RA.isInteger32('10'));
+    assert.isFalse(RA.isInteger32(false));
+    assert.isFalse(RA.isInteger32([]));
+    assert.isFalse(RA.isInteger32({}));
+  });
+
+  it('should support placeholder to specify "gaps"', function () {
+    const isInteger32 = RA.isInteger32(R.__);
+    assert.isTrue(isInteger32(0));
+  });
+});
diff --git a/types/test/isInteger32.ts b/types/test/isInteger32.ts
new file mode 100644
index 0000000000..6eb79a4b65
--- /dev/null
+++ b/types/test/isInteger32.ts
@@ -0,0 +1,16 @@
+import * as RA from 'ramda-adjunct';
+
+RA.isInteger32(0); // $ExpectType boolean
+RA.isInteger32(null); // $ExpectType boolean
+RA.isInteger32(true); // $ExpectType boolean
+RA.isInteger32(NaN); // $ExpectType boolean
+RA.isInteger32({}); // $ExpectType boolean
+RA.isInteger32([]); // $ExpectType boolean
+RA.isInteger32(() => {}); // $ExpectType boolean
+RA.isInteger32('string'); // $ExpectType boolean
+RA.isInteger32(1); // $ExpectType boolean
+RA.isInteger32(0.1); // $ExpectType boolean
+RA.isInteger32(Object(0.1)); // $ExpectType boolean
+RA.isInteger32(Infinity); // $ExpectType boolean
+RA.isInteger32(Number.MAX_VALUE); // $ExpectType boolean
+RA.isInteger32(Number.MIN_VALUE); // $ExpectType boolean