<commit_before>const ObjectID = require('mongodb').ObjectID;

const getString = (value) => {
  return value
    ? value.toString()
    : '';
}

const getDateIfValid = (value) => {
  const date = Date.parse(value);
  return isNaN(date)
    ? null
    : new Date(date);
}

const getArrayIfValid = (value) => {
  return Array.isArray(value)
    ? value
    : null;
}

const getArrayOfObjectID = (value) => {
  if(Array.isArray(value) && value.length > 0) {
    return value.map(id => getObjectIDIfValid(id)).filter(id => !!id);
  } else {
    return [];
  }
}

const getNumberIfValid = (value) => {
  const n = parseFloat(value);
  return n
    ? n
    : null;
}

const getNumberIfPositive = (value) => {
  const n = parseFloat(value);
  return n >= 0
    ? n
    : null;
}

const getBooleanIfValid = (value, defaultValue = null) => {
  if(value === "true" || value === "false") {
    return value === "true";
  } else {
    return (typeof value === 'boolean') ? value : defaultValue;<commit_msg>Refactoring number check<commit_after>const ObjectID = require('mongodb').ObjectID;

const getString = (value) => {
  return value
    ? value.toString()
    : '';
}

const getDateIfValid = (value) => {
  const date = Date.parse(value);
  return isNaN(date)
    ? null
    : new Date(date);
}

const getArrayIfValid = (value) => {
  return Array.isArray(value)
    ? value
    : null;
}

const getArrayOfObjectID = (value) => {
  if(Array.isArray(value) && value.length > 0) {
    return value.map(id => getObjectIDIfValid(id)).filter(id => !!id);
  } else {
    return [];
  }
}

const isNumber = value => {
  return !isNaN(parseFloat(value)) && isFinite(value);
}

const getNumberIfValid = value => {
  return isNumber(value)
    ? parseFloat(value)
    : null;
}

const getNumberIfPositive = (value) => {
  const n = getNumberIfValid(value);
  return n && n >= 0
    ? n
    : null;
}

const getBooleanIfValid = (value, defaultValue = null) => {
  if(value === "true" || value === "false") {
    return value === "true";
  } else {
    return (typeof value === 'boolean') ? value : defaultValue;
{'fraction_non_alphanumeric': 0.16594930655188905, 'fraction_numerical': 0.001912960306073649, 'mean_word_length': 3.278118609406953, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '5080664', 'n_tokens_mistral': 719, 'n_tokens_neox': 713, 'n_words': 163}