Skip to content

Commit

Permalink
feat: add isNonEmptyArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume ARM committed Jan 18, 2018
1 parent 57b4de4 commit ed179f4
Show file tree
Hide file tree
Showing 4 changed files with 58 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 @@ -53,6 +53,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 @@ -10,6 +10,7 @@ export { default as isNotNull } from './isNotNull';
export { default as isNotNil } from './isNotNil';
export { default as isArray } from './isArray';
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(isNotEmpty, isArray);

export default isNonEmptyArray;
23 changes: 23 additions & 0 deletions test/isNonEmptyArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 ed179f4

Please sign in to comment.