Skip to content

Commit

Permalink
feat: add isEmptyArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume ARM committed Jan 18, 2018
1 parent 57b4de4 commit 30e3366
Show file tree
Hide file tree
Showing 4 changed files with 56 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 @@ -38,6 +38,11 @@ declare namespace RamdaAdjunct {
*/
isArray(val: any): val is Array<any>;

/**
* Checks if input value is an empty `Array`.
*/
isEmptyArray(val: any): val is Array<any>;

/**
* Checks if input value is `Boolean`.
*/
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export { default as isNull } from './isNull';
export { default as isNotNull } from './isNotNull';
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 isBoolean } from './isBoolean';
export { default as isNotBoolean } from './isNotBoolean';
Expand Down
29 changes: 29 additions & 0 deletions src/isEmptyArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { both, isEmpty } from 'ramda';

import isArray from './isArray';


/**
* Checks if input value is an empty `Array`.
*
* @func isEmptyArray
* @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.isNotEmptyArray|isNotEmptyArray}
* @example
*
* RA.isEmptyArray([]); // => true
* RA.isEmptyArray([42]); // => false
* RA.isEmptyArray({}); // => false
* RA.isEmptyArray(null); // => false
* RA.isEmptyArray(undefined); // => false
* RA.isEmptyArray(42); // => false
* RA.isEmptyArray('42'); // => false
*/
const isEmptyArray = both(isEmpty, isArray);

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

describe('isEmptyArray', function() {
it('tests a value to be an empty `Array`', function() {
eq(RA.isEmptyArray([]), true);
eq(RA.isEmptyArray(new Array()), true);
eq(RA.isEmptyArray(Array.prototype), true);

eq(RA.isEmptyArray([1]), false);
eq(RA.isEmptyArray(void 0), false);
eq(RA.isEmptyArray({}), false);
eq(RA.isEmptyArray(null), false);
eq(RA.isEmptyArray(undefined), false);
eq(RA.isEmptyArray(17), false);
eq(RA.isEmptyArray('Array'), false);
eq(RA.isEmptyArray(true), false);
eq(RA.isEmptyArray(false), false);
eq(RA.isEmptyArray({ __proto__: Array.prototype }), false);
});
});

0 comments on commit 30e3366

Please sign in to comment.