-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |