Utils
js
import { clamp, damp } from '@studiometa/js-toolkit/utils';Every one of them also has a subpath of its own:
js
import { clamp } from '@studiometa/js-toolkit/utils/clamp';With a bundler, prefer the barrel — tree-shaking removes what you do not import. From an ESM CDN with no build step, prefer the subpath: there is no bundler to shake the graph.
The categories
| Category | Contents |
|---|---|
| Type guards | isString, isNumber, isObject, isDefined, … |
| Strings | case conversion, leading and trailing characters |
| Math | clamp, lerp, map, wrap, fold, round, mean, createRange |
| Easings | the 24 easing functions, createEaseOut, createEaseInOut |
| Motion | damp, spring, smoothTo, the inertia family |
| CSS | transform, matrix, getOffsetSizes, setClassesOrStyles |
| Transitions | transition, enterTransition, leaveTransition |
| DOM | createElement, selectorFor |
| Focus | trapFocus, untrapFocus, saveActiveElement |
| Scroll | scrollTo, scrollPosition, lockScroll |
| History | historyPush, historyReplace, objectToURLSearchParams |
| Loading | loadImage, loadScript, loadLink |
| Timing | debounce, throttle, wait, memo, noop |
| Objects & random | deepmerge, random, randomInt, randomItem |
What v3 shipped and v4 does not
| Removed | Because |
|---|---|
tween, animate | time-based playback moves to a separate ui-animation package |
domScheduler, useScheduler | one scheduler is the clock |
Queue, SmartQueue | the scheduler's lanes replace them |
| the collision helpers | not ported |
keyCodes | useKey() delivers named booleans, so nothing is left to compare against |
nextTick, nextMicrotask | await Promise.resolve() and queueMicrotask() say it |
isEmpty, isEmptyString, isArray, isDev | the platform or a one-liner says it |
cache, memoize | memo covers the one case core needed |
addClass, removeClass, toggleClass, addStyle, removeStyle | classList and style say it |
loadIframe, loadElement | not ported |
How a utility earns its place
It is judged by consumer need, not by core's own use. Some of these are not called anywhere in core — they ship because a component author would otherwise write them again, and getting them wrong is easy. deepmerge is the clearest case.
The reverse also holds: a function core happens to use internally is not public for that reason alone.