clamp.js.flow 506 B

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