Skip to content

Commit

Permalink
Add isNotEmpty (#3430)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harris-Miller committed Nov 21, 2023
1 parent ddd9736 commit 246fbac
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export { default as invoker } from './invoker.js';
export { default as is } from './is.js';
export { default as isEmpty } from './isEmpty.js';
export { default as isNil } from './isNil.js';
export { default as isNotEmpty } from './isNotEmpty.js';
export { default as isNotNil } from './isNotNil.js';
export { default as join } from './join.js';
export { default as juxt } from './juxt.js';
Expand Down
2 changes: 1 addition & 1 deletion source/isEmpty.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import equals from './equals.js';
* @sig a -> Boolean
* @param {*} x
* @return {Boolean}
* @see R.empty
* @see R.empty, R.isNotEmpty
* @example
*
* R.isEmpty([1, 2, 3]); //=> false
Expand Down
28 changes: 28 additions & 0 deletions source/isNotEmpty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import _curry1 from './internal/_curry1.js';
import isEmpty from './isEmpty.js';


/**
* Returns `false` if the given value is its type's empty value; `true`
* otherwise.
*
* @func
* @memberOf R
* @since v0.29.2
* @category Logic
* @sig a -> Boolean
* @param {*} x
* @return {Boolean}
* @see R.empty, R.isEmpty
* @example
*
* R.isNotEmpty([1, 2, 3]); //=> true
* R.isNotEmpty([]); //=> false
* R.isNotEmpty(''); //=> false
* R.isNotEmpty(null); //=> true
* R.isNotEmpty({}); //=> false
* R.isNotEmpty({length: 0}); //=> true
* R.isNotEmpty(Uint8Array.from('')); //=> false
*/
var isNotEmpty = _curry1(function isNotEmpty(x) { return !isEmpty(x); });
export default isNotEmpty;
50 changes: 50 additions & 0 deletions test/isNotEmpty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var R = require('../source/index.js');
var eq = require('./shared/eq.js');


describe('isNotEmpty', function() {

it('returns true for null', function() {
eq(R.isNotEmpty(null), true);
});

it('returns true for undefined', function() {
eq(R.isNotEmpty(undefined), true);
});

it('returns false for empty string', function() {
eq(R.isNotEmpty(''), false);
eq(R.isNotEmpty(' '), true);
});

it('returns false for empty array', function() {
eq(R.isNotEmpty([]), false);
eq(R.isNotEmpty([[]]), true);
});

it('returns false for empty typed array', function() {
eq(R.isNotEmpty(Uint8Array.from('')), false);
eq(R.isNotEmpty(Float32Array.from('')), false);
eq(R.isNotEmpty(new Float32Array([])), false);
eq(R.isNotEmpty(Uint8Array.from('1')), true);
eq(R.isNotEmpty(Float32Array.from('1')), true);
eq(R.isNotEmpty(new Float32Array([1])), true);
});

it('returns false for empty object', function() {
eq(R.isNotEmpty({}), false);
eq(R.isNotEmpty({x: 0}), true);
});

it('returns false for empty arguments object', function() {
eq(R.isNotEmpty((function() { return arguments; })()), false);
eq(R.isNotEmpty((function() { return arguments; })(0)), true);
});

it('returns true for every other value', function() {
eq(R.isNotEmpty(0), true);
eq(R.isNotEmpty(NaN), true);
eq(R.isNotEmpty(['']), true);
});

});

0 comments on commit 246fbac

Please sign in to comment.