ChattyServer/lib/validator.js
/**
* Checks if the given data set a valid for a certain property.
* @example
*   isValidEventData('register', {userName:'Henk', publicKey:'sdfdrgdfgdsfgdgdfg'}) -> true
*   isValidEventData('register', {userName:'Henk'}) -> false (missing the publicKey property)
*
* @param {string} eventName - The name of the socket.IO event
* @param {object} data - The data retrieved from the client
* @return True wen the given data contains the right properties or false then the data is incomplete
*/
Checks if the given data set a valid for a certain property.
Checks if the given data set a valid for a certain property .
function isValidEventData(eventName, data)
{
  var eventDataProps = validatorList[eventName]
  if(eventDataProps.length === 0)
  {
    return data !== null
  }
  else
  {
    var dataIsValid = eventDataProps.every(function(eventProp)
    {
      return eventProp in data
    })
    return dataIsValid
  }
}
function isValidEventData ( eventName , data ) { var eventDataProps = validatorList [ eventName ] if ( eventDataProps . length === 0 ) { return data !== null } else { var dataIsValid = eventDataProps . every ( function ( eventProp ) { return eventProp in data } ) return dataIsValid } }
Checks if the given data set a valid for a certain property.
Checks if the given data set a valid for a certain property .