{"size": 1359, "ext": "js", "max_stars_repo_path": "lib/model/constraints/min.js", "max_stars_repo_name": "silverera/bearcat", "max_stars_repo_stars_event_min_datetime": "2015-01-02T14:05:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-30T05:08:05.000Z", "max_issues_repo_path": "lib/model/constraints/min.js", "max_issues_repo_name": "silverera/bearcat", "max_issues_repo_issues_event_min_datetime": "2015-01-07T09:34:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-31T07:28:37.000Z", "max_forks_repo_path": "lib/model/constraints/min.js", "max_forks_repo_name": "silverera/bearcat", "max_forks_repo_forks_event_min_datetime": "2015-01-01T12:04:29.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-23T09:56:19.000Z"}
{"max_stars_count": 419, "max_issues_count": 28, "max_forks_count": 82, "avg_line_length": 25.1666666667, "max_line_length": 85, "alphanum_fraction": 0.5033112583}
/*!
 * .______    _______     ___      .______       ______     ___   .__________.
 * (   _  )  (   ____)   /   \     (   _  )     (      )   /   \  (          )
 * |  |_)  ) |  |__     /  ^  \    |  |_)  )   |  ,----'  /  ^  \ `---|  |---`
 * |   _  <  |   __)   /  /_\  \   |      )    |  |      /  /_\  \    |  |
 * |  |_)  ) |  |____ /  _____  \  |  |)  ----.|  `----./  _____  \   |  |
 * (______)  (_______/__/     \__\ ( _| `.____) (______)__/     \__\  |__|
 *
 * Bearcat MinConstraint
 * Copyright(c) 2015 fantasyni <fantasyni@163.com>
 * MIT Licensed
 */

var Utils = require('../../util/utils');
var Util = require('util');

/**
 * MinConstraint constructor function.
 *
 * @api public
 */
var MinConstraint = function() {
	this.$cid = "min";
	this.message = "[MinConstraint] key: %s value %d is smaller than the min value: %d";
	this.min = null;
}

/**
 * MinConstraint validate function.
 *
 * @param   {String} key
 * @param   {Number} value
 * @return  {Object} Error object
 * @api public
 */
MinConstraint.prototype.validate = function(key, value) {
	var message = this.message;
	var min = this.min;

	if (!Utils.checkNumber(min)) {
		min = parseInt(min);
		this.min = min;
	}

	if (!Utils.checkNumber(value)) {
		return;
	}

	if (value < min) {
		return new Error(Util.format(message, key, value, min));
	}
}

module.exports = MinConstraint;