Skip to content

parseEasing

Reads a CSS easing into an easing function, to play in JavaScript the timing a stylesheet or a design tool export describes. It is the inverse of toCssLinear.

Accepts every CSS <easing-function>:

  • the keywords linear, ease, ease-in, ease-out, ease-in-out, step-start, step-end;
  • cubic-bezier(x1, y1, x2, y2) (see cubicBezier);
  • steps(count[, position]) (see steps);
  • linear(0, 0.25 40%, 1): points with optional input positions, as CSS fills them in.

Case and extra spaces are ignored. The input is clamped to [0, 1].

Available since v3.1.5

import { parseEasing } from '@helpers4/animation';
// or, from the all-in-one package (same code, one install):
import { parseEasing } from 'helpers4/animation';
parseEasing(css: string): function | null
ParameterTypeDescription
cssstringThe CSS easing

function | null — The easing function, or null if css is not a valid CSS easing

Keywords, cubic-bezier(), steps() and linear() are all read.

parseEasing('ease-out')!(0.5)               // => 0.6846...
parseEasing('steps(4, jump-start)')!(0.3)   // => 0.5
parseEasing('linear(0, 0.9 50%, 1)')!(0.25) // => 0.45

Anything that is not a CSS easing gives null.

parseEasing('bounce') // => null

View source on GitHub