1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  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.  * @flow
    
  8.  */
    
  9. 
    
  10. export function clamp(min: number, max: number, value: number): number {
    
  11.   if (Number.isNaN(min) || Number.isNaN(max) || Number.isNaN(value)) {
    
  12.     throw new Error(
    
  13.       `Clamp was called with NaN. Args: min: ${min}, max: ${max}, value: ${value}.`,
    
  14.     );
    
  15.   }
    
  16.   return Math.min(max, Math.max(min, value));
    
  17. }