Module: utilities/object
Classes
Functions
addWordSeparators
▸ addWordSeparators(str
): string
Parameters
Name | Type |
---|---|
str | string |
Returns
string
Defined in
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
Name | Type | Description |
---|---|---|
a | any [] | The first array |
b | any [] | The second array |
Returns
boolean
Whether or not they match
Defined in
b64ToArrayBuffer
▸ b64ToArrayBuffer(input
): ArrayBuffer
Parameters
Name | Type |
---|---|
input | string |
Returns
ArrayBuffer
Defined in
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
Name | Type |
---|---|
TFunc | extends AnyFunction |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
fn | TFunc | undefined | The function to wrap. |
delay | number | undefined | The time to wait, in milliseconds |
immediate | boolean | 2 | false | If immediate is true, trigger the function immediately rather than eventually. |
Returns
fn
The wrapped function
▸ (this
, ...args
): void
Parameters
Name | Type |
---|---|
this | ThisParameterType <TFunc > |
...args | Parameters <TFunc > |
Returns
void
Defined in
deep_copy
▸ deep_copy<T
>(object
, seen?
): T
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
object | T |
seen? | Set <any > |
Returns
T
Defined in
deep_equals
▸ deep_equals(object
, other
, ignore_undefined?
, seen?
, other_seen?
): boolean
Parameters
Name | Type | Default value |
---|---|---|
object | any | undefined |
other | any | undefined |
ignore_undefined | boolean | false |
seen? | Set <PropertyKey > | undefined |
other_seen? | Set <PropertyKey > | undefined |
Returns
boolean
Defined in
escape_regex
▸ escape_regex(input
): string
Parameters
Name | Type |
---|---|
input | string |
Returns
string
Defined in
generateHex
▸ generateHex(length?
): string
Parameters
Name | Type | Default value |
---|---|---|
length | number | 40 |
Returns
string
Defined in
generateUUID
▸ generateUUID(): `${string}-${string}-${string}-${string}-${string}`
Returns
`${string}-${string}-${string}-${string}-${string}`
Defined in
get
▸ get<TPath
, TValue
, TReturn
>(path
, object
): TReturn
Get a value from an object at a path.
Type parameters
Name | Type |
---|---|
TPath | extends string |
TValue | any |
TReturn | ExtractType <TValue , ExtractSegments <TPath >, ExtractSegments <TPath >[0 ], ArrayShift <ExtractSegments <TPath >>> |
Parameters
Name | Type | Description |
---|---|---|
path | TPath | The path to follow, using periods to go down a level. |
object | TValue | The starting object. |
Returns
TReturn
The value at that point in the path, or undefined if part of the path doesn't exist.
Defined in
getTwitchEmoteSrcSet
▸ getTwitchEmoteSrcSet(id
, animated?
, dark?
, big?
): string
Parameters
Name | Type | Default value |
---|---|---|
id | string | undefined |
animated | boolean | false |
dark | boolean | true |
big | boolean | false |
Returns
string
Defined in
getTwitchEmoteURL
▸ getTwitchEmoteURL(id
, scale
, animated?
, dark?
): string
Parameters
Name | Type | Default value |
---|---|---|
id | string | undefined |
scale | number | undefined |
animated | boolean | false |
dark | boolean | true |
Returns
string
Defined in
glob_to_regex
▸ glob_to_regex(input
): string
Parameters
Name | Type |
---|---|
input | string |
Returns
string
Defined in
has
▸ has<T
>(object
, key
): key is keyof T
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
object | T |
key | PropertyKey |
Returns
key is keyof T
Defined in
importRsaKey
▸ importRsaKey(pem
, uses?
): Promise
<CryptoKey
>
Parameters
Name | Type |
---|---|
pem | string |
uses | KeyUsage [] |
Returns
Promise
<CryptoKey
>
Defined in
isValidShortcut
▸ isValidShortcut(key
): boolean
Parameters
Name | Type |
---|---|
key | string |
Returns
boolean
Defined in
makeAddonIdChecker
▸ makeAddonIdChecker(input
): RegExp
Parameters
Name | Type |
---|---|
input | string |
Returns
RegExp
Defined in
make_enum
▸ make_enum<T
>(...input
): FakeEnum
<T
>
Type parameters
Name | Type |
---|---|
T | extends string |
Parameters
Name | Type |
---|---|
...input | T [] |
Returns
FakeEnum
<T
>
Defined in
make_enum_flags
▸ make_enum_flags<T
>(...input
): FakeEnumFlags
<T
>
Type parameters
Name | Type |
---|---|
T | extends string |
Parameters
Name | Type |
---|---|
...input | T [] |
Returns
FakeEnumFlags
<T
>
Defined in
map_equals
▸ map_equals(first
, second
): boolean
Parameters
Name | Type |
---|---|
first | Map <any , any > |
second | Map <any , any > |
Returns
boolean
Defined in
matchScreen
▸ matchScreen(screens
, options
): undefined
| ScreenDimensions
Parameters
Name | Type |
---|---|
screens | ScreenDimensions [] |
options | ScreenOptions |
Returns
undefined
| ScreenDimensions
Defined in
maybe_call
▸ maybe_call<T
>(input
, ctx
, ...args
): MaybeReturn
<T
>
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
input | T |
ctx | any |
...args | MaybeParameters <T > |
Returns
MaybeReturn
<T
>
Defined in
normalizeAddonIdForComparison
▸ normalizeAddonIdForComparison(input
): string
Parameters
Name | Type |
---|---|
input | string |
Returns
string
Defined in
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
Name | Type |
---|---|
TFunc | extends AnyFunction |
TReturn | Awaited <ReturnType <TFunc >> |
Parameters
Name | Type |
---|---|
fn | TFunc |
Returns
fn
▸ (this
, ...args
): Promise
<TReturn
>
Parameters
Name | Type |
---|---|
this | ThisParameterType <TFunc > |
...args | Parameters <TFunc > |
Returns
Promise
<TReturn
>
Defined in
pick_random
▸ pick_random<T
>(obj
): T
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
obj | T [] |
Returns
T
Defined in
▸ pick_random<T
, K
>(obj
): T
[K
]
Type parameters
Name | Type |
---|---|
T | extends object |
K | extends string | number | symbol |
Parameters
Name | Type |
---|---|
obj | T |
Returns
T
[K
]
Defined in
set_equals
▸ set_equals(first
, second
): boolean
Parameters
Name | Type |
---|---|
first | Set <any > |
second | Set <any > |
Returns
boolean
Defined in
sha256
▸ sha256(message
): Promise
<string
>
Parameters
Name | Type |
---|---|
message | string |
Returns
Promise
<string
>
Defined in
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
Name | Type | Default value | Description |
---|---|---|---|
object | T | undefined | The thing to copy. |
depth? | number | 2 | The maximum depth to explore the object. |
seen? | Set <any > | undefined | A Set of seen objects. Internal use only. |
Returns
T
The copy to safely store or use.
Export
Defined in
shallow_object_equals
▸ shallow_object_equals(first
, second
): boolean
Parameters
Name | Type |
---|---|
first | any |
second | any |
Returns
boolean
Defined in
sleep
▸ sleep(delay
): Promise
<void
>
Parameters
Name | Type |
---|---|
delay | number |
Returns
Promise
<void
>
Defined in
split_chars
▸ split_chars(str
): null
| RegExpMatchArray
| never
[]
Parameters
Name | Type |
---|---|
str | string |
Returns
null
| RegExpMatchArray
| never
[]
Defined in
substr_count
▸ substr_count(str
, needle
): number
Return the number of times a substring is found within a string.
Parameters
Name | Type | Description |
---|---|---|
str | string | The string to search within. |
needle | string | The substring to search for. |
Returns
number
The number of matches found.
Defined in
timeout
▸ timeout<TReturn
>(promise
, delay
): Promise
<TReturn
>
Type parameters
Name | Type |
---|---|
TReturn | unknown |
Parameters
Name | Type |
---|---|
promise | Promise <TReturn > |
delay | number |
Returns
Promise
<TReturn
>
Defined in
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
Name | Type | Default value | Description |
---|---|---|---|
input | string | undefined | The string to truncate. |
target | number | 100 | The target length for the result |
overage | number | 15 | Accept up to this many additional characters for a better result |
ellipsis | string | '…' | The string to append when truncating |
break_line | boolean | true | If true, attempt to break at the first LF |
trim | boolean | true | If true, runs trim() on the string before truncating |
Returns
string
The truncated string