Numeric Range Normalization Utility

0.1.2 · abandoned · verified Sun Apr 19

normalize-range is a utility package designed to normalize numeric values within specified ranges, particularly useful for applications involving cyclical systems like angles or polar coordinates. The current stable version is 0.1.2, released approximately 8 years ago, indicating the package is no longer actively maintained. Its core functionality includes `wrap` for values that "wrap around" (e.g., 361 degrees becoming 1 degree in a 0-360 range), `limit` for clamping values within a fixed inclusive range, `test` for range checking, `validate` for asserting values within a range, and `curry` for creating partially applied range functions. A key differentiator is its explicit handling of inclusive/exclusive range boundaries, which differs between `wrap` and `limit` operations, providing precise control for various normalization scenarios.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core `wrap` and `limit` functions, along with the `curry` utility for creating partially applied range functions, showcasing how to normalize values in both cyclical and bounded ranges.

const nr = require('normalize-range');

console.log('Wrapping 400 in (0, 360):', nr.wrap(0, 360, 400));
//=> 40
console.log('Wrapping -90 in (0, 360):', nr.wrap(0, 360, -90));
//=> 270
console.log('Limiting 500 in (0, 100):', nr.limit(0, 100, 500));
//=> 100
console.log('Limiting -20 in (0, 100):', nr.limit(0, 100, -20));
//=> 0

// Currying example for convenience
const wrapAngle = nr.curry(0, 360).wrap;
const limitTo10 = nr.curry(0, 10).limit;

console.log('Curried wrapAngle(-30):', wrapAngle(-30));
//=> 330
console.log('Curried limitTo10(15):', limitTo10(15));
//=> 10

view raw JSON →