diff options
author | Sam Potts <sam@potts.es> | 2020-01-30 14:23:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-30 14:23:10 +0000 |
commit | 9d512911252cf4835c2b7364cb4ae392cb277a1d (patch) | |
tree | 5e6dcc7647285e49683f05d8a49187e8078d0d2b /src/js/utils/numbers.js | |
parent | 44d3a17870949e828e5b1a4619a30dfcb626a174 (diff) | |
parent | b2ac730572ad81aa9755e8b7852c53ceba0e8e9f (diff) | |
download | plyr-9d512911252cf4835c2b7364cb4ae392cb277a1d.tar.lz plyr-9d512911252cf4835c2b7364cb4ae392cb277a1d.tar.xz plyr-9d512911252cf4835c2b7364cb4ae392cb277a1d.zip |
Merge pull request #1663 from sampotts/master
Merge back to beta
Diffstat (limited to 'src/js/utils/numbers.js')
-rw-r--r-- | src/js/utils/numbers.js | 17 |
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 }; |