<commit_before>import restify from 'restify';


export default async function validate (data) {
  if (!data.name) {
    throw new restify.errors.BadRequestError('Please inform your name.');
  }

  if (!data.email || !validateEmail(data.email)) {
    throw new restify.errors.BadRequestError('Your email address seems not to be valid.');
  }

  if (!data.subject) {
    throw new restify.errors.BadRequestError('Please inform your subject.');
  }

  if (!data.content) {
    throw new restify.errors.BadRequestError('Please inform your message.');
  }
}


function validateEmail (email) {
  const regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  return regex.test(email);
}<commit_msg>Validate properties length<commit_after>import restify from 'restify';


const SAFE_LENGTH = 5000;


export default async function validate (data) {
  if (!data.name) {
    throw new restify.errors.BadRequestError('Please inform your name.');
  }

  if (!data.email || !validateEmail(data.email)) {
    throw new restify.errors.BadRequestError('Your email address seems not to be valid.');
  }

  if (!data.subject) {
    throw new restify.errors.BadRequestError('Please inform your subject.');
  }

  if (!data.content) {
    throw new restify.errors.BadRequestError('Please inform your message.');
  }

  const isBigMessage = Object
    .keys(data)
    .filter(key => data[key].length > SAFE_LENGTH)
    .length > 0;

  if (isBigMessage) {
    throw new restify.errors.BadRequestError('Your message is too big for me.');
  }
}


function validateEmail (email) {
  const regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  return regex.test(email);
}
{'fraction_non_alphanumeric': 0.23875802997858672, 'fraction_numerical': 0.023019271948608137, 'mean_word_length': 3.626237623762376, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2993093', 'n_tokens_mistral': 700, 'n_tokens_neox': 682, 'n_words': 135}