<commit_before>'use strict';

const _ = require('lodash');
const functionName = require('fn-name');

function isNgoose(value) {
  return _.isFunction(value) && functionName(value) === 'ngooseModel';
}

function errField(value, key) {
  const type = _.isFunction(value) ? functionName(value) : value;
  throw new Error('Invalid field ' + key + ':' + type + '. Fields must be type constructors, array or objects.');
}


function checkSupportedTypes(value, key) {
  if (value !== String &&
    value !== Number &&
    value !== Boolean &&
    value !== Date &&
    !isNgoose(value) &&
    key !== '_init'

    ) {

    errField(value, key);
  }
}


function checkSupportedObjectTypes(value, key) {
  /* eslint-disable no-use-before-define */

  if (_.isArray(value)) {

    if (value.length < 1) {
      errField(value, key);
    }


    checkField(value[0], key);
  } else {
    checkFields(value);
  }
}

function checkField(value, key) {


  if (!value) {
    errField();
  }

  if (_.isFunction(value)) {

    checkSupportedTypes(value, key);
  } else {
    if (!_.isObject(value) || _.isRegExp(value) || _.isDate(value)) {
      errField(value, key);
    }

    if (_.isObject(value)) {
      checkSupportedObjectTypes(value, key);

    }
  }
}

function checkFields(definition) {
  _(definition).forEach(checkField);
}

function buildFieldWithDefault(FieldDefinition, instance, fieldName) {
  const defaultValue = FieldDefinition[1];
  const FieldType = FieldDefinition[0];

  if (_.isFunction(defaultValue)) {

    instance[fieldName] = defaultValue.apply(this);

  } else  if (FieldType === Date) {
    instance[fieldName] = new FieldType(defaultValue);
  }  else if (_.isObject(FieldType) && !_.isArray(FieldType) && !_.isFunction(FieldType)) {
    /* eslint-disable no-use-before-define */
    instance[fieldName] = buildInstance(FieldType, defaultValue);

  } else {
    const nativeFieldType = FieldType;
    instance[fieldName] = nativeFieldType(defaultValue);
  }

}

function buildInstance(definition, data) {
  const instance = {};
<commit_msg>code format<commit_after>'use strict';

const _ = require('lodash');
const functionName = require('fn-name');

function isNgoose(value) {
  return _.isFunction(value) && functionName(value) === 'ngooseModel';
}

function errField(value, key) {
  const type = _.isFunction(value) ? functionName(value) : value;
  throw new Error('Invalid field ' + key + ':' + type + '. Fields must be type constructors, array or objects.');
}


function checkSupportedTypes(value, key) {
  if (value !== String &&
    value !== Number &&
    value !== Boolean &&
    value !== Date &&
    !isNgoose(value) &&
    key !== '_init'

    ) {

    errField(value, key);
  }
}


function checkSupportedObjectTypes(value, key) {
  /* eslint-disable no-use-before-define */

  if (_.isArray(value)) {

    if (value.length < 1) {
      errField(value, key);
    }


    checkField(value[0], key);
  } else {
    checkFields(value);
  }
}

function checkField(value, key) {


  if (!value) {
    errField();
  }

  if (_.isFunction(value)) {

    checkSupportedTypes(value, key);
  } else {
    if (!_.isObject(value) || _.isRegExp(value) || _.isDate(value)) {
      errField(value, key);
    }

    if (_.isObject(value)) {
      checkSupportedObjectTypes(value, key);

    }
  }
}

function checkFields(definition) {
  definition.forEach(checkField);
}

function buildFieldWithDefault(FieldDefinition, instance, fieldName) {
  const defaultValue = FieldDefinition[1];
  const FieldType = FieldDefinition[0];

  if (_.isFunction(defaultValue)) {

    instance[fieldName] = defaultValue.apply(this);

  } else  if (FieldType === Date) {
    instance[fieldName] = new FieldType(defaultValue);
  }  else if (_.isObject(FieldType) && !_.isArray(FieldType) && !_.isFunction(FieldType)) {
    /* eslint-disable no-use-before-define */
    instance[fieldName] = buildInstance(FieldType, defaultValue);

  } else {
    const nativeFieldType = FieldType;
    instance[fieldName] = nativeFieldType(defaultValue);
  }

}

function buildInstance(definition, data) {
  const instance = {};

{'fraction_non_alphanumeric': 0.15186176685324895, 'fraction_numerical': 0.0019469457288878072, 'mean_word_length': 3.7025171624713957, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2152812', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1296, 'n_words': 269}