-
Notifications
You must be signed in to change notification settings - Fork 0
Utility functions
Brandon Jordan edited this page May 1, 2025
·
18 revisions
Spark provides basic utility functions.
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 for ms milliseconds.
await sleep(ms);Check if the two values are truly equal. Generally only recommended for deep comparison of objects or arrays.
if(equal(value1,value2)) {
//
}Check if a value is truly empty.
| Empty | Not Empty |
|---|---|
{}, [], null, undefined, typeof 'undefined'
|
false, 0
|
if(empty(value)) {
//
}Get the difference between two arrays.
arrayDiff(arr1, arr2);Compare the keys and values of an array. Returns a boolean.
arrayCompare(array1, array2);Deep compare sorts the two objects consistently then stringifies the objects and compares the two strings. Returns a boolean.
objCompare(obj1, obj2);Sort object by keys with an optional compare function.
sortObj(obj, compareFn);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)