Limit values to a defined range with @compactjs/limit.

Install:

npm install @compactjs/limit

Import:

import { limit } from '@compactjs/limit';

And use:

// hours
limit(25, 24); // returns: 1

// degrees
limit(90 - 180, 360); // returns: 270

Find it on GitHub: https://github.com/CompactJS/limit