Skip to content

Module: utilities/object

Classes

Functions

addWordSeparators

addWordSeparators(str): string

Parameters

NameType
strstring

Returns

string

Defined in

src/utilities/object.ts:706


array_equals

array_equals(a, b): boolean

Check that two arrays are the same length and that each array has the same items in the same indices.

Parameters

NameTypeDescription
aany[]The first array
bany[]The second array

Returns

boolean

Whether or not they match

Defined in

src/utilities/object.ts:300


b64ToArrayBuffer

b64ToArrayBuffer(input): ArrayBuffer

Parameters

NameType
inputstring

Returns

ArrayBuffer

Defined in

src/utilities/object.ts:981


debounce

debounce<TFunc>(fn, delay, immediate?): (this: ThisParameterType<TFunc>, ...args: Parameters<TFunc>) => void

Return a wrapper for a function that will only execute the function a period of time after it has stopped being called.

Type parameters

NameType
TFuncextends AnyFunction

Parameters

NameTypeDefault valueDescription
fnTFuncundefinedThe function to wrap.
delaynumberundefinedThe time to wait, in milliseconds
immediateboolean | 2falseIf immediate is true, trigger the function immediately rather than eventually.

Returns

fn

The wrapped function

▸ (this, ...args): void

Parameters
NameType
thisThisParameterType<TFunc>
...argsParameters<TFunc>
Returns

void

Defined in

src/utilities/object.ts:227


deep_copy

deep_copy<T>(object, seen?): T

Type parameters

Name
T

Parameters

NameType
objectT
seen?Set<any>

Returns

T

Defined in

src/utilities/object.ts:598


deep_equals

deep_equals(object, other, ignore_undefined?, seen?, other_seen?): boolean

Parameters

NameTypeDefault value
objectanyundefined
otheranyundefined
ignore_undefinedbooleanfalse
seen?Set<PropertyKey>undefined
other_seen?Set<PropertyKey>undefined

Returns

boolean

Defined in

src/utilities/object.ts:313


escape_regex

escape_regex(input): string

Parameters

NameType
inputstring

Returns

string

Defined in

src/utilities/object.ts:701


generateHex

generateHex(length?): string

Parameters

NameTypeDefault value
lengthnumber40

Returns

string

Defined in

src/utilities/object.ts:845


generateUUID

generateUUID(): `${string}-${string}-${string}-${string}-${string}`

Returns

`${string}-${string}-${string}-${string}-${string}`

Defined in

src/utilities/object.ts:35


get

get<TPath, TValue, TReturn>(path, object): TReturn

Get a value from an object at a path.

Type parameters

NameType
TPathextends string
TValueany
TReturnExtractType<TValue, ExtractSegments<TPath>, ExtractSegments<TPath>[0], ArrayShift<ExtractSegments<TPath>>>

Parameters

NameTypeDescription
pathTPathThe path to follow, using periods to go down a level.
objectTValueThe starting object.

Returns

TReturn

The value at that point in the path, or undefined if part of the path doesn't exist.

Defined in

src/utilities/object.ts:506


getTwitchEmoteSrcSet

getTwitchEmoteSrcSet(id, animated?, dark?, big?): string

Parameters

NameTypeDefault value
idstringundefined
animatedbooleanfalse
darkbooleantrue
bigbooleanfalse

Returns

string

Defined in

src/utilities/object.ts:15


getTwitchEmoteURL

getTwitchEmoteURL(id, scale, animated?, dark?): string

Parameters

NameTypeDefault value
idstringundefined
scalenumberundefined
animatedbooleanfalse
darkbooleantrue

Returns

string

Defined in

src/utilities/object.ts:6


glob_to_regex

glob_to_regex(input): string

Parameters

NameType
inputstring

Returns

string

Defined in

src/utilities/object.ts:713


has

has<T>(object, key): key is keyof T

Type parameters

Name
T

Parameters

NameType
objectT
keyPropertyKey

Returns

key is keyof T

Defined in

src/utilities/object.ts:104


importRsaKey

importRsaKey(pem, uses?): Promise<CryptoKey>

Parameters

NameType
pemstring
usesKeyUsage[]

Returns

Promise<CryptoKey>

Defined in

src/utilities/object.ts:997


isValidShortcut

isValidShortcut(key): boolean

Parameters

NameType
keystring

Returns

boolean

Defined in

src/utilities/object.ts:27


makeAddonIdChecker

makeAddonIdChecker(input): RegExp

Parameters

NameType
inputstring

Returns

RegExp

Defined in

src/utilities/object.ts:642


make_enum

make_enum<T>(...input): FakeEnum<T>

Type parameters

NameType
Textends string

Parameters

NameType
...inputT[]

Returns

FakeEnum<T>

Defined in

src/utilities/object.ts:118


make_enum_flags

make_enum_flags<T>(...input): FakeEnumFlags<T>

Type parameters

NameType
Textends string

Parameters

NameType
...inputT[]

Returns

FakeEnumFlags<T>

Defined in

src/utilities/object.ts:134


map_equals

map_equals(first, second): boolean

Parameters

NameType
firstMap<any, any>
secondMap<any, any>

Returns

boolean

Defined in

src/utilities/object.ts:378


matchScreen

matchScreen(screens, options): undefined | ScreenDimensions

Parameters

NameType
screensScreenDimensions[]
optionsScreenOptions

Returns

undefined | ScreenDimensions

Defined in

src/utilities/object.ts:70


maybe_call

maybe_call<T>(input, ctx, ...args): MaybeReturn<T>

Type parameters

Name
T

Parameters

NameType
inputT
ctxany
...argsMaybeParameters<T>

Returns

MaybeReturn<T>

Defined in

src/utilities/object.ts:662


normalizeAddonIdForComparison

normalizeAddonIdForComparison(input): string

Parameters

NameType
inputstring

Returns

string

Defined in

src/utilities/object.ts:638


once

once<TFunc, TReturn>(fn): (this: ThisParameterType<TFunc>, ...args: Parameters<TFunc>) => Promise<TReturn>

Make sure that a given asynchronous function is only called once at a time.

Type parameters

NameType
TFuncextends AnyFunction
TReturnAwaited<ReturnType<TFunc>>

Parameters

NameType
fnTFunc

Returns

fn

▸ (this, ...args): Promise<TReturn>

Parameters
NameType
thisThisParameterType<TFunc>
...argsParameters<TFunc>
Returns

Promise<TReturn>

Defined in

src/utilities/object.ts:275


pick_random

pick_random<T>(obj): T

Type parameters

Name
T

Parameters

NameType
objT[]

Returns

T

Defined in

src/utilities/object.ts:686

pick_random<T, K>(obj): T[K]

Type parameters

NameType
Textends object
Kextends string | number | symbol

Parameters

NameType
objT

Returns

T[K]

Defined in

src/utilities/object.ts:687


set_equals

set_equals(first, second): boolean

Parameters

NameType
firstSet<any>
secondSet<any>

Returns

boolean

Defined in

src/utilities/object.ts:390


sha256

sha256(message): Promise<string>

Parameters

NameType
messagestring

Returns

Promise<string>

Defined in

src/utilities/object.ts:37


shallow_copy

shallow_copy<T>(object, depth?, seen?): T

Copy an object so that it can be safely serialized. If an object is not serializable, such as a promise, returns null.

Type parameters

Name
T

Parameters

NameTypeDefault valueDescription
objectTundefinedThe thing to copy.
depth?number2The maximum depth to explore the object.
seen?Set<any>undefinedA Set of seen objects. Internal use only.

Returns

T

The copy to safely store or use.

Export

Defined in

src/utilities/object.ts:556


shallow_object_equals

shallow_object_equals(first, second): boolean

Parameters

NameType
firstany
secondany

Returns

boolean

Defined in

src/utilities/object.ts:362


sleep

sleep(delay): Promise<void>

Parameters

NameType
delaynumber

Returns

Promise<void>

Defined in

src/utilities/object.ts:109


split_chars

split_chars(str): null | RegExpMatchArray | never[]

Parameters

NameType
strstring

Returns

null | RegExpMatchArray | never[]

Defined in

src/utilities/object.ts:679


substr_count

substr_count(str, needle): number

Return the number of times a substring is found within a string.

Parameters

NameTypeDescription
strstringThe string to search within.
needlestringThe substring to search for.

Returns

number

The number of matches found.

Defined in

src/utilities/object.ts:449


timeout

timeout<TReturn>(promise, delay): Promise<TReturn>

Type parameters

NameType
TReturnunknown

Parameters

NameType
promisePromise<TReturn>
delaynumber

Returns

Promise<TReturn>

Defined in

src/utilities/object.ts:151


truncate

truncate(input, target?, overage?, ellipsis?, break_line?, trim?): string

Truncate a string. Tries to intelligently break the string in white-space if possible, without back-tracking. The returned string can be up to ellipsis.length + target + overage characters long.

Parameters

NameTypeDefault valueDescription
inputstringundefinedThe string to truncate.
targetnumber100The target length for the result
overagenumber15Accept up to this many additional characters for a better result
ellipsisstring'…'The string to append when truncating
break_linebooleantrueIf true, attempt to break at the first LF
trimbooleantrueIf true, runs trim() on the string before truncating

Returns

string

The truncated string

Defined in

src/utilities/object.ts:800