lib/utils/assertType.js
function assertArray(attr, data, type) {
  if (data === null || data === undefined) {
    return [];
  }

  if (!Array.isArray(data)) {
    throw new ParseError(`Attribute ${attr} must be of type "array"`);
  }

  const clone = [];

  for (const d of data) {
    if (d !== undefined && d !== null) {
      if (typeof d !== type) {
        throw new ParseError(`Attribute ${attr} must contain only values of type "${type}"`);
      }

      clone.push(d);
    }
  }

  return clone;
}
function assertArray(attr, data, type) {
  if (data === null || data === undefined) {
    return [];
  }

  if (!Array.isArray(data)) {
    throw new ParseError(`Attribute ${attr} must be of type "array"`);
  }

  const clone = [];

  for (const d of data) {
    if (d !== undefined && d !== null) {
      if (typeof d !== type) {
        throw new ParseError(`Attribute ${attr} must contain only values of type "${type}"`);
      }

      clone.push(d);
    }
  }

  return clone;
}
function assertArray ( attr , data , type ) { if ( data === null || data === undefined ) { return [ ] ; } if ( ! Array . isArray ( data ) ) { throw new ParseError ( ` ${ attr } ` ) ; } const clone = [ ] ; for ( const d of data ) { if ( d !== undefined && d !== null ) { if ( typeof d !== type ) { throw new ParseError ( ` ${ attr } ${ type } ` ) ; } clone . push ( d ) ; } } return clone ; }
Throws if the provided data is not an array containing exclusively
values of the specified "type"
Returns a clone of the provided array if valid

@throws
@param {string} attr - tested attribute name
@param {*} data
@return {array}
Throws if the provided data is not an array containing exclusively values of the specified type Returns a clone of the provided array if valid