New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

just-clamp

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

just-clamp - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

31

index.js

@@ -9,14 +9,29 @@ module.exports = clamp;

clamp(0, n, 0); // 0
n = undefined;
clamp(3, n, 8); // 3
n = null;
clamp(3, n, 8); // 3
n = NaN;
clamp(3, n, 8); // 3
var n = -5;
clamp(1, n, 12); // 1
clamp(-8, n, -7); // -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
*/
function clamp(lower, n, higher) {
if (!Number(n)) {
n = 0;
if (typeof lower != 'number') {
throw new Error('lower boundary must be a number');
}
if (typeof n != 'number') {
throw new Error('number to clamp must be a number');
}
if (typeof higher != 'number') {
throw new Error('higher boundary must be a number');
}
if (Number.isNaN(lower) || Number.isNaN(n) || Number.isNaN(higher)) {
return NaN;
}
if (n < lower) {

@@ -23,0 +38,0 @@ return lower;

{
"name": "just-clamp",
"version": "1.0.0",
"version": "2.0.0",
"description": "restrict a number within a range",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -14,8 +14,14 @@ ## just-clamp

clamp(0, n, 0); // 0
n = undefined;
clamp(3, n, 8); // 3
n = null;
clamp(3, n, 8); // 3
n = NaN;
clamp(3, n, 8); // 3
var n = -5;
clamp(1, n, 12); // 1
clamp(-8, n, -7); // -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
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc