wrap

Wraps a number when it breaches the defined range.

Import

import { wrap } from '@popmotion/popcorn';

Usage

wrap accepts a range, defined as a min and max.

When a third number is provided:

  • If it lies within the range, it is returned.
  • If it lies outside the range, it is wrapped back around:
wrap(0, 1, 0.5); // 0.5
wrap(0, 1, 1.5); // 0.5

Types

wrap(min: number, max: number, v: number): number;
wrap(min: number, max: number) => (v: number) => number;