Registry / data / normalize-range

normalize-range

JSON →
library0.1.2jsnpmunverified

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.

npm install normalize-range
INSTALL
IMPORT
SIG · NORMALIZE-RANGE
N
normalize-range
datajavascriptv0.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

normalize-range module
const nr = require('normalize-range');
import nr from 'normalize-range'; // or import * as nr from 'normalize-range';
This package is CommonJS-only and does not provide an ESM export. Direct ESM imports will fail.
wrap function
const { wrap } = require('normalize-range');
import { wrap } from 'normalize-range';
While direct destructuring from `require` is common, the module itself is CommonJS-only and ESM imports are not supported.
curry function
const curryRange = require('normalize-range').curry;
import { curry } from 'normalize-range';
Accessing curried functions or specific methods directly requires `require()` syntax as the package is CommonJS-only.

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
Debug
Known issues
breakingThis package is CommonJS-only and lacks native ES module (ESM) support. Attempting to `import` it directly in an ES module environment will result in errors.
fix
Use dynamic `import('normalize-range').then(nr => ...)` or transpilation if targeting a mixed environment, or ensure your file is a CommonJS module using `require()`.
affects: >=0.1.2
gotchaThe `wrap` function treats the `min` value as inclusive and the `max` value as exclusive (e.g., `wrap(0, 360, 360)` returns `0`). In contrast, the `limit` function treats both `min` and `max` as inclusive.
fix
Carefully review the API documentation for `wrap` and `limit` to ensure correct boundary handling based on your specific use case, especially when dealing with edge values equal to `min` or `max`.
affects: >=0.1.2
deprecatedThe `normalize-range` package is no longer actively maintained. The last commit and release occurred approximately 8 years ago. Consider potential security implications or lack of compatibility with newer JavaScript features or environments.
fix
Evaluate alternative, actively maintained range normalization libraries if long-term support, security updates, or new features are critical. If continuing to use this package, be aware of its unmaintained status.
affects: >=0.1.2
Errors
Common errors & fixes
ReferenceError: require is not defined in ES module scope
Attempting to use `require()` within a JavaScript file that is being treated as an ES module (e.g., due to `"type": "module"` in `package.json` or `.mjs` extension).
fix
If your project is ESM-only, use dynamic import: `import('normalize-range').then(nrModule => { const nr = nrModule; /* ... */ });`. Alternatively, ensure the file using `require()` is a CommonJS module (e.g., `.js` file in a non-module project, or explicitly marked as `"type": "commonjs"`).
TypeError: (0, _normalizeRange.wrap) is not a function
This typically occurs when a bundler or transpiler tries to convert a CommonJS `require` into an ESM `import` in a way that doesn't correctly handle the module's default export, or when directly trying to destructure from an incorrectly imported CJS module.
fix
Ensure that `normalize-range` is imported using the standard CommonJS `require` syntax: `const nr = require('normalize-range');` and then access methods like `nr.wrap(min, max, value)`.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
normalize-range — npm install normalize-range · libregistry