Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

just-clamp

angus-c10.1kMIT4.2.0TypeScript support: included

restrict a number within a range

clamp, restrict, greater, less, range, number, just

readme

just-clamp

Part of a library of zero-dependency npm modules that do just do one thing. Guilt-free utilities for every occasion.

🍦 Try it

npm install just-clamp
yarn add just-clamp

Restrict a number within a range

import clamp from 'just-clamp';

var n = 5;
clamp(1, n, 12); // 5
clamp(3, n, 1); // 3
clamp(8, n, 9); // 8
clamp(0, n, 0); // 0

var n = -5;
clamp(1, n, 12); // 1
clamp(-7, n, -8); // -7

clamp(NaN, n, 8); // NaN
clamp(3, n, NaN); // NaN  
clamp(3, NaN, 8); // NaN    

clamp(undefined, n, 8); // throws
clamp(3, n, 'h'); // throws  
clamp(3, false, 8); // throws 

changelog

just-clamp

4.2.0

Minor Changes

  • Rename node module .js -> .cjs

4.1.1

Patch Changes

  • fix: reorder exports to set default last #488

4.1.0

Minor Changes

  • package.json updates to fix #467 and #483