js-util

Home > rc-js-util

rc-js-util package

Classes

Class Description
_Array Utilities that apply to Array and ArrayLike.
_Debug Utilities for debug builds.
_Dictionary Utilities for ‘dictionaries’, i.e. { [index: string]: any }.
_Equality Non-standard equality tests.
_F32 Utilities relating to single precision floats.
_F64 Utilities relating to double precision floats.
_Fp Utilities for functional programming.
_Identifier Utilities for generating identifiers.
_Iterator Utilities relating to IterableIterator & generators.
_Map Utilities that apply to Map.
_Math Utilities relating to math.
_Number Utilities that apply to numbers.
_Path File path manipulation utilities.
_Production Utilities for production builds.
_Promise Utilities for handling promises.
_RegExp Utilities that apply to RegExp.
_Set Utilities that apply to Set.
_String Utilities that apply to string.
AOnDestroy Provides a communication channel via callbacks which can be easily cleared & copied.
AReferenceCounted Provides a way to handle cleanup of manually managed resources where there is not a single owner. NB The object is pre-claimed (ref count 1) on creation.
ATypedArrayTuple Common methods of typed arrays, extend to make typed array tuples.
BroadcastEvent Strong reference implementation of IBroadcastEvent.
CircularBuffer Presents an array as if it were circular, going past the end or start loops around.
CircularFIFOStack Circular first in first out stack.
DebugProtectedView Provides a view of an object that can be invalidated, causing attempts to access it to error in _BUILD.DEBUG.
DebugSharedObjectChecks Provides life cycle and access checks for shared objects.
DirtyCheckedUniqueCollection Provides a unique array with O(1) add & remove, with dirty checking on getArray.
IncrementalUpdater Performs update operations once every waitPeriod until the iterator returned by IIncrementallyUpdatable is exhausted.
IncrementingIdentifierFactory Provides an incrementing integer identifier.
LinkedReferenceCounter A reference counted object that can be nested.
Margin2d 2x2 matrix representing margins on a rectangle.
Mat2 Row major 2x2 matrix.
Mat3 Row major 3x3 matrix.
Mat4 Row major 4x4 matrix.
Mulberry32Generator Random number generator.
NestableError Composable error, useful for automatically generating user friendly localized error messages.
NormalizedDataViewProvider Provides INormalizedDataView.
NotRandomGenerator Instead of returning a random number, return the constant instead.
Range1d Vec2 representing a 1d range.
Range2d 2x2 matrix representing a 2d range.
RawVoidPointer Provides a reference counted wrapper to a pointer malloc‘d from JS and is free‘d on reference count hitting 0.
ReferenceCountedPtr Wrapper of wasm object.
ReferenceCounter Weak reference counter.
RgbaColorPacker Utility for packing and unpacking RGBA into int32 with one byte per channel.
SanitizedEmscriptenTestModule  
SharedArray Typed array shared between wasm and javascript.
SharedStaticArray Typed array representing static memory in wasm.
TemporaryListener Provides a communication channel via callbacks which can be easily cleared & copied.
Vec2 Vector 2.
Vec3 Vector 3.
Vec4 Vector 4.

Enumerations

Enumeration Description
ECircularStackOverflowMode Sets the behavior of CircularFIFOStack when a value is pushed which won’t fit.
ERgbaMasks Bit mask for packed RGBA colors.
ERgbaShift Bit offset for packed RGBA colors.

Functions

Function Description
arrayAddToSet(items, set) Adds the items in an array to the set.
arrayBinaryIndexOf(indexable, comparisonValueToSearchFor, getComparisonValueAtIndex, length, start) Performs a bisection search of an ‘indexable’ object, i.e. can be accessed by index, for example Array. Custom data structures are also supported.
arrayBinaryLastIndexOf(indexable, comparisonValueToSearchFor, getComparisonValueAtIndex, length, start) Performs a bisection search of an ‘indexable’ object, i.e. can be accessed by index, for example Array. Custom data structures are also supported.
arrayCollect(items, collected, collect) Like Array.reduce but without the requirement to return the value in the callback.
arrayCompact(items) Strips null and undefined items from arrays (non mutative).
arrayCompactMap(items, map) Like _Array.map but where the callback returns null it will be omitted from the result.
arrayContains(items, item) Returns true if the item is present in the list (=== equality test).
arrayContains(items, item) Returns true if the item is present in the list (=== equality test).
arrayCopyInto(from, to, startIndex, length) Make an array contain the same items as another.
arrayFlatMap(items, mapCallback) Iterate over ArrayLike calling a callback against it, the callback returns ArrayLike which is concatenated into a single Array.
arrayForEach(items, callback) Like Array.forEach.
arrayForEachRange(from, to, callback) Like arrayForEach() with integer range as input.
arrayGenerateRange(from, to) Generates a range of integers output in an Array.
arrayIndex(items, getKey) Populates a Map given a key creating function and ArrayLike.
arrayInsertAtIndex(items, itemToInsert, insertAtIndex) Modifies input array by inserting at given index.
arrayIntersect(a, b, getComparisonValue) Given two ArrayLike, provides the items common between them in an Array.
arrayIsArray(obj) Checks if the parameter is an instance of Array or is a view of ArrayBuffer.
arrayIsNotEmpty(items) Returns true if the argument is not null, undefined or empty. Type narrows to TArray where true.
arrayLast(items) Gets the last value in ArrayLike.
arrayMap(items, callback) Like Array.map.
arrayMapRange(from, to, callback) Like arrayMap() with integer range as input.
arrayMax(numbers) Find the largest number in an array, if the array is empty the return is -Infinity.
arrayMin(numbers) Find the smallest number in an array, if the array is empty the return is Infinity.
arrayNormalizeEmptyToUndefined(array) Replaces length 0 ArrayLike with undefined.
arrayNormalizeNullishToEmpty(array) Replaces null / undefined with an empty Array.
arrayPushUnique(items, itemToPush, getComparisonValue) Like Array.push but checks if the value is unique first.
arrayRemoveMany(items, itemsToRemove) Removes each item in itemsToRemove from items (including any repeated items).
arrayRemoveOne(items, itemToRemove) Removes either 0 or one item from items, even if itemToRemove appears more than once.
arrayReplaceOne(items, itemToRemove, replaceWith) Replaces the first match of itemToRemove with replaceWith.
arraySetDifference(a, b) returns items in A not in B.
arraySymmetricDifference(a, b, aSet, bSet) Returns those items in A not in B, and those items in B not in A.
arrayUnion(items, getComparisonValue) Given an ArrayLike of ArrayLike, provides all unique items in an Array.
arrayUnique(items) Creates a new array with no duplicates, using standard object equality.
dictionaryCloneExtend(base, extension) Creates an object which is extended sequentially by two additional objects.
dictionaryExtend(base, extension) Modifies an object to include the keys and values of another.
dictionaryForEach(dictionary, callback) Like Array.forEach but for arbitrary objects.
dictionaryPairs(dictionary) converts objects into key value pair tuples.
dictionaryPush(dict, key, value) Used with dictionary that store arrays. Where an array exists for a given key the value will be appended to that array, otherwise a new array will be created containing the value.
dictionaryValues(d) Equivalent to Object.values.
equalityAllEqual(items) Returns true if all items are triple equal ===.
equalityAreConsistentlyDefined(a, b) Returns true if both A and B are both null, undefined or ‘defined’. Defined is not null and not undefined.
fpDebounce(wait, immediate, functionToProxy) Creates a function that will proxy calls to functionToProxy when wait time has passed since the last call, using the most recent arguments. Where immediate is true, the function immediately proxies the call and will not proxy again until wait time passes since the last call.
fpIdentity(arg) Returns the argument.
fpMaybeNewValue(newValue, oldValue) Returns the newValue if defined, else the old value.
fpNoOp(_args) Does nothing (intentionally…).
fpNormalizeToNull(value) Normalizes undefined input to null.
fpNormalizeToUndefined(value) Normalizes null input to undefined.
fpOnce(initialize) Creates a function that can be called many times but will run at most once.
fpValueOrNull(predicate, value) Returns the value if the predicate is true, else null.
getEmscriptenWrapper(memory, emscriptenModuleFactory, extension) Factory for creating wrapped emscripten module.
iteratorConsumeAll(iterator) Iterate over an iterator until it’s done, discarding the results.
mapAddToSet(map, key, value) Used with maps that store sets. Where a set exists for a given key the value will be added to that set, otherwise a new set will be created containing the value.
mapAddToSet(map, key, value) Used with maps that store sets. Where a set exists for a given key the value will be added to that set, otherwise a new set will be created containing the value.
mapArrayMap(map, callback) Like Array.map but with a Map input. Outputs an Array.
mapClearingDeleteFromSet(map, key, value) Used with maps that store sets. Where a set exists for a given key the value will be removed from that set, if it is empty after removal, then the set is deleted.
mapClearingDeleteFromSet(map, key, value) Used with maps that store sets. Where a set exists for a given key the value will be removed from that set.
mapConcat(map, key, values) Used with maps that store arrays. Where an array exists for a given key the values will be appended to that array, otherwise a copy of values array will be inserted.
mapConcat(map, key, values) Used with maps that store arrays. Where an array exists for a given key the values will be appended to that array, otherwise a copy of values array will be inserted.
mapDeleteFromSet(map, key, value) Used with maps that store sets. Where a set exists for a given key the value will be removed from that set.
mapDeleteFromSet(map, key, value) Used with maps that store sets. Where a set exists for a given key the value will be removed from that set.
mapDeleteGet(map, key) Get the stored value if present, then delete the key.
mapDeleteGet(map, key) Get the stored value if present, then delete the key.
mapEntriesToArray(map) Converts a Map into an Array of its key value pairs.
mapFirstKey(map) Gets the first inserted key in a Map.
mapFirstValue(map) Gets the first inserted value in a Map.
mapInitializeGet(map, key, getValue) Gets the value from a Map for a given key, where the value is undefined or hasn’t been set, the callback’s return will be inserted into the Map and returned.
mapInitializeGet(map, key, getValue) Gets the value from a Map for a given key, where the value is undefined or hasn’t been set, the callback’s return will be inserted into the Map and returned.
mapIntersect(a, b) <p>Does not check value equality, only key. Takes items from A.</p><p>See mapIntersect().</p>
mapKeysToArray(map) Converts a Map into an Array of its keys.
mapPush(map, key, value) Used with maps that store arrays. Where an array exists for a given key the value will be appended to that array, otherwise a new array will be created containing the value.
mapPush(map, key, value) Used with maps that store arrays. Where an array exists for a given key the value will be appended to that array, otherwise a new array will be created containing the value.
mapRemoveManyFromArray(map, key, itemsToRemove) Used with maps that store arrays. Where an array exists for a given key the values will be removed from that array.
mapRemoveManyFromArray(map, key, itemsToRemove) Used with maps that store arrays. Where an array exists for a given key the values will be removed from that array.
mapRemoveOneFromArray(map, key, value) Used with maps that store arrays. Where an array exists for a given key the value will be removed from that array.
mapRemoveOneFromArray(map, key, value) Used with maps that store arrays. Where an array exists for a given key the value will be removed from that array.
mapReportingAddToSet(map, key, value) Used with maps that store sets. Where a set exists for a given key the value will be added to that set, otherwise a new set will be created containing the value.
mapReportingAddToSet(map, key, value) Used with maps that store sets. Where a set exists for a given key the value will be added to that set, otherwise a new set will be created containing the value.
mapSetDifference(a, b) returns items in A not in B.
mapSymmetricDifference(a, b) Returns a map with keys in A not in B, and keys in B not in A.
mapUnion(a, b) Returns a map with keys from both A and B. If both A and B have the same key the value from B will be used.
mapValuesToArray(map) Converts a Map into an Array of its values.
mathBound(value, min, max) Bound a value in to a range.
mathBoundRandom(min, max) Create a random value between min and max.
mathHypot2(a, b) As per Math.hypot, expect with 2 args.
mathMax(a, b) Returns the larger of the two parameters a and b.
mathMin(a, b) Returns the smaller of the two parameters a and b.
numberGetHexString(value) Returns the hex representation of the number. If it’s not a number it returns “NaN”.
Once(target, key, descriptor) Method decorator. The target will be called only once, subsequent calls will return the first return.
pathJoin(start, end, separator) Joins two strings start and end with a separator.
promiseDelay(resolveWith, delay) Returns a Promise which will resolve to resolveWith after a delay of delay (in milliseconds).
promiseRejectFalse(value, error) Returns a Promise of rejection with the supplied error if the value is false.
promiseRejectFalsey(value, error) Returns a Promise of rejection with the supplied error if the value is falsy.
promiseRejectNull(value, error) Returns a Promise of rejection with the supplied error if the value is null or undefined.
regexEscapeRegex(value) Escapes RegExp special characters in strings.
setDefaultUnitTestFlags()  
setIsSetEqual(a, b) Tests to see if all of the members of a set are the same.
setSetDifference(a, b) returns items in A not in B.
setSymmetricDifference(a, b) Returns those items in A not in B, and those items in B not in A.
setValuesToArray(set) Converts a set into an array of its values.
stringNormalizeEmptyToUndefined(input) Replaces length 0 strings with undefined.
stringNormalizeNullUndefinedToEmpty(input) Replaces null / undefined with an empty string.

Interfaces

Interface Description
IBroadcastEvent Simple one to many communication channel. Proxies the arguments of emit to each listener.
IDebugAllocateListener  
IDebugBindings Emscripten bindings for debugging.
IDebugProtectedView Factory for creating proxy objects that can be invalidated later. Once invalidated any property read that wasn’t explicitly marked safe will cause a debug error. Available in debug contexts only.
IDebugSharedObject See ISharedObject.
IDebugSharedObjectLifeCycleChecker Wrapper of FinalizationRegistry for shared objects, useful for checking if the shared object was properly disposed. Available in debug contexts only.
IDebugWeakBroadcastEvent Like IBroadcastEvent but without holding strong references. Available in debug contexts only.
IDebugWeakStore A weakmap store available in debug contexts only.
IDictionary  
IDirtyCheckedUniqueCollection Provides a unique array with O(1) add & remove, with dirty checking on getArray.
IEmscriptenDebug  
IEmscriptenWrapper  
IFIFOStack Circular first in first out stack.
IIdentifierFactory  
IIncrementallyUpdatable A provider that should return an iterator that represents a sequence of update operations. Useful for breaking up operations that would block the UI for an unacceptably long time.
IIncrementalUpdater Performs update operations once every waitPeriod until the iterator returned by IIncrementallyUpdatable is exhausted.
IJsUtilBindings  
ILinkedReferenceCounter A reference counted object that can be nested.
IMargin2dCtor Constructor for Margin2d.
IMat2Ctor Constructor for Mat2.
IMat3Ctor Constructor for Mat3.
IMat4Ctor Constructor for Mat4.
IMemoryUtilBindings  
INormalizedDataView Provides a way to set a value on a DataView without needing to know the types at the point of setting. Use NormalizedDataViewProvider to get an instance.
INumericKeyedDictionary  
IOnDestroy Provides a ITemporaryListener that is cleared on onDestroy.
IOnFree  
IOnMemoryResize  
IRandomNumberGenerator  
IRange1dCtor Constructor for Range1d.
IRange2dCtor Constructor for Range2d.
IRawVoidPointer Provides a reference counted wrapper to a pointer malloc‘d from JS and is free‘d on reference count hitting 0.
IReadonlyDictionary  
IReadonlyMargin2d Margin2d.
IReadonlyMat2 Mat2.
IReadonlyMat3 Mat3.
IReadonlyMat4 Mat4.
IReadonlyRange1d Range1d.
IReadonlyRange2d Range2d.
IReadonlySetLike  
IReadonlyVec2 Vec2.
IReadonlyVec3 Vec3.
IReadonlyVec4 Vec4.
IRefCountedObject Holds references to resource(s) that must be life-cycle managed.
IReferenceCounted Provides a way to handle cleanup of manually managed resources where there is not a single owner.
IReferenceCountedPtr Wrapper of wasm object. NB The object is pre-claimed (ref count 1) on creation. On free the pointer will be set to null.
ISanitizedTestModuleOptions  
ISetLike  
ISharedArray Typed array representing a contiguous block of memory in wasm.
ISharedArrayBindings  
ISharedObject Holds a reference to wasm object.
ITemporaryListener Provides a communication channel via callbacks which can be easily cleared & copied.
ITypedArrayTupleFactory Defines utility methods for creating typed array tuples.
IVec2Ctor Constructor for Vec2.
IVec3Ctor Constructor for Vec3.
IVec4Ctor Constructor for Vec4.
IWebAssemblyMemoryMemory Copied from lib.dom.d.ts to avoid portability issues.

Namespaces

Namespace Description
Emscripten External lib.

Variables

Variable Description
arrayEmptyArray An empty readonly array, useful to avoid GC pressure.
emscriptenAsanTestModuleOptions  
emscriptenSafeHeapTestModuleOptions  
isLittleEndian  
iteratorEmptyIterator An iterator that is done.

Type Aliases

Type Alias Description
TDebouncedFn  
TDebugListener  
TDecayedTypedArrayTuple Like ATypedArrayTuple but indexable with any number.
TExtractIndexes Extract numerical indexes out of a type, if there aren’t any fallback to number.
TExtractTypeTypedArrayTuple  
TF32Margin2d Float32 Margin2d.
TF32Mat2 Float32 Mat2.
TF32Mat3 Float32 Mat3.
TF32Mat4 Float32 Mat4.
TF32Range1d Float32 Range1d.
TF32Range2d Float32 Range2d.
TF32SharedArray Float32 ISharedArray.
TF32SharedStaticArray Float32 ISharedArray (static).
TF32Vec2 Float32 Vec2.
TF32Vec3 Float32 Vec3.
TF32Vec4 Float32 Vec4.
TF64Margin2d Float64 Margin2d.
TF64Mat2 Float64 Mat2.
TF64Mat3 Float64 Mat3.
TF64Mat4 Float64 Mat4.
TF64Range1d Float64 Range1d.
TF64Range2d Float64 Range2d.
TF64SharedArray Float64 ISharedArray.
TF64SharedStaticArray Float64 ISharedArray (static).
TF64Vec2 Float64 Vec2.
TF64Vec3 Float64 Vec3.
TF64Vec4 Float64 Vec4.
TGetComparisonValueAtIndex  
TGetStringFromLocalization  
TKeysOf  
TListener  
TMargin2dCtorArgs  
TMat2CtorArgs  
TMat3CtorArgs  
TMat4CtorArgs  
TNeverFallback If the value is never, return the fallback instead.
TNeverPredicate If TTest is never, return TTrue, else TFalse.
TNextInt Gives the next int between 0 - 16.
TNullable  
TPickExcept  
TPickPartial Like Partial but allows specification of optional properties.
TPickRequired Like Required but allows specification of required properties.
TPredicate  
TProperty  
TRange1dCtorArgs  
TRange2dCtorArgs  
TSharedArrayPrefix  
TTupleLike Tuple version of ArrayLike.
TTupleLikeOfLength Useful for homogenous tuples of arbitrary length.
TTypedArray  
TTypedArrayCast Typed array tuples of the same dimension but different storage type (e.g. float32 vs int32) are not structurally compatible by design. Where an implicit conversion is desired you can cast between typed array tuples of the same dimension using this utility type as described in the example.
TTypedArrayCtor  
TTypedArrayTupleMutativeMethods The method names of ATypedArrayTuple which mutate the array.
TUnionToIntersection  
TUnpackArray  
TUnpackIfArray  
TVec2CtorArgs  
TVec3CtorArgs  
TVec4CtorArgs  
TWebAssemblyMemoryListenerArgs  
TWriteable Removes readonly from an object.