-
-
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.
Ref #66
- Loading branch information
Showing
4 changed files
with
69 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
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 { pipe, equals } from 'ramda'; | ||
|
||
|
||
/** | ||
* In JavaScript, a `truthy` value is a value that is considered true | ||
* when evaluated in a Boolean context. All values are truthy unless | ||
* they are defined as falsy (i.e., except for `false`, `0`, `""`, `null`, `undefined`, and `NaN`). | ||
* | ||
* @func isTruthy | ||
* @memberOf RA | ||
* @since {@link https://char0n.github.io/ramda-adjunct/2.2.0|v2.2..0} | ||
* @category Type | ||
* @sig * -> Boolean | ||
* @param {*} val The value to test | ||
* @return {Boolean} | ||
* @see {@link RA.isFalsy|isFalsy} | ||
* @example | ||
* | ||
* RA.isTruthy({}); // => true | ||
* RA.isTruthy([]); // => true | ||
* RA.isTruthy(42); // => true | ||
* RA.isTruthy(3.14); // => true | ||
* RA.isTruthy('foo'); // => true | ||
* RA.isTruthy(new Date()); // => true | ||
* RA.isTruthy(Infinity); // => true | ||
*/ | ||
const isTruthy = pipe(Boolean, equals(true)); | ||
|
||
export default isTruthy; |
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,32 @@ | ||
import * as RA from '../src/index'; | ||
import eq from './shared/eq'; | ||
import Symbol from './shared/Symbol'; | ||
import args from './shared/arguments'; | ||
|
||
|
||
describe('isTruthy', function() { | ||
it('tests a value for `truthy`', function() { | ||
eq(RA.isTruthy('abc'), true); | ||
eq(RA.isTruthy(Object('abc')), true); | ||
eq(RA.isTruthy(args), true); | ||
eq(RA.isTruthy([1, 2, 3]), true); | ||
eq(RA.isTruthy(true), true); | ||
eq(RA.isTruthy(new Date()), true); | ||
eq(RA.isTruthy(new Error()), true); | ||
eq(RA.isTruthy(Array.prototype.slice), true); | ||
eq(RA.isTruthy({ 0: 1, length: 1 }), true); | ||
eq(RA.isTruthy(1), true); | ||
eq(RA.isTruthy(/x/), true); | ||
eq(RA.isTruthy(Symbol), true); | ||
eq(RA.isTruthy({}), true); | ||
eq(RA.isTruthy([]), true); | ||
eq(RA.isTruthy(Infinity), true); | ||
|
||
eq(RA.isTruthy(false), false); | ||
eq(RA.isTruthy(0), false); | ||
eq(RA.isTruthy(''), false); | ||
eq(RA.isTruthy(null), false); | ||
eq(RA.isTruthy(undefined), false); | ||
eq(RA.isTruthy(NaN), false); | ||
}); | ||
}); |