Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clamp utility for clamping a value between two bounds #30

Merged
merged 3 commits into from
Sep 10, 2023
Merged

Conversation

giraugh
Copy link
Owner

@giraugh giraugh commented Sep 10, 2023

/**
 * Return a value that is clamped between two inclusive bounds.
 * @param value the value to clamp
 * @param min the minimum bound
 * @param max the maximum bound
 * @returns returns `value` if within bounds, otherwise the closest bound
 *
 * @example
 * clamp(10, 3, 12) === 10
 * clamp(1, 3, 12) === 3
 * clamp(20, 3, 12) === 12
 */
export const clamp = (value: number, min: number, max: number): number =>
  Math.min(max, Math.max(min, value))

@changeset-bot
Copy link

changeset-bot bot commented Sep 10, 2023

🦋 Changeset detected

Latest commit: da4a9d6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@giraugh/tools Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@giraugh giraugh added the enhancement New feature or request label Sep 10, 2023
@giraugh giraugh self-assigned this Sep 10, 2023
@giraugh giraugh requested a review from GRA0007 September 10, 2023 05:54
@giraugh giraugh merged commit 2d9967a into main Sep 10, 2023
2 checks passed
@giraugh giraugh deleted the feat/clamp branch September 10, 2023 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants