Utils is a module of functions, available as the Utils export (import { Utils } from 'formstone') or individually (import { select, on } from 'formstone/utils'). Most functions that take a target accept an element, a NodeList, an HTMLCollection, an array, a Set or any other iterable collection.
Checks if a value is falsey (undefined, false, or null).
Parameters
Name
Type
Description
v
any
The value to check
Returns
Type
Description
boolean
True if the value is undefined, false, or null
.isFn()
Checks if a value is a function.
Parameters
Name
Type
Description
v
any
Value to check
Returns
Type
Description
boolean
True if a function
.isObj()
Checks if a value is an object. Returns false for null.
Parameters
Name
Type
Description
v
any
Value to check
Returns
Type
Description
boolean
True if an object
.isU()
Checks if a value is undefined.
Parameters
Name
Type
Description
v
any
Value to check
Returns
Type
Description
boolean
True if undefined
Objects
.extend()
Extends objects by merging properties from one or more source objects into a new object; the arguments are never modified. A deep merge recurses into plain objects at any depth. Arrays, functions, regular expressions and other non-plain values are copied by reference, not merged. __proto__ keys are ignored.
Iterates over a target and executes a callback for each item. Collections (NodeList, HTMLCollection, array, Set and other iterables) are iterated; a single value, string or DOM node is treated as one item; null, undefined and false items are skipped.
Parameters
Name
Type
Description
target
element|NodeList|HTMLCollection|array|Set|any
The target to iterate over
cb
function
Callback function to execute for each item
.iterable()
Converts a value to an array for iteration. Collections (NodeList, HTMLCollection, array, Set and other iterables) are expanded; a single value, string or DOM node becomes a one-item array (<form> and <select> elements are not expanded into their controls). null, undefined and false items are removed.
Parameters
Name
Type
Description
target
any
The target to convert (element, collection, or any value)
Returns the longest transition (duration + delay) of an element in milliseconds.
Parameters
Name
Type
Description
el
element
The target element
Returns
Type
Description
number
Transition time in milliseconds
.afterTransition()
Executes a callback once an element's transition completes. Runs immediately when the element has no transition (for example with prefers-reduced-motion), and falls back to a timeout because transitionend never fires for 0s, interrupted, or non-rendered transitions. Only transitions on the element itself count; bubbled child transitions are ignored.
Normalizes class name arguments into an array of single class names. Used by the class helpers, so addClass(), removeClass() and hasClass() accept the same forms.
Parameters
Name
Type
Description
...classes
string|array
Class names: separate arguments, space-separated strings, or a single array