-
-
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.
feat: add isNonPositive, isNonNegative (#434)
- clarify zero exclusion for isPositive, isNegative Closes #324
- Loading branch information
1 parent
274d5ad
commit 8d62dc1
Showing
8 changed files
with
197 additions
and
35 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
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,30 @@ | ||
import { both, gte, flip } from 'ramda'; | ||
|
||
import isNumber from './isNumber'; | ||
|
||
/** | ||
* Checks if value is a non-negative `Number` primitive or object. This includes all positive | ||
* numbers and zero. | ||
* | ||
* @func isNonNegative | ||
* @memberOf RA | ||
* @since {@link https://char0n.github.io/ramda-adjunct/2.6.0|v2.6.0} | ||
* @category Type | ||
* @sig * -> Boolean | ||
* @param {*} val The value to test | ||
* @return {boolean} | ||
* @see {@link RA.isPositive|isPositive}, {@link RA.isNonPositive|isNonPositive} | ||
* @example | ||
* | ||
* RA.isNonNegative(0); // => true | ||
* RA.isNonNegative(1); // => true | ||
* RA.isNonNegative(Infinity); // => true | ||
* RA.isNonNegative(Number.MAX_VALUE); // => true | ||
* | ||
* RA.isNonNegative(-Infinity); // => false | ||
* RA.isNonNegative(Number.MIN_VALUE); // => false | ||
* RA.isNonNegative(NaN); // => false | ||
*/ | ||
const isNonNegative = both(isNumber, flip(gte)(0)); | ||
|
||
export default isNonNegative; |
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,30 @@ | ||
import { both, lte, flip } from 'ramda'; | ||
|
||
import isNumber from './isNumber'; | ||
|
||
/** | ||
* Checks if value is a non-positive `Number` primitive or object. This includes all negative | ||
* numbers and zero. | ||
* | ||
* @func isNonPositive | ||
* @memberOf RA | ||
* @since {@link https://char0n.github.io/ramda-adjunct/2.6.0|v2.6.0} | ||
* @category Type | ||
* @sig * -> Boolean | ||
* @param {*} val The value to test | ||
* @return {Boolean} | ||
* @see {@link RA.isNegative|isNegative}, {@link RA.isNonNegative|isNonNegative} | ||
* @example | ||
* | ||
* RA.isNonPositive(0); // => true | ||
* RA.isNonPositive(-1); // => true | ||
* RA.isNonPositive(-Infinity); // => true | ||
* RA.isNonPositive(Number.MIN_VALUE); // => true | ||
* | ||
* RA.isNonPositive(Infinity); // => false | ||
* RA.isNonPositive(Number.MAX_VALUE); // => false | ||
* RA.isNonPositive(NaN); // => false | ||
*/ | ||
const isNonPositive = both(isNumber, flip(lte)(0)); | ||
|
||
export default isNonPositive; |
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,42 @@ | ||
import * as RA from '../src/index'; | ||
import MAX_SAFE_INTEGER from '../src/internal/polyfills/Number.MAX_SAFE_INTEGER'; | ||
import MIN_SAFE_INTEGER from '../src/internal/polyfills/Number.MIN_SAFE_INTEGER'; | ||
import eq from './shared/eq'; | ||
import args from './shared/arguments'; | ||
import Symbol from './shared/Symbol'; | ||
|
||
describe('isNonNegative', function() { | ||
it('tests a value for non-negative `Number`', function() { | ||
eq(RA.isNonNegative(0), true); | ||
eq(RA.isNonNegative(-0.1), false); | ||
eq(RA.isNonNegative(0.1), true); | ||
eq(RA.isNonNegative(Object(0)), true); | ||
eq(RA.isNonNegative(Object(-0.1)), false); | ||
eq(RA.isNonNegative(Object(0.1)), true); | ||
eq(RA.isNonNegative(NaN), false); | ||
eq(RA.isNonNegative(Infinity), true); | ||
eq(RA.isNonNegative(-Infinity), false); | ||
eq(RA.isNonNegative(MAX_SAFE_INTEGER), true); | ||
eq(RA.isNonNegative(MIN_SAFE_INTEGER), false); | ||
eq(RA.isNonNegative(Number.MAX_VALUE), true); | ||
eq(RA.isNonNegative(Number.MIN_VALUE), true); | ||
|
||
eq(RA.isNonNegative(new Date()), false); | ||
eq(RA.isNonNegative(args), false); | ||
eq(RA.isNonNegative([1, 2, 3]), false); | ||
eq(RA.isNonNegative(Object(false)), false); | ||
eq(RA.isNonNegative(new Error()), false); | ||
eq(RA.isNonNegative(RA), false); | ||
eq(RA.isNonNegative(Array.prototype.slice), false); | ||
eq(RA.isNonNegative({ a: 1 }), false); | ||
eq(RA.isNonNegative(/x/), false); | ||
eq(RA.isNonNegative(Object('a')), false); | ||
|
||
if (Symbol !== 'undefined') { | ||
eq(RA.isNonNegative(Symbol), false); | ||
} | ||
|
||
eq(RA.isNonNegative(null), false); | ||
eq(RA.isNonNegative(undefined), false); | ||
}); | ||
}); |
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,42 @@ | ||
import * as RA from '../src/index'; | ||
import MAX_SAFE_INTEGER from '../src/internal/polyfills/Number.MAX_SAFE_INTEGER'; | ||
import MIN_SAFE_INTEGER from '../src/internal/polyfills/Number.MIN_SAFE_INTEGER'; | ||
import eq from './shared/eq'; | ||
import args from './shared/arguments'; | ||
import Symbol from './shared/Symbol'; | ||
|
||
describe('isNonPositive', function() { | ||
it('tests a value for non-positive `Number`', function() { | ||
eq(RA.isNonPositive(0), true); | ||
eq(RA.isNonPositive(-0.1), true); | ||
eq(RA.isNonPositive(0.1), false); | ||
eq(RA.isNonPositive(Object(0)), true); | ||
eq(RA.isNonPositive(Object(-0.1)), true); | ||
eq(RA.isNonPositive(Object(0.1)), false); | ||
eq(RA.isNonPositive(NaN), false); | ||
eq(RA.isNonPositive(Infinity), false); | ||
eq(RA.isNonPositive(-Infinity), true); | ||
eq(RA.isNonPositive(MAX_SAFE_INTEGER), false); | ||
eq(RA.isNonPositive(MIN_SAFE_INTEGER), true); | ||
eq(RA.isNonPositive(Number.MAX_VALUE), false); | ||
eq(RA.isNonPositive(Number.MIN_VALUE), false); | ||
|
||
eq(RA.isNonPositive(new Date()), false); | ||
eq(RA.isNonPositive(args), false); | ||
eq(RA.isNonPositive([1, 2, 3]), false); | ||
eq(RA.isNonPositive(Object(false)), false); | ||
eq(RA.isNonPositive(new Error()), false); | ||
eq(RA.isNonPositive(RA), false); | ||
eq(RA.isNonPositive(Array.prototype.slice), false); | ||
eq(RA.isNonPositive({ a: 1 }), false); | ||
eq(RA.isNonPositive(/x/), false); | ||
eq(RA.isNonPositive(Object('a')), false); | ||
|
||
if (Symbol !== 'undefined') { | ||
eq(RA.isNonPositive(Symbol), false); | ||
} | ||
|
||
eq(RA.isNonPositive(null), false); | ||
eq(RA.isNonPositive(undefined), false); | ||
}); | ||
}); |