aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils/numbers.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2019-04-25 12:11:06 +1000
committerGitHub <noreply@github.com>2019-04-25 12:11:06 +1000
commite644eeb5b62e6e2eb915d5915cb65ba8af88c05e (patch)
tree60f96b088ce8490429199163a5e71768b8a9b52c /src/js/utils/numbers.js
parent2bd08cdc28bf55b7f7a169b02eb288d7b197b8d6 (diff)
parent5ddd9e02def654bb677c988403dbefbc4a32787c (diff)
downloadplyr-e644eeb5b62e6e2eb915d5915cb65ba8af88c05e.tar.lz
plyr-e644eeb5b62e6e2eb915d5915cb65ba8af88c05e.tar.xz
plyr-e644eeb5b62e6e2eb915d5915cb65ba8af88c05e.zip
Merge pull request #1423 from sampotts/develop
v3.5.4
Diffstat (limited to 'src/js/utils/numbers.js')
-rw-r--r--src/js/utils/numbers.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/js/utils/numbers.js b/src/js/utils/numbers.js
new file mode 100644
index 00000000..f6eb65c8
--- /dev/null
+++ b/src/js/utils/numbers.js
@@ -0,0 +1,17 @@
+/**
+ * Returns a number whose value is limited to the given range.
+ *
+ * Example: limit the output of this computation to between 0 and 255
+ * (x * 255).clamp(0, 255)
+ *
+ * @param {Number} input
+ * @param {Number} min The lower boundary of the output range
+ * @param {Number} max The upper boundary of the output range
+ * @returns A number in the range [min, max]
+ * @type Number
+ */
+export function clamp(input = 0, min = 0, max = 255) {
+ return Math.min(Math.max(input, min), max);
+}
+
+export default { clamp };