Beta —
@videojs/utils is close to stable. Experimental adoption in real projects is welcome.@videojs/utils provides the shared utility functions used across every package in the Video.js monorepo. It is the lowest-level dependency in the stack, with no Video.js runtime dependencies of its own.
Installation
Exports
| Entry point | Description |
|---|---|
./predicate | Type-safe predicate functions (isUndefined, isNull, isFunction, isString, isObject) |
./dom | DOM helpers (listen, animationFrame, idleCallback, onEvent) |
./array | Array utilities |
./events | Event utilities |
./function | Function utilities |
./object | Object utilities |
./string | String utilities |
./style | CSS style utilities |
./time | Time formatting utilities |
./number | Number utilities |
./types | Shared TypeScript types |
Predicate utilities (./predicate)
Type-safe narrowing predicates used throughout the codebase. Always prefer these over inline typeof checks:
| Instead of | Use |
|---|---|
x === undefined | isUndefined(x) |
x === null | isNull(x) |
typeof x === 'function' | isFunction(x) |
typeof x === 'string' | isString(x) |
DOM helpers (./dom)
Browser-specific utilities for events, animation frames, and idle callbacks. All return cleanup functions and support AbortSignal:
| Function | Returns | Description |
|---|---|---|
listen(target, event, handler, options?) | () => void | Adds an event listener, returns a cleanup function |
animationFrame(callback) | () => void | Schedules requestAnimationFrame, returns a cancel function |
idleCallback(callback) | () => void | Schedules requestIdleCallback, returns a cancel function |
onEvent(target, event) | Promise<Event> | Returns a promise that resolves when the event fires |
No runtime dependencies
@videojs/utils has no runtime dependencies. All exports are tree-shakeable ("sideEffects": false).
Related packages
@videojs/store
State management that depends on utils.
@videojs/core
Core logic that depends on utils.
@videojs/spf
Stream Processing Framework that depends on utils.
@videojs/html
HTML player that depends on utils.