Socket
Socket
Sign inDemoInstall

@react-stately/utils

Package Overview
Dependencies
Maintainers
2
Versions
783
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-stately/utils - npm Package Compare versions

Comparing version 3.0.0-nightly.870 to 3.0.0-nightly.877

33

dist/main.js

@@ -113,27 +113,14 @@ var {

function roundToStep(value, step) {
if (!isNaN(step)) {
// have to avoid Math.round(num / multiple) * multiple; because it can give results like "0.3000000000000004" for Round(.2 + .1, .1)
let diff = Math.abs(value % step);
function snapValueToStep(value, min, max, step) {
let remainder = (value - (isNaN(min) ? 0 : min)) % step;
let snappedValue = Math.abs(remainder) * 2 >= step ? value + Math.sign(remainder) * (step - Math.abs(remainder)) : value - remainder;
if (value >= 0) {
return diff > step / 2 ? value - diff + step : value - diff;
} else {
return diff > step / 2 ? value + diff - step : value + diff;
if (!isNaN(min)) {
if (snappedValue < min) {
snappedValue = min;
} else if (!isNaN(max) && snappedValue > max) {
snappedValue = min + Math.floor((max - min) / step) * step;
}
}
return value;
}
exports.roundToStep = roundToStep;
function snapValueToStep(value, min, max, step) {
let remainder = (value - min) % step;
let snappedValue = Math.abs(remainder) * 2 >= step ? value - Math.abs(remainder) + step : value - remainder;
if (snappedValue < min) {
snappedValue = min;
} else if (snappedValue > max) {
snappedValue = min + Math.floor((max - min) / step) * step;
} else if (!isNaN(max) && snappedValue > max) {
snappedValue = Math.floor(max / step) * step;
} // correct floating point behavior by rounding to step precision

@@ -140,0 +127,0 @@

@@ -103,24 +103,14 @@ import { useCallback, useRef, useState } from "react";

}
export function roundToStep(value, step) {
if (!isNaN(step)) {
// have to avoid Math.round(num / multiple) * multiple; because it can give results like "0.3000000000000004" for Round(.2 + .1, .1)
let diff = Math.abs(value % step);
export function snapValueToStep(value, min, max, step) {
let remainder = (value - (isNaN(min) ? 0 : min)) % step;
let snappedValue = Math.abs(remainder) * 2 >= step ? value + Math.sign(remainder) * (step - Math.abs(remainder)) : value - remainder;
if (value >= 0) {
return diff > step / 2 ? value - diff + step : value - diff;
} else {
return diff > step / 2 ? value + diff - step : value + diff;
if (!isNaN(min)) {
if (snappedValue < min) {
snappedValue = min;
} else if (!isNaN(max) && snappedValue > max) {
snappedValue = min + Math.floor((max - min) / step) * step;
}
}
return value;
}
export function snapValueToStep(value, min, max, step) {
let remainder = (value - min) % step;
let snappedValue = Math.abs(remainder) * 2 >= step ? value - Math.abs(remainder) + step : value - remainder;
if (snappedValue < min) {
snappedValue = min;
} else if (snappedValue > max) {
snappedValue = min + Math.floor((max - min) / step) * step;
} else if (!isNaN(max) && snappedValue > max) {
snappedValue = Math.floor(max / step) * step;
} // correct floating point behavior by rounding to step precision

@@ -127,0 +117,0 @@

@@ -6,5 +6,4 @@ export function useControlledState<T>(value: T, defaultValue: T, onChange: (value: T, ...args: any[]) => void): [T, (value: T | ((prevState: T) => T), ...args: any[]) => void];

export function clamp(value: number, min?: number, max?: number): number;
export function roundToStep(value: number, step: number): number;
export function snapValueToStep(value: number, min: number, max: number, step: number): number;
//# sourceMappingURL=types.d.ts.map
{
"name": "@react-stately/utils",
"version": "3.0.0-nightly.870+3706c6a5",
"version": "3.0.0-nightly.877+cbaffb3e",
"description": "Spectrum UI components in React",

@@ -28,3 +28,3 @@ "license": "Apache-2.0",

},
"gitHead": "3706c6a504192bf7cb547467671e3c760b0dd14e"
"gitHead": "cbaffb3e7e94f5000c42d9153548021907250dee"
}

@@ -21,25 +21,16 @@ /*

export function roundToStep(value: number, step: number): number {
if (!isNaN(step)) {
// have to avoid Math.round(num / multiple) * multiple; because it can give results like "0.3000000000000004" for Round(.2 + .1, .1)
let diff = Math.abs(value % step);
if (value >= 0) {
return diff > (step / 2) ? (value - diff + step) : value - diff;
} else {
return diff > (step / 2) ? (value + diff - step) : value + diff;
}
}
return value;
}
export function snapValueToStep(value: number, min: number, max: number, step: number): number {
let remainder = ((value - min) % step);
let remainder = ((value - (isNaN(min) ? 0 : min)) % step);
let snappedValue = Math.abs(remainder) * 2 >= step
? (value - Math.abs(remainder)) + step
? value + Math.sign(remainder) * (step - Math.abs(remainder))
: value - remainder;
if (snappedValue < min) {
snappedValue = min;
} else if (snappedValue > max) {
snappedValue = min + Math.floor((max - min) / step) * step;
if (!isNaN(min)) {
if (snappedValue < min) {
snappedValue = min;
} else if (!isNaN(max) && snappedValue > max) {
snappedValue = min + Math.floor((max - min) / step) * step;
}
} else if (!isNaN(max) && snappedValue > max) {
snappedValue = Math.floor(max / step) * step;
}

@@ -46,0 +37,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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