Skip to content

Commit

Permalink
feat: add isNonEmptyArray (#289)
Browse files Browse the repository at this point in the history
Close #279
  • Loading branch information
guillaumearm authored and char0n committed Jan 19, 2018
1 parent 961692e commit 464060e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ declare namespace RamdaAdjunct {
*/
isNotArray(val: any): boolean;

/**
* Checks if input value is a non empty `Array`.
*/
isNonEmptyArray(val: any): val is Array<any>;

/**
* Checks if input value is complement of `Boolean`.
*/
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { default as isNotNil } from './isNotNil';
export { default as isArray } from './isArray';
export { default as isEmptyArray } from './isEmptyArray';
export { default as isNotArray } from './isNotArray';
export { default as isNonEmptyArray } from './isNonEmptyArray';
export { default as isBoolean } from './isBoolean';
export { default as isNotBoolean } from './isNotBoolean';
export { default as isNilOrEmpty } from './isNilOrEmpty';
Expand Down
29 changes: 29 additions & 0 deletions src/isNonEmptyArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { both } from 'ramda';

import isNotEmpty from './isNotEmpty';
import isArray from './isArray';

/**
* Checks if input value is not an empty `Array`.
*
* @func isNonEmptyArray
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/2.4.0|v2.4.0}
* @category Type
* @sig * -> Boolean
* @param {*} val The value to test
* @return {Boolean}
* @see {@link RA.isEmptyArray|isEmptyArray}
* @example
*
* RA.isNonEmptyArray([42]); // => true
* RA.isNonEmptyArray([]); // => false
* RA.isNonEmptyArray({}); // => false
* RA.isNonEmptyArray(null); // => false
* RA.isNonEmptyArray(undefined); // => false
* RA.isNonEmptyArray(42); // => false
* RA.isNonEmptyArray('42'); // => false
*/
const isNonEmptyArray = both(isArray, isNotEmpty);

export default isNonEmptyArray;
24 changes: 24 additions & 0 deletions test/isNonEmptyArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as RA from '../src/index';
import eq from './shared/eq';


describe('isNonEmptyArray', function () {
it('tests a value to be a non empty `Array`', function () {
eq(RA.isNonEmptyArray([42]), true);
eq(RA.isNonEmptyArray(new Array('content')), true);

eq(RA.isNonEmptyArray([]), false);
eq(RA.isNonEmptyArray(new Array()), false);
eq(RA.isNonEmptyArray(new Array(42)), false);
eq(RA.isNonEmptyArray(Array.prototype), false);
eq(RA.isNonEmptyArray(void 0), false);
eq(RA.isNonEmptyArray({}), false);
eq(RA.isNonEmptyArray(null), false);
eq(RA.isNonEmptyArray(undefined), false);
eq(RA.isNonEmptyArray(42), false);
eq(RA.isNonEmptyArray('Array'), false);
eq(RA.isNonEmptyArray(true), false);
eq(RA.isNonEmptyArray(false), false);
eq(RA.isNonEmptyArray({ __proto__: Array.prototype }), false);
});
});

0 comments on commit 464060e

Please sign in to comment.