Repository: char0n/ramda-adjunct
Pull request #2257 (2022-05-03 14:07:59)

isUinteger32
#1281

Mostly inspired by #1826

rhian-cs: Hey there @char0n can you review this PR?

Patch:
diff --git a/src/index.js b/src/index.js
index 36096c35fb..0931ef0b1a 100644
--- a/src/index.js
+++ b/src/index.js
@@ -63,6 +63,8 @@ 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 isUinteger32 } from './isUinteger32';
+export { default as isUint32 } from './isUinteger32'; // alias of isUinteger32
 export { default as isNotInteger } from './isNotInteger';
 export { default as isBigInt } from './isBigInt';
 export { default as isFloat } from './isFloat';
diff --git a/src/isUinteger32.js b/src/isUinteger32.js
new file mode 100644
index 0000000000..0d5f541c31
--- /dev/null
+++ b/src/isUinteger32.js
@@ -0,0 +1,29 @@
+import { curryN } from 'ramda';
+
+import toUinteger32 from './toUinteger32';
+
+/**
+ * Checks whether the passed value is an unsigned 32 bit integer.
+ *
+ * @func isUinteger32
+ * @aliases isUint32
+ * @memberOf RA
+ * @since {@link https://char0n.github.io/ramda-adjunct/3.2.0|v3.2.0}
+ * @category Type
+ * @sig * -> Boolean
+ * @param {*} val The value to test
+ * @return {boolean}
+ * @see {@link RA.toUinteger32|toUinteger32}
+ * @example
+ *
+ * RA.isUinteger32(0); //=> true
+ * RA.isUinteger32(2 ** 32 - 1); //=> true
+ *
+ * RA.isUinteger32(Infinity); //=> false
+ * RA.isUinteger32(NaN); //=> false
+ * RA.isUinteger32(-1); //=> false
+ * RA.isUinteger32(2 ** 32); //=> false
+ */
+const isUinteger32 = curryN(1, (val) => toUinteger32(val) === val);
+
+export default isUinteger32;
diff --git a/types/index.d.ts b/types/index.d.ts
index d6b9956dbd..0b00592895 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -360,6 +360,12 @@ declare namespace RamdaAdjunct {
          */
         isInteger32(val: any): boolean;
 
+        /**
+         * Checks whether the passed value is an unsigned 32 bit integer number.
+         */
+        isUinteger32(val: any): boolean;
+        isUint32(val: any): boolean; // alias
+
         /**
          * Checks whether the passed value is complement of `integer`.
          */


Test patch:
diff --git a/test/isUinteger32.js b/test/isUinteger32.js
new file mode 100644
index 0000000000..8c0075671e
--- /dev/null
+++ b/test/isUinteger32.js
@@ -0,0 +1,44 @@
+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('isUinteger32', function () {
+  it('should return true for positive 32 bit integers', function () {
+    assert.isTrue(RA.isUinteger32(0));
+    assert.isTrue(RA.isUinteger32(100000));
+    assert.isTrue(RA.isUinteger32(2 ** 32 - 1));
+  });
+
+  it('should return false for negative 32 bit integers', function () {
+    assert.isFalse(RA.isUinteger32(-1));
+    assert.isFalse(RA.isUinteger32(-(2 ** 32 - 1)));
+  });
+
+  it('should return false for 64 bit integers', function () {
+    assert.isFalse(RA.isUinteger32(2 ** 32));
+    assert.isFalse(RA.isUinteger32(MIN_SAFE_INTEGER));
+    assert.isFalse(RA.isUinteger32(MAX_SAFE_INTEGER));
+  });
+
+  it('should return false for non integers', function () {
+    assert.isFalse(RA.isUinteger32(null));
+    assert.isFalse(RA.isUinteger32(undefined));
+    assert.isFalse(RA.isUinteger32(NaN));
+    assert.isFalse(RA.isUinteger32(Infinity));
+    assert.isFalse(RA.isUinteger32(-Infinity));
+    assert.isFalse(RA.isUinteger32(0.1));
+    assert.isFalse(RA.isUinteger32(Math.E));
+    assert.isFalse(RA.isUinteger32('10'));
+    assert.isFalse(RA.isUinteger32(false));
+    assert.isFalse(RA.isUinteger32([]));
+    assert.isFalse(RA.isUinteger32({}));
+  });
+
+  it('should support placeholder to specify "gaps"', function () {
+    const isUinteger32 = RA.isUinteger32(R.__);
+    assert.isTrue(isUinteger32(0));
+  });
+});
diff --git a/types/test/isUinteger32.ts b/types/test/isUinteger32.ts
new file mode 100644
index 0000000000..593e95a575
--- /dev/null
+++ b/types/test/isUinteger32.ts
@@ -0,0 +1,16 @@
+import * as RA from 'ramda-adjunct';
+
+RA.isUinteger32(0); // $ExpectType boolean
+RA.isUinteger32(null); // $ExpectType boolean
+RA.isUinteger32(true); // $ExpectType boolean
+RA.isUinteger32(NaN); // $ExpectType boolean
+RA.isUinteger32({}); // $ExpectType boolean
+RA.isUinteger32([]); // $ExpectType boolean
+RA.isUinteger32(() => {}); // $ExpectType boolean
+RA.isUinteger32('string'); // $ExpectType boolean
+RA.isUinteger32(1); // $ExpectType boolean
+RA.isUinteger32(0.1); // $ExpectType boolean
+RA.isUinteger32(Object(0.1)); // $ExpectType boolean
+RA.isUinteger32(Infinity); // $ExpectType boolean
+RA.isUinteger32(Number.MAX_VALUE); // $ExpectType boolean
+RA.isUinteger32(Number.MIN_VALUE); // $ExpectType boolean