Skip to content

Utility functions

Brandon Jordan edited this page May 1, 2025 · 18 revisions

Spark provides basic utility functions.

Next Frame

Wait for the next tick. This can give the microtime needed to ensure all values and states have been applied before proceeding to the next instruction. Useful for animation or reactivity.

await nextFrame();

Sleep

Sleep for ms milliseconds.

await sleep(ms);

Is Equal

Check if the two values are truly equal. Generally only recommended for deep comparison of objects or arrays.

if(equal(value1,value2)) {
    //
}

Is Empty

Check if a value is truly empty.

Empty Not Empty
{}, [], null, undefined, typeof 'undefined' false, 0
if(empty(value)) {
    //
}

Array Differences

Get the difference between two arrays.

arrayDiff(arr1, arr2);

Compare Arrays

Compare the keys and values of an array. Returns a boolean.

arrayCompare(array1, array2);

Compare Objects

Deep compare sorts the two objects consistently then stringifies the objects and compares the two strings. Returns a boolean.

objCompare(obj1, obj2);

Sort Object

Sort object by keys with an optional compare function.

sortObj(obj, compareFn);

Size Of

Get the size of a value.

  • If the value is an object, it returns a count of all of the keys in the entire object.
  • If the object is a string or an array, it returns the length of the value.
  • Otherwise, it returns the value as it's likely a number type value.
sizeOf(value)
Clone this wiki locally