Methods
-
<static> stableSort( list, comparator )
-
Description
Stably sorts arrays since
.sort()has issues.Parameters
Name Type Description listArray array to sort
comparatorfunction comparator to sort by
Details
-
<static> memoizeObject( object ) → {Proxy}
-
Description
Generates an automatically memoizing version of an object.
Parameters
Name Type Description objectObject object to memoize
Returns
Details
-
<static> suppressErrors( method, description ) → {callable}
-
Description
Wraps the method in a
try..catchblock.Parameters
Name Type Description methodcallable method to wrap
descriptionstring description of method
Returns
Details
-
<static> isNil( anything )
-
Description
This only exists because Samo relied on lodash being there... fuck lodash.
Parameters
Name Type Description anything* whatever you want
Details
-
<static> formatTString( string, values ) → {string}
-
Description
Format template strings with placeholders (
${placeholder}) into full strings. Quick example:Utilities.formatString("Hello, ${user}", {user: "Zerebos"})would return "Hello, Zerebos".Parameters
Name Type Description stringstring string to format
valuesobject object literal of placeholders to replacements
Returns
Details
-
<static> formatString( string, values ) → {string}
-
Description
Format strings with placeholders (
{{placeholder}}) into full strings. Quick example:Utilities.formatString("Hello, {{user}}", {user: "Zerebos"})would return "Hello, Zerebos".Parameters
Name Type Description stringstring string to format
valuesobject object literal of placeholders to replacements
Returns
Details
-
<static> findInReactTree( tree, searchFilter )
-
Description
Finds a value, subobject, or array from a tree that matches a specific filter. Great for patching render functions.
Parameters
Name Type Description treeobject React tree to look through. Can be a rendered object or an internal instance.
searchFiltercallable Filter function to check subobjects against.
Details
-
<static> findInTree( tree, searchFilter, options )
-
Description
Finds a value, subobject, or array from a tree that matches a specific filter.
Parameters
Name Type Description treeobject Tree that should be walked
searchFiltercallable Filter to check against each object and subobject
optionsobject Additional options to customize the search
Name Type Attributes Default Description walkableArray.<string> | null <optional> Array of strings to use as keys that are allowed to be walked on. Null value indicates all keys are walkable
ignoreArray.<string> <optional> [] Array of strings to use as keys to exclude from the search, most helpful when
walkable = null.Details
-
<static> getNestedProp( obj, path )
-
Description
Gets a nested property (if it exists) safely. Path should be something like
prop.prop2.prop3. Numbers can be used for arrays as well likeprop.prop2.array.0.id.Parameters
Name Type Description objObject object to get nested property of
pathstring representation of the property to obtain
Details
-
<static> className( ...argument )
-
Description
Builds a classname string from any number of arguments. This includes arrays and objects. When given an array all values from the array are added to the list. When given an object they keys are added as the classnames if the value is truthy. Copyright (c) 2018 Jed Watson https://github.com/JedWatson/classnames MIT License
Parameters
Name Type Attributes Description argumentAny <repeatable> anything that should be used to add classnames.
Details
-
<static> addToPrototype( object, prop, func )
-
Description
Safely adds to the prototype of an existing object by checking if the property exists on the prototype.
Parameters
Name Type Description objectobject Object whose prototype to extend
propstring Name of the prototype property to add
funccallable Function to run
Details
-
<static> extend( extendee, ...extenders ) → {object}
-
Description
Deep extends an object with a set of other objects. Objects later in the list of
extendershave priority, that is to say if one sets a key to be a primitive, it will be overwritten with the next one with the same key. If it is an object, and the keys match, the object is extended. This happens recursively.Parameters
Name Type Attributes Description extendeeobject Object to be extended
extendersobject <repeatable> Objects to extend with
Returns
Details
-
<static> deepclone( value ) → {Any}
-
Description
Clones an object and all it's properties.
Parameters
Name Type Description valueAny The value to clone
Returns
Details
-
<static> deepfreeze( object, exclude )
-
Description
Freezes an object and all it's properties.
Parameters
Name Type Description objectAny The object to freeze
excludefunction A function to filter object that shouldn't be frozen
Details
-
<static> removeFromArray( array, item ) → {Array}
-
Description
Removes an item from an array. This differs from Array.prototype.filter as it mutates the original array instead of creating a new one.
Parameters
Name Type Description arrayArray The array to filter
itemAny The item to remove from the array
Returns
Details
-
<static> debounce( executor, delay )
-
Description
Returns a function, that, as long as it continues to be invoked, will not be triggered. The function will be called after it stops being called for N milliseconds.
Adapted from the version by David Walsh (https://davidwalsh.name/javascript-debounce-function)
Parameters
Name Type Description executorfunction delaynumber Details
-
<static> loadData( name, key, defaultData ) → {object}
-
Description
Loads data through BetterDiscord's API.
Parameters
Name Type Description namestring name for the file (usually plugin name)
keystring which key the data is saved under
defaultDataobject default data to populate the object with
Returns
Details
-
<static> saveData( name, key, data )
-
Description
Saves data through BetterDiscord's API.
Parameters
Name Type Description namestring name for the file (usually plugin name)
keystring which key the data should be saved under
dataobject data to save
Details
-
<static> loadSettings( name, defaultData ) → {object}
-
Description
Loads settings through BetterDiscord's API.
Parameters
Name Type Description namestring name for the file (usually plugin name)
defaultDataobject default data to populate the object with
Returns
Details
-
<static> saveSettings( name, data )
-
Description
Saves settings through BetterDiscord's API.
Parameters
Name Type Description namestring name for the file (usually plugin name)
dataobject settings to save
Details