npm package: @splidejs/utils
Description: The collection of utility functions and constructors to share with Splide packages. This is **internal use only**.
Latest version: 1.2.0


# Splide Utils

The collection of utility functions and constructors to share with Splide packages.
This is **internal use only**.


## Quick Reference
 #### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/constructors/EventBinder/EventBinder.ts#L32"><code>EventBinder()</code></a>

The constructor function to provide methods to subscribe native events.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/constructors/EventBus/EventBus.ts#L56"><code>EventBus()</code></a>

Provides the simple event system.
Note that `M` - type for an event map - must have index signature,
but that makes all callback function `AnyFunction`.
To avoid this:
- Use a type alias instead of interface.
- Or do like `EventBus<EventMap & Record<string, AnyFunction>, keyof EventMap>`.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/constructors/EventInterface/EventInterface.ts#L30"><code>EventInterface()</code></a>

The constructor function that provides interface for both internal and native events.
Only the root `EventInterface` instance can destroy all locked instances.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/constructors/RequestInterval/RequestInterval.ts#L28"><code>RequestInterval()</code></a>

Requests interval like the native `setInterval()` with using `requestAnimationFrame`.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/constructors/State/State.ts#L19"><code>State()</code></a>

The function providing a super simple state system.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/constructors/Throttle/Throttle.ts#L22"><code>Throttle()</code></a>

Returns the throttled function.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/math/math/math.ts#L1"><code>abs()</code></a>

Returns the absolute value of a number (the value without regard to whether it is positive or negative).
For example, the absolute value of -5 is the same as the absolute value of 5.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/component/abstractMethod/abstractMethod.ts#L7"><code>abstractMethod()</code></a>

Always throws an error.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/addClass/addClass.ts#L10"><code>addClass()</code></a>

Adds classes to the element.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/append/append.ts#L7"><code>append()</code></a>

Appends children to the parent element.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/function/apply/apply.ts#L11"><code>apply()</code></a>

Create a function where provided arguments are bound.
`this` parameter will be always null.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/math/approximatelyEqual/approximatelyEqual.ts#L13"><code>approximatelyEqual()</code></a>

Checks if the provided 2 numbers are approximately equal or not.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/error/assert/assert.ts#L7"><code>assert()</code></a>

Throws an error when `assertion` is falsy.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/object/assign/assign.ts#L35"><code>assign()</code></a>

The alias of `Object.assign()` with strict type annotation.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/before/before.ts#L7"><code>before()</code></a>

Inserts a node or nodes before the specified reference node.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/math/between/between.ts#L12"><code>between()</code></a>

Checks if the subject number is between `x` and `y`.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/html/buildAttrs/buildAttrs.ts#L20"><code>buildAttrs()</code></a>

Converts attributes provided as an object to a single string.
If boolean is provided, this method treats the attribute as a boolean type.
Use `'true'` or `'false'` (string) when you need to set it as a value.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/string/camelToKebab/camelToKebab.ts#L6"><code>camelToKebab()</code></a>

Converts the provided string in the camel case to the kebab case.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/math/math/math.ts#L1"><code>ceil()</code></a>

Returns the smallest integer greater than or equal to its numeric argument.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/child/child.ts#L12"><code>child()</code></a>

Returns a child element that matches the specified tag or class name.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/children/children.ts#L13"><code>children()</code></a>

Finds children that have the specified tag or class name.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/math/clamp/clamp.ts#L13"><code>clamp()</code></a>

Clamps a number.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/html/classNames/classNames.ts#L14"><code>classNames()</code></a>

Conditionally joins provided class names.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/closest/closest.ts#L9"><code>closest()</code></a>

Starts from the provided element, searches for the first element that matches the selector in ascendants.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/create/create.ts#L7"><code>create()</code></a>

Creates a HTML element.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/display/display.ts#L10"><code>display()</code></a>

Sets the `display` CSS value to the element.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/html/div/div.ts#L14"><code>div()</code></a>

Builds a `div` tag with classes or attributes.
This is a special version of `tag()`.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/array/empty/empty.ts#L6"><code>empty()</code></a>

Empties the array.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/error/error/error.ts#L4"><code>error()</code></a>

The alias of `console.error`.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/arrayLike/find/find.ts#L12"><code>find()</code></a>

The find method for an array or array-like object.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/math/math/math.ts#L1"><code>floor()</code></a>

Returns the greatest integer less than or equal to its numeric argument.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/focus/focus.ts#L10"><code>focus()</code></a>

Focuses the provided element without scrolling the ascendant element.
If providing `null` or an element which is not an instance of `HTMLElement`, this function will do nothing.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/array/forEach/forEach.ts#L10"><code>forEach()</code></a>

The extended `Array#forEach` method that accepts a single value as an argument.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/object/forOwn/forOwn.ts#L13"><code>forOwn()</code></a>

Iterates over the provided object by own enumerable keys with calling the iteratee function.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/string/format/format.ts#L9"><code>format()</code></a>

Replaces `%s` in the provided string with replacements.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/getAttribute/getAttribute.ts#L7"><code>getAttribute()</code></a>

Returns the specified attribute value.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/hasClass/hasClass.ts#L9"><code>hasClass()</code></a>

Checks if the element contains the specified class or not.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/arrayLike/includes/includes.ts#L12"><code>includes()</code></a>

Checks if the array-like object includes the value or not.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/component/inherit/inherit.ts#L13"><code>inherit()</code></a>

Loosely inherits a parent component.
This does not share `prototype`.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/type/type.ts#L35"><code>isArray()</code></a>

Checks if the given subject is an array or not.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/type/type.ts#L62"><code>isBoolean()</code></a>

Checks if the given subject is boolean or not.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/type/type.ts#L44"><code>isFunction()</code></a>

Checks if the given subject is a function or not.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/type/type.ts#L94"><code>isHTMLElement()</code></a>

Checks if the given subject is an HTMLElement instance or not.
This method takes into account which `window` the node belongs to.
Note that `ownerDocument` can be `null` and the non-null assertion looks inappropriate,
but `try-catch` will catch the error (this makes the bundle size smaller a bit).

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/type/type.ts#L80"><code>isNull()</code></a>

Checks if the given subject is `null` or not.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/type/type.ts#L24"><code>isObject()</code></a>

Checks if the given subject is an object or not.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/type/type.ts#L53"><code>isString()</code></a>

Checks if the given subject is a string or not.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/type/type.ts#L71"><code>isUndefined()</code></a>

Checks if the given subject is `undefined` or not.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/matches/matches.ts#L12"><code>matches()</code></a>

Checks if the element can be selected by the provided selector or not.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/math/math/math.ts#L1"><code>max()</code></a>

Returns the larger of a set of supplied numeric expressions.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/measure/measure.ts#L15"><code>measure()</code></a>

Attempts to convert the provided value to pixel as the relative value to the parent element.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/object/merge/merge.ts#L39"><code>merge()</code></a>

Recursively merges source properties to the object.
Be aware that this method does not merge arrays. They are just duplicated by `slice()`.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/math/math/math.ts#L1"><code>min()</code></a>

Returns the smaller of a set of supplied numeric expressions.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/function/nextTick/nextTick.ts#L9"><code>nextTick()</code></a>

Invokes the callback on the next tick.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/function/noop/noop.ts#L4"><code>noop()</code></a>

No operation.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/object/omit/omit.ts#L13"><code>omit()</code></a>

Deletes specified own keys from the object.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/object/ownKeys/ownKeys.ts#L4"><code>ownKeys()</code></a>

An alias of `Object.keys()`

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/string/pad/pad.ts#L9"><code>pad()</code></a>

Pads the number with 0.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/parseHtml/parseHtml.ts#L11"><code>parseHtml()</code></a>

Parses the provided HTML string and returns the first element.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/component/parseOption/parseOption.ts#L17"><code>parseOption()</code></a>

Parses an option that may have an object literal for nested options.
If users do not provided the option, this method treats it as `true`.
- `true` or `undefined`: `{}`
- `false` or `null`: `false`
- `T` : `T`

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/prevent/prevent.ts#L7"><code>prevent()</code></a>

Call the `preventDefault()` of the provided event.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/array/push/push.ts#L12"><code>push()</code></a>

Extended `Array#push()` that accepts an item or an array with items.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/query/query.ts#L9"><code>query()</code></a>

Returns an element that matches the provided selector.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/queryAll/queryAll.ts#L12"><code>queryAll()</code></a>

Returns elements that match the provided selector.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/function/raf/raf.ts#L4"><code>raf()</code></a>

The arias of `window.requestAnimationFrame()`.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/rect/rect.ts#L6"><code>rect()</code></a>

Returns a DOMRect object of the provided element.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/removeAttribute/removeAttribute.ts#L10"><code>removeAttribute()</code></a>

Removes attributes from the element.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/removeClass/removeClass.ts#L10"><code>removeClass()</code></a>

Removes classes from the element.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/removeNode/removeNode.ts#L9"><code>removeNode()</code></a>

Removes the provided node from its parent.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/setAttribute/setAttribute.ts#L9"><code>setAttribute()</code></a>

Sets attribute/attributes to the element or elements.
If the value is `null`, `undefined` or an empty string, the attribute will be removed.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/math/math/math.ts#L1"><code>sign()</code></a>

Returns the sign of the x, indicating whether x is positive, negative or zero.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/arrayLike/slice/slice.ts#L13"><code>slice()</code></a>

The slice method for an array-like object.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/style/style.ts#L5"><code>style()</code></a>

Applies inline styles to the provided element by an object literal.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/html/tag/tag.ts#L14"><code>tag()</code></a>

Builds a tag with classes or attributes.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/timeOf/timeOf.ts#L8"><code>timeOf()</code></a>

Extracts the timestamp from the event object.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/array/toArray/toArray.ts#L11"><code>toArray()</code></a>

Push the provided value to an array if the value is not an array.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/toggleClass/toggleClass.ts#L12"><code>toggleClass()</code></a>

Toggles the provided class or classes by following the `add` boolean.

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/string/uniqueId/uniqueId.ts#L16"><code>uniqueId()</code></a>

Returns a sequential unique ID as "prefix-number".

#### <a href="https://github.com/Splidejs/utils/blob/7de73b5/src/utils/dom/unit/unit.ts#L12"><code>unit()</code></a>

Appends `px` to the provided number.
If the value is already string, just returns it.