clamp.js 459 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. /**
  3. * Copyright (c) 2013-present, Facebook, Inc.
  4. *
  5. * This source code is licensed under the MIT license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. *
  8. *
  9. * @typechecks
  10. */
  11. /**
  12. * Clamps (or clips or confines) the value to be between min and max.
  13. */
  14. function clamp(value, min, max) {
  15. if (value < min) {
  16. return min;
  17. }
  18. if (value > max) {
  19. return max;
  20. }
  21. return value;
  22. }
  23. module.exports = clamp;