/**
* @author [Tristan Valcke]{@link https://github.com/Itee}
* @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
*
* @module sources/cores/arrays/isArrayOfObject
* @desc Export function to validate if a value is an array of objects or not
* @example
*
* import { isArrayOfObject } from 'itee-validators'
*
* if( isArrayOfObject( value ) ) {
* //...
* } else {
* //...
* }
*
*/
import { isNotObject } from '../objects/isObject'
import { isNotArray } from './isArray'
import { isEmptyArray } from './isEmptyArray'
/**
* Check if given data is an array where all values are of object type
*
* @param data {*} The data to check against the array of object type
* @returns {boolean} true if data is an array where all values are of object type, false otherwise
*/
export function isArrayOfObject( data ) {
if ( isNotArray( data ) ) { return false }
if ( isEmptyArray( data ) ) { return false }
for ( let index = 0, dataLength = data.length ; index < dataLength ; index++ ) {
if ( isNotObject( data[ index ] ) ) {
return false
}
}
return true
}
/**
* Check if given data is not an array where all values are of object type
*
* @param data {*} The data to check against the array of object type
* @returns {boolean} true if data is not an array where all values are of object type, false otherwise
*/
export function isNotArrayOfObject( data ) {
if ( isNotArray( data ) ) { return true }
if ( isEmptyArray( data ) ) { return true }
for ( let index = 0, dataLength = data.length ; index < dataLength ; index++ ) {
if ( isNotObject( data[ index ] ) ) {
return true
}
}
return false
}