Skip to content

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

CategoryContents
Type guardsisString, isNumber, isObject, isDefined, …
Stringscase conversion, leading and trailing characters
Mathclamp, lerp, map, wrap, fold, round, mean, createRange
Easingsthe 24 easing functions, createEaseOut, createEaseInOut
Motiondamp, spring, smoothTo, the inertia family
CSStransform, matrix, getOffsetSizes, setClassesOrStyles
Transitionstransition, enterTransition, leaveTransition
DOMcreateElement, selectorFor
FocustrapFocus, untrapFocus, saveActiveElement
ScrollscrollTo, scrollPosition, lockScroll
HistoryhistoryPush, historyReplace, objectToURLSearchParams
LoadingloadImage, loadScript, loadLink
Timingdebounce, throttle, wait, memo, noop
Objects & randomdeepmerge, random, randomInt, randomItem

What v3 shipped and v4 does not

RemovedBecause
tween, animatetime-based playback moves to a separate ui-animation package
domScheduler, useSchedulerone scheduler is the clock
Queue, SmartQueuethe scheduler's lanes replace them
the collision helpersnot ported
keyCodesuseKey() delivers named booleans, so nothing is left to compare against
nextTick, nextMicrotaskawait Promise.resolve() and queueMicrotask() say it
isEmpty, isEmptyString, isArray, isDevthe platform or a one-liner says it
cache, memoizememo covers the one case core needed
addClass, removeClass, toggleClass, addStyle, removeStyleclassList and style say it
loadIframe, loadElementnot 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.

MIT Licensed