Comparing version 0.0.1 to 0.1.0
50
index.js
@@ -7,16 +7,42 @@ /** | ||
module.exports = { | ||
betwee: between, | ||
isBetween: isBetween, | ||
toPrecision: toPrecision, | ||
getPrecision: getPrecision | ||
between: decorate(between), | ||
isBetween: decorate(isBetween), | ||
toPrecision: decorate(toPrecision), | ||
getPrecision: decorate(getPrecision) | ||
}; | ||
/** | ||
* Get fn wrapped with array attrs recognition | ||
* | ||
* @return {Function} Target method recognizing arrays | ||
*/ | ||
function decorate(fn){ | ||
return function(a){ | ||
if (a instanceof Array) { | ||
var result = [], args = arguments, slice; | ||
for (var i = 0; i < a.length; i++){ | ||
slice = []; | ||
for (var j = 0, l = args.length; j < l; j++){ | ||
val = args[j] instanceof Array ? args[j][i] : args[j]; | ||
val = val || 0; | ||
slice.push(val); | ||
} | ||
result.push(fn.apply(this, slice)); | ||
} | ||
return result; | ||
} else { | ||
return fn.apply(this, arguments); | ||
} | ||
}; | ||
} | ||
/** | ||
* Clamper | ||
* Clamper. | ||
* Detects proper clamp min/max. | ||
* | ||
* @param {number} a Current value to cut off | ||
* @param {number} min Left limit | ||
* @param {number} max Right limit | ||
* @param {number} min One side limit | ||
* @param {number} max Other side limit | ||
* | ||
@@ -27,3 +53,3 @@ * @return {number} Clamped value | ||
function between(a, min, max){ | ||
return max > min ? Math.max(Math.min(a,max),min) : Math.max(Math.min(a,min),max) | ||
return max > min ? Math.max(Math.min(a,max),min) : Math.max(Math.min(a,min),max); | ||
} | ||
@@ -57,8 +83,8 @@ | ||
* @example | ||
* round(213.34, 1) == 213 | ||
* round(213.34, .1) == 213.3 | ||
* round(213.34, 10) == 210 | ||
* toPrecision(213.34, 1) == 213 | ||
* toPrecision(213.34, .1) == 213.3 | ||
* toPrecision(213.34, 10) == 210 | ||
*/ | ||
function round(value, step) { | ||
function toPrecision(value, step) { | ||
step = parseFloat(step); | ||
@@ -65,0 +91,0 @@ if (step === 0) return value; |
{ | ||
"name": "mumath", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Micro math methods: isBetween, between, getPrecition, toPrecision", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2725
94