Utils

Animatry provides a set of general-purpose utility functions to simplify your animation logic.
These are accessible directly from animatry and work independently of animations.

Example

Here's how to clamp and round values:

const x = animatry.clamp(1.2, 0, 1); // 1
const y = animatry.round(3.14159, 2); // 3.14

Math utilities

Function
Description
clamp(number, min, max)
Restricts a number between min and max.
round(value, decimals)
Rounds to a given number of decimal places.
lerp(a, b, t)
Linearly interpolates between two values (0 ≤ t ≤ 1).
random(min, max)
Returns a random float between min and max.
shuffle(array)
Shuffles an array in place.
isEven(n)
Returns true if n is even.
isOdd(n)
Returns true if n is odd.

DOM utilities

Function
Description
select(selector)
Selects elements (supports CSS, arrays, and NodeLists).
selectCss(property, value, root)
Selects elements by a CSS property and value.
getParent(el)
Returns the parent of a given element.
pageReady(callback)
Runs a function once the page has fully loaded.

Logic & strings

Function
Description
pipeline(...fns)
Chains multiple functions: output of one is input of next.
filterObjects(obj, filter)
Splits an object into matching and non-matching parts.
camelToKebab(str)
Converts a camelCase string to kebab-case.

Encapsulation

Function
Description
encapsulate(element, className)
Wraps the element in a shadow-style div with a class. Useful for scoping.

Logging

Function
Description
log(message)
Prints a formatted Animatry log message.
warn(message)
Prints a formatted Animatry warning.