<commit_before>'use strict'
module.exports = limitSpec




/**
 * Set limit spec
 *
 * @see http://druid.io/docs/0.6.120/LimitSpec.html
 * @param {string} [type=default] Type of LimitSpec
 * @param {number} limit Limit of records
 * @param {object[]} orderByColumns
 * returns {object}
 */
function limitSpec(type, limit, orderByColumns) {
  return {
    type:    type,
    limit:   limit,
    columns: orderByColumns
  }
}<commit_msg>feat(Query/limitSpec): add validations<commit_after>'use strict'

var errors = require('../errors')
  , FieldError = errors.FieldError
  , FieldTypeError = errors.FieldTypeError

module.exports = limitSpec




/**
 * Set limit spec
 *
 * @see http://druid.io/docs/0.6.120/LimitSpec.html
 * @param {string|object} [type=default] Type of LimitSpec or LimitSpec object
 * @param {number} [limit] Limit of records
 * @param {object[]} [orderByColumns] Sorting columns
 * returns {object}
 */
function limitSpec(type, limit, orderByColumns) {
  if (typeof type === 'object') {
    return type
  }

  if (typeof limit !== 'number') {
    limit = parseInt(limit, 10)
  }

  if (type !== 'default') {
    throw new FieldError('Currently only DefaultLimitSpec is supported')
  }
  else if (isNaN(limit)) {
    throw new FieldTypeError('limitSpec.limit', 'number')
  }
  else if (!Array.isArray(orderByColumns) || !orderByColumns.length) {
    throw new FieldTypeError('limitSpec.columns', 'array')
  }

  return {
    type:    type,
    limit:   parseInt(limit, 10),
    columns: orderByColumns
  }
}
{'fraction_non_alphanumeric': 0.13958060288335516, 'fraction_numerical': 0.009174311926605505, 'mean_word_length': 3.7275541795665634, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7185228', 'n_tokens_mistral': 506, 'n_tokens_neox': 486, 'n_words': 127}