Methods
-
<static> stableSort( list, comparator )
-
Description
Stably sorts arrays since
.sort()
has issues.Parameters
Name Type Description list
Array array to sort
comparator
function comparator to sort by
Details
-
<static> memoizeObject( object ) → {Proxy}
-
Description
Generates an automatically memoizing version of an object.
Parameters
Name Type Description object
Object object to memoize
Returns
Details
-
<static> suppressErrors( method, description ) → {callable}
-
Description
Wraps the method in a
try..catch
block.Parameters
Name Type Description method
callable method to wrap
description
string 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 string
string string to format
values
object 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 string
string string to format
values
object 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 tree
object React tree to look through. Can be a rendered object or an internal instance.
searchFilter
callable 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 tree
object Tree that should be walked
searchFilter
callable Filter to check against each object and subobject
options
object Additional options to customize the search
Name Type Attributes Default Description walkable
Array.<string> | null <optional> Array of strings to use as keys that are allowed to be walked on. Null value indicates all keys are walkable
ignore
Array.<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 obj
Object object to get nested property of
path
string 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 argument
Any <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 object
object Object whose prototype to extend
prop
string Name of the prototype property to add
func
callable 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
extenders
have 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 extendee
object Object to be extended
extenders
object <repeatable> Objects to extend with
Returns
Details
-
<static> deepclone( value ) → {Any}
-
Description
Clones an object and all it's properties.
Parameters
Name Type Description value
Any The value to clone
Returns
Details
-
<static> deepfreeze( object, exclude )
-
Description
Freezes an object and all it's properties.
Parameters
Name Type Description object
Any The object to freeze
exclude
function 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 array
Array The array to filter
item
Any 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 executor
function delay
number Details
-
<static> loadData( name, key, defaultData ) → {object}
-
Description
Loads data through BetterDiscord's API.
Parameters
Name Type Description name
string name for the file (usually plugin name)
key
string which key the data is saved under
defaultData
object 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 name
string name for the file (usually plugin name)
key
string which key the data should be saved under
data
object data to save
Details
-
<static> loadSettings( name, defaultData ) → {object}
-
Description
Loads settings through BetterDiscord's API.
Parameters
Name Type Description name
string name for the file (usually plugin name)
defaultData
object default data to populate the object with
Returns
Details
-
<static> saveSettings( name, data )
-
Description
Saves settings through BetterDiscord's API.
Parameters
Name Type Description name
string name for the file (usually plugin name)
data
object settings to save
Details