misc
A bunch of little functions that should be part of core Javascript, but aren't.
// access like this (preferred)
import {constrain, range} from "@liqvid/utils/misc";
// or like this (legacy)
import {Utils} from "liqvid";
const {constrain, range} = Utils.misc;
between()
Equivalent to (min <= val) && (val < max).
between(min: number, val: number, max: number): boolean;
bind()
Bind methods of an object to the object, so that this behaves as expected. This is mainly for code using class components rather than Hooks.
bind<T extends {[P in K]: Function}, K extends keyof T>(o: T, methods: K[]): void;
clamp()
Clamps a value between a lower and upper bound.
clamp: (min: number, val: number, max: number) => number;
constrain()
Alias for clamp().
lerp()
Linear interpolation between a and b.
lerp: (a: number, b: number, t: number) => number;
range()
Returns integers from a (inclusive) to b (exclusive). If called with one argument, range(n) is equivalent to range(0, n).
range: (a: number, b?: number) => number[];
wait()
Returns a Promise that resolves in time milliseconds.
wait(time: number): Promise<void>;
waitFor()
Returns a Promise that resolves once callback returns true.
waitFor(callback: () => boolean, interval?: number): Promise<void>;