Home

function: clamp


clamp(number: number, lower: number, upper: number): number

Clamps `number` within the inclusive `lower` and `upper` bounds.

Example(s):

clamp(-10, -5, 5)
// => -5

clamp(10, -5, 5)
// => 5

Params:

Name Type Attribute Description
number The number to clamp.
lower The lower bound.
upper The upper bound.

Returns:

number

  {
    "comment": "/**\r\n * Clamps `number` within the inclusive `lower` and `upper` bounds.\r\n *\r\n * @since 4.0.0\r\n * @category Number\r\n * @param {number} number The number to clamp.\r\n * @param {number} lower The lower bound.\r\n * @param {number} upper The upper bound.\r\n * @returns {number} Returns the clamped number.\r\n * @example\r\n *\r\n * clamp(-10, -5, 5)\r\n * // => -5\r\n *\r\n * clamp(10, -5, 5)\r\n * // => 5\r\n */",
    "meta": {
        "range": [
            394,
            713
        ],
        "filename": "clamp.js",
        "lineno": 18,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100000502",
            "name": "clamp",
            "type": "FunctionDeclaration",
            "paramnames": [
                "number",
                "lower",
                "upper"
            ]
        },
        "vars": {
            "number": "clamp~number",
            "lower": "clamp~lower",
            "upper": "clamp~upper"
        }
    },
    "description": "Clamps `number` within the inclusive `lower` and `upper` bounds.",
    "since": "4.0.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Number",
            "value": "Number"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "description": "The number to clamp.",
            "name": "number"
        },
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "description": "The lower bound.",
            "name": "lower"
        },
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "description": "The upper bound.",
            "name": "upper"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "description": "Returns the clamped number."
        }
    ],
    "examples": [
        "clamp(-10, -5, 5)\r// => -5\r\rclamp(10, -5, 5)\r// => 5"
    ],
    "name": "clamp",
    "longname": "clamp",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000050",
    "___s": true,
    "filepath": "clamp.js"
}