diff --git a/src/index.d.ts b/src/index.d.ts index 38e9c2c43c..80acfee8f8 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -38,6 +38,11 @@ declare namespace RamdaAdjunct { */ isArray(val: any): val is Array; + /** + * Checks if input value is an empty `Array`. + */ + isEmptyArray(val: any): val is Array; + /** * Checks if input value is `Boolean`. */ diff --git a/src/index.js b/src/index.js index 0daf9b6afd..1dc068a0d4 100644 --- a/src/index.js +++ b/src/index.js @@ -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'; diff --git a/src/isEmptyArray.js b/src/isEmptyArray.js new file mode 100644 index 0000000000..e69cda3df5 --- /dev/null +++ b/src/isEmptyArray.js @@ -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; diff --git a/test/isEmptyArray.js b/test/isEmptyArray.js new file mode 100644 index 0000000000..086a43de39 --- /dev/null +++ b/test/isEmptyArray.js @@ -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); + }); +});