remeda
Version:
A utility library for JavaScript and Typescript.
1 lines • 1.55 kB
Source Map (JSON)
{"version":3,"file":"clamp.cjs","names":["purry"],"sources":["../src/clamp.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\ntype Limits = {\n readonly min?: number;\n readonly max?: number;\n};\n\n/**\n * Clamp the given value within the inclusive min and max bounds.\n *\n * @param value - The number.\n * @param limits - The bounds limits.\n * @signature\n * R.clamp(value, { min, max });\n * @example\n * clamp(10, { min: 20 }) // => 20\n * clamp(10, { max: 5 }) // => 5\n * clamp(10, { max: 20, min: 5 }) // => 10\n * @dataFirst\n * @category Number\n */\nexport function clamp(value: number, limits: Limits): number;\n\n/**\n * Clamp the given value within the inclusive min and max bounds.\n *\n * @param limits - The bounds limits.\n * @signature\n * R.clamp({ min, max })(value);\n * @example\n * clamp({ min: 20 })(10) // => 20\n * clamp({ max: 5 })(10) // => 5\n * clamp({ max: 20, min: 5 })(10) // => 10\n * @dataLast\n * @category Number\n */\nexport function clamp(limits: Limits): (value: number) => number;\n\nexport function clamp(...args: ReadonlyArray<unknown>): unknown {\n return purry(clampImplementation, args);\n}\n\nconst clampImplementation = (value: number, { min, max }: Limits): number =>\n min !== undefined && value < min\n ? min\n : max !== undefined && value > max\n ? max\n : value;\n"],"mappings":"wCAsCA,SAAgB,EAAM,GAAG,EAAuC,CAC9D,OAAOA,EAAAA,EAAM,EAAqB,EAAK,CAGzC,MAAM,GAAuB,EAAe,CAAE,MAAK,SACjD,IAAQ,IAAA,IAAa,EAAQ,EACzB,EACA,IAAQ,IAAA,IAAa,EAAQ,EAC3B,EACA"}