lib/utils/assertType.js
function assertUniTypeObject(attr, data, type) {
  data = assertObject(attr, data);

  if (data === null) {
    return null;
  }

  Object.keys(data).forEach(key => {
    if (type === undefined) {
      type = typeof data[key];
    }
    type = type.toLowerCase();

    let msg = `Attribute ${attr} must be of type "object" and have all its properties of type ${type}.`
      + `\nExpected "${attr}.${key}" to be of type "${type}", but go "${typeof data[key]}".`;

    switch (type) {
      case 'array':
        if (!Array.isArray(data[key])) {
          throw new ParseError(msg);
        }
        break;
      default:
        if (typeof data[key] !== type) {
          throw new ParseError(msg);
        }
        break;
    }

  });

  return data;
}
function assertUniTypeObject(attr, data, type) {
  data = assertObject(attr, data);

  if (data === null) {
    return null;
  }

  Object.keys(data).forEach(key => {
    if (type === undefined) {
      type = typeof data[key];
    }
    type = type.toLowerCase();

    let msg = `Attribute ${attr} must be of type "object" and have all its properties of type ${type}.`
      + `\nExpected "${attr}.${key}" to be of type "${type}", but go "${typeof data[key]}".`;

    switch (type) {
      case 'array':
        if (!Array.isArray(data[key])) {
          throw new ParseError(msg);
        }
        break;
      default:
        if (typeof data[key] !== type) {
          throw new ParseError(msg);
        }
        break;
    }

  });

  return data;
}
function assertUniTypeObject ( attr , data , type ) { data = assertObject ( attr , data ) ; if ( data === null ) { return null ; } Object . keys ( data ) . forEach ( key => { if ( type === undefined ) { type = typeof data [ key ] ; } type = type . toLowerCase ( ) ; let msg = ` ${ attr } ${ type } ` + ` \n ${ attr } ${ key } ${ type } ${ typeof data [ key ] } ` ; switch ( type ) { case 'array' : if ( ! Array . isArray ( data [ key ] ) ) { throw new ParseError ( msg ) ; } break ; default : if ( typeof data [ key ] !== type ) { throw new ParseError ( msg ) ; } break ; } } ) ; return data ; }
Throws if the provided object is not an object or if it contains heterogeaous typed properties.
Returns the unmodified data if validated.

@throws {ParseError}
@param {string} attr - tested attribute name
@param {*} data
@param {string} [type] - expected type for data properties
@returns {object|null}
Throws if the provided object is not an object or if it contains heterogeaous typed properties . Returns the unmodified data if validated .