Capítulo 147 de 411

Chapter 147: gsap.utils.unitize()

Core Idea

unitize() wraps another function so its result always gets a unit appended (and strips units from the input before calling it).

Reference Tables

ParameterTypeDescription
fnFunctionthe raw-number function to wrap
unitStringdefault "px" — unit to strip on input and re-add on output

Code Examples

let clamp = gsap.utils.unitize(gsap.utils.clamp(0, 100), "px");
clamp(132); // "100px"
  • What it demonstrates: wrapping clamp() (which only understands raw numbers) so it can safely accept and return "px"-suffixed values.

Connects To

  • gsap.utils.wrap() / clamp(): common candidates for wrapping since they operate on raw numbers.