src/utils.js
/**
 * Validates the attributes object against the constraints.
 * The attributes must be a plain object or a form element, things like backbone models etc are not
 * supported. See https://validatejs.org/#constraints for constraints details.
 *
 * @param {object} attributes The attributes to validate.
 * @param {object} constraints The constraints object.
 * @returns {object} An object of array of error messages or `undefined` if no error found.
 */
Validates the attributes object against the constraints.
The attributes must be a plain object or a form element, things like backbone models etc are not
supported.

@param {object} attributes The attributes to validate.
@param {object} constraints The constraints object.
@returns {object} An object of array of error messages or `undefined` if no error found.
Validates the attributes object against the constraints . The attributes must be a plain object or a form element things like backbone models etc are not supported . @param { object } attributes The attributes to validate . @param { object } constraints The constraints object . @returns { object } An object of array of error messages or ` undefined ` if no error found .
function validate(attributes, constraints) {
  const unknownKeys = difference(Object.keys(attributes), Object.keys(constraints));
  const unknownErrs = unknownKeys.length > 0
    ? Object.fromEntries(unknownKeys.map((key) => [key, ['is unknown key']]))
    : undefined;
  const validationErrs = validatejs(attributes, constraints, { fullMessages: false });
  if (isNil(validationErrs) && isNil(unknownErrs)) {
    return undefined;
  }
  if (!isNil(validationErrs) && !isNil(unknownErrs)) {
    return merge(validationErrs, unknownErrs);
  }
  if (!isNil(validationErrs)) {
    return validationErrs;
  }
  return unknownErrs;
}
function validate ( attributes , constraints ) { const unknownKeys = difference ( Object . keys ( attributes ) , Object . keys ( constraints ) ) ; const unknownErrs = unknownKeys . length > 0 ? Object . fromEntries ( unknownKeys . map ( ( key ) => [ key , [ 'is unknown key' ] ] ) ) : undefined ; const validationErrs = validatejs ( attributes , constraints , { fullMessages : false } ) ; if ( isNil ( validationErrs ) && isNil ( unknownErrs ) ) { return undefined ; } if ( ! isNil ( validationErrs ) && ! isNil ( unknownErrs ) ) { return merge ( validationErrs , unknownErrs ) ; } if ( ! isNil ( validationErrs ) ) { return validationErrs ; } return unknownErrs ; }
Validates the attributes object against the constraints.
Validates the attributes object against the constraints .