Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add isFalsy #240

Merged
merged 1 commit into from
Dec 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,12 @@ declare namespace RamdaAdjunct {
*/
isTruthy(val: any): boolean;

/**
* A falsy value is a value that translates to false when evaluated in a Boolean context.
* Falsy values are `false`, `0`, `""`, `null`, `undefined`, and `NaN`.
*/
isFalsy(val: any): boolean;

/**
* Identity type.
*/
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export { default as isNotPair } from './isNotPair';
export { default as isThenable } from './isThenable';
export { default as isPromise } from './isPromise';
export { default as isTruthy } from './isTruthy';
export { default as isFalsy } from './isFalsy';
// Function
export { default as stubUndefined } from './stubUndefined';
export { default as stubNull } from './stubNull';
Expand Down
29 changes: 29 additions & 0 deletions src/isFalsy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { complement } from 'ramda';

import isTruthy from './isTruthy';


/**
* A falsy value is a value that translates to false when evaluated in a Boolean context.
* Falsy values are `false`, `0`, `""`, `null`, `undefined`, and `NaN`.
*
* @func isFalsy
* @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 https://developer.mozilla.org/en-US/docs/Glossary/Falsy|falsy}, {@link RA.isTruthy|isTruthy}
* @example
*
* RA.isFalsy(false); // => true
* RA.isFalsy(0); // => true
* RA.isFalsy(''); // => true
* RA.isFalsy(null); // => true
* RA.isFalsy(undefined); // => true
* RA.isFalsy(NaN); // => true
*/
const isFalsy = complement(isTruthy);

export default isFalsy;
2 changes: 1 addition & 1 deletion src/isTruthy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { pipe, equals } from 'ramda';
* @sig * -> Boolean
* @param {*} val The value to test
* @return {Boolean}
* @see {@link RA.isFalsy|isFalsy}
* @see {@link https://developer.mozilla.org/en-US/docs/Glossary/Truthy|truthy}, {@link RA.isFalsy|isFalsy}
* @example
*
* RA.isTruthy({}); // => true
Expand Down
31 changes: 31 additions & 0 deletions test/isFalsy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as RA from '../src/index';
import eq from './shared/eq';
import Symbol from './shared/Symbol';
import args from './shared/arguments';


describe('isFalsy', function() {
it('tests a value for `falsy`', function() {
eq(RA.isFalsy(false), true);
eq(RA.isFalsy(0), true);
eq(RA.isFalsy(''), true);
eq(RA.isFalsy(null), true);
eq(RA.isFalsy(undefined), true);
eq(RA.isFalsy(NaN), true);

eq(RA.isFalsy('abc'), false);
eq(RA.isFalsy(Object('abc')), false);
eq(RA.isFalsy(args), false);
eq(RA.isFalsy([1, 2, 3]), false);
eq(RA.isFalsy(new Date()), false);
eq(RA.isFalsy(new Error()), false);
eq(RA.isFalsy(Array.prototype.slice), false);
eq(RA.isFalsy({ 0: 1, length: 1 }), false);
eq(RA.isFalsy(1), false);
eq(RA.isFalsy(/x/), false);
eq(RA.isFalsy(Symbol), RA.isUndefined(Symbol));
eq(RA.isFalsy({}), false);
eq(RA.isFalsy([]), false);
eq(RA.isFalsy(Infinity), false);
});
});