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