TypeScript Easing Functions

0.2.0 · active · verified Sun Apr 19

ts-easing is a lightweight, zero-dependency collection of standard easing functions written entirely in TypeScript. Currently at version 0.2.0, it provides common easing curves like quadratic, cubic, sinusoidal, exponential, and circular, among others. The library is designed for simplicity, accepting a single normalized input `t` in the range `[0, 1]` and returning an eased value also in `[0, 1]`. Due to its stable and self-contained nature, it likely has a very slow or infrequent release cadence, primarily for bug fixes or minor additions rather than frequent feature releases. Its key differentiator is its minimal footprint, strong TypeScript typing, and adherence to the standard easing function interface, making it suitable for animations and transitions in both browser and Node.js environments without external dependencies. It aims to be a straightforward utility for developers needing reliable easing logic for animation or UI interactions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing the `easing` object and using several common easing functions (quadratic, cubic, exponential, sine) at various input `t` values from 0 to 1, showing their output.

import { easing } from 'ts-easing';

// Demonstrating various easing functions at different progress points
const testPoints = [0, 0.25, 0.5, 0.75, 1];

console.log("--- Easing Function Outputs ---");

console.log("\nQuadratic Ease (ease.quadratic):");
testPoints.forEach(t => {
  const easedValue = easing.quadratic(t);
  console.log(`t=${t.toFixed(2)} -> ${easedValue.toFixed(4)}`);
});

console.log("\nCubic Ease (ease.cubic): ");
testPoints.forEach(t => {
  const easedValue = easing.cubic(t);
  console.log(`t=${t.toFixed(2)} -> ${easedValue.toFixed(4)}`);
});

console.log("\nExponential Ease (ease.exponential): ");
testPoints.forEach(t => {
  const easedValue = easing.exponential(t);
  console.log(`t=${t.toFixed(2)} -> ${easedValue.toFixed(4)}`);
});

console.log("\nSine Ease (ease.sine): ");
testPoints.forEach(t => {
  const easedValue = easing.sine(t);
  console.log(`t=${t.toFixed(2)} -> ${easedValue.toFixed(4)}`);
});

// In a real application, these functions would be used inside an animation loop
// For example, to calculate an animated property based on time progress `t`.

view raw JSON →