Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion helpers/3p/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,61 @@ helpers.avg = function() {
// remove handlebars options object
args.pop();
return exports.sum(args) / args.length;
};
};

/**
* Return the min of `a` and `b`.
* ```handlebars
* {{min 1 5}}
* //=> '1'
* ```
*
* @param {Number} `a`
* @param {Number} `b`
* @api public
*/

helpers.min = function(a, b) {
return a < b ? a : b;
}


/**
* Return the max of `a` and `b`.
* ```handlebars
* {{max 1 5}}
* //=> '5'
* ```
*
* @param {Number} `a`
* @param {Number} `b`
* @api public
*/

helpers.max = function(a, b) {
return a > b ? a : b;
}


/**
* Return the value `test` constrained to the provided `min` and `max`.
* If the value `test` falls outside of the provided `min` or `max`, the respective bounds will be returned instead.
*
* ```handlebars
* {{clamp 3 2 4}}
* //=> '3'
* {{clamp 10 2 4}}
* //=> '4'
* {{clamp -10 2 4}}
* //=> '2'
* ```
*
* @param {Number} `test`
* @param {Number} `min`
* @param {Number} `max`
* @api public
*/

helpers.clamp = function(test, min, max) {
return helpers.max(min, helpers.min(test, max));
}