aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils/numbers.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2019-06-01 19:55:14 +1000
committerSam Potts <sam@potts.es>2019-06-01 19:55:14 +1000
commit12c6282d14e3e06a7784760f83affc9195afed1f (patch)
treeaf1c6be692c4cf2679e7efc604896b686974368d /src/js/utils/numbers.js
parent996075decc6e8c0f0c5059dccea21b16020eb78b (diff)
parent0249772f019762ebd494ac409e597103820413c3 (diff)
downloadplyr-12c6282d14e3e06a7784760f83affc9195afed1f.tar.lz
plyr-12c6282d14e3e06a7784760f83affc9195afed1f.tar.xz
plyr-12c6282d14e3e06a7784760f83affc9195afed1f.zip
Merge branch 'develop' into css-variables
# Conflicts: # .eslintrc # demo/dist/demo.css # demo/dist/demo.js # demo/dist/demo.min.js # demo/dist/demo.min.js.map # dist/plyr.css # dist/plyr.js # dist/plyr.min.js # dist/plyr.min.js.map # dist/plyr.min.mjs # dist/plyr.min.mjs.map # dist/plyr.mjs # dist/plyr.polyfilled.js # dist/plyr.polyfilled.min.js # dist/plyr.polyfilled.min.js.map # dist/plyr.polyfilled.min.mjs # dist/plyr.polyfilled.min.mjs.map # dist/plyr.polyfilled.mjs # gulpfile.js # package.json
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 };