@bluehexagons/easing
Small, dependency-free easing functions for JavaScript and TypeScript. The package ships tree-shakeable ESM, CommonJS, and declarations for both module systems.

Install
npm install https://codeload.github.com/bluehexagons/easing/tar.gz/refs/tags/v0.6.0
Use
import { createElasticInOut, cubicBezier, ease, quadInOut, spring } from '@bluehexagons/easing';
quadInOut(0.5); // 0.5
ease(quadInOut, 0.5, 20, 100); // 60
cubicBezier(0.25, 0.1, 0.25, 1); // CSS `ease`
createElasticInOut({ amplitude: 1.5, period: 0.4 });
spring({ stiffness: 120, damping: 14 });
CommonJS uses the same API:
const { ease, quadInOut } = require('@bluehexagons/easing');
Easing functions accept normalized time, usually from 0 to 1. Values outside that range are extrapolated when the curve's math permits it. Overshooting curves can return values outside [0, 1]; wrap one with clamp() when that is undesirable.
API
The built-in families are sine, quad, cubic, quart, quint, expo, circ, back, bounce, and elastic. Each provides In, Out, and InOut variants, such as cubicIn, cubicOut, and cubicInOut. linear is also included.
| Function |
Purpose |
ease(fn, time, from, to) |
Ease between two numeric values. |
lerp(time, from, to) |
Linearly interpolate between two values. |
smoothstep(time) / smootherstep(time) |
Smooth polynomial curves with zero endpoint velocity, or zero endpoint velocity and acceleration. |
hermite(options?) |
Create a cubic curve with configurable endpoint slopes. |
inOut(time, first, second) |
Apply a different curve to each half. |
combineInOut(first, second) |
Create the reusable form of inOut. |
reverse(fn) |
Reverse a curve in time and value. |
clamp(fn, min?, max?) |
Clamp a curve's output; defaults to [0, 1]. |
compose(outer, inner) |
Apply one curve after another. |
mix(first, second, weight?) |
Blend two curves by output value. |
repeat(fn, count) / alternate(fn, count) |
Repeat a curve, optionally reversing every other cycle. |
piecewiseLinear(points) |
Create a curve by linearly interpolating normalized stops. |
monotoneSpline(points) |
Create a smooth, shape-preserving curve from normalized stops. |
invert(fn, options?) |
Create an inverse lookup for a continuous, strictly monotonic curve. |
createElasticIn/Out/InOut(options?) |
Configure an elastic curve once. Amplitude must be at least 1; period must be positive. |
cubicBezier(x1, y1, x2, y2) |
Create a CSS-compatible cubic Bézier curve. The x controls must be in [0, 1]. |
steps(count, position?) |
Create a stepped curve using start or end positioning. |
spring(options?) |
Create a normalized damped spring with mass, stiffness, damping, velocity, and duration-in-seconds controls. |
Every reusable curve has the type (time: number) => number, exported as EasingFunction.
Piecewise constructors accept points in either [[time, value], ...] or [{ at, value }, ...] form; times must start at 0, end at 1, and be strictly increasing. monotoneSpline additionally requires non-decreasing values. invert uses bisection and throws when its input is outside the curve's endpoint value range.
repeat wraps at each cycle boundary and preserves the wrapped curve's final endpoint at time 1; alternate reverses the curve on every other cycle, so its final value depends on whether the final cycle is forward or reversed.
For configuration-driven animation, import the parameter-free registry separately:
import { easings, type EasingName } from '@bluehexagons/easing/named';
const name: EasingName = 'bounceOut';
const value = easings[name](0.5);
Development
npm ci
npm run check
The gate builds both package formats, checks runtime and consumer types,
verifies the committed curve gallery, and runs release-tool tests, lint and
formatting. Run npm run docs:curves only to intentionally regenerate the
gallery after a curve or gallery change.
Runtime assertions report the curve and sample on failure. To investigate a
release-tool failure without rebuilding the package, filter its Node suite:
node --test --test-reporter=spec --test-timeout=10000 --test-name-pattern='unpublished' scripts/release.test.mjs
Releases are created with npm run release after updating the version. GitHub Actions verifies the supported Node versions.
Derived from Easie and Robert Penner's easing equations. Licensed under Apache-2.0.