Utils

Methods

# (static) allset(fields) → {boolean}

Returns whether each parameter is neither undefined nor null.

NOTE: This function does not have the noEmptyString parameter and will always disallow empty strings.

If you need to allow those, please chain the Utils.isset function in your code and use the noEmptyString parameter there.

Parameters:
Name Type Attributes Description
fields any <repeatable>

Various amount of parameters you want to check.

Since:
  • 1.0.0
Returns:
Type
boolean

# (static) callFunc(funcName, params)

Checks whether a function exists on the window and then calls it with the passed parameters.

NOTE: The function has to directly exist on the window and can not be nested.

Parameters:
Name Type Attributes Description
funcName string

The name of the function to call. Has to be a string.

params any <repeatable>

A various amount of parameters to pass to the function.

Since:
  • 1.0.0

# (static) camelCaseToKebabCase(camelCase) → {string}

Converts a camel case string to kebab case. If no uppercase letter was found, this will just return the original string.

E.g. the string "HelloWorld" becomes "hello-world", but "helloworld" remains unchanged.

Parameters:
Name Type Description
camelCase string

The camel case string you want to convert.

Since:
  • 1.0.0
Returns:
Type
string

# (static) containsText(text, snippet, caseSensitiveopt) → {boolean|null}

Returns whether the text contains the given snippet.

If either text or snippet is not of type string, this will return null.

Parameters:
Name Type Attributes Default Description
text string

The text to check.

snippet string

The snippet to search for.

caseSensitive boolean <optional>
false

Determines if the check should be case-sensitive.

Since:
  • 1.0.0
Returns:
Type
boolean | null

# (static) createList(baseText, splitteropt, deleteEmptyStringsopt) → {Array.<string>}

Creates and returns a list (Array) from a comma-separated string, after removing whitespaces with Utils.trimSpaces.

The splitter character can be changed for more flexibility. Defaults to a comma.

If the passed baseText is not of type string, this function just returns an empty array.

Parameters:
Name Type Attributes Default Description
baseText string

The string you want to create a list from.

splitter string <optional>
','

The character you want to use as a separator for each entry.

deleteEmptyStrings boolean <optional>
false

If set to true, the returned list will not contain empty strings ("")

Since:
  • 1.0.0
Returns:
Type
Array.<string>

# (static) divisibleBy(dividend, divisor) → {boolean}

Returns whether the first parameter (dividend) is divisible by the second parameter (divisor) without remainder.

Uses a modulo calculation internally.

Parameters:
Name Type Description
dividend number

Dividend

divisor number

Divisor

Since:
  • 1.0.0
Returns:
Type
boolean

# (static) formatCurrency(amount, currencyCode, localeopt) → {string}

Formats the given number to a matching currency string.

If the amount has no decimal places, only the number itself will be shown.

E.g. 20.00 => 20€, but 4.2 => 4,20€. (Trailing zeros would normally be omitted)

Parameters:
Name Type Attributes Description
amount number

The amount to format

currencyCode string

An ISO 4217 currency code. E.g. USD for $, EUR for €, RUB for ₽.

locale string | undefined <optional>

The locale code for your country. If this value is undefined, the browser will try setting the right value for you.

Since:
  • 1.0.0
Returns:
Type
string

# (static) formatTimerValue(number) → {string}

Formats timer numbers to always have 2 digits. So 3 becomes 03, but 11 remains unchanged.

NOTE: This returns the new value as string and not as a number.

Parameters:
Name Type Description
number number
Returns:
Type
string

# (static) funcExists(funcName) → {boolean}

Returns whether the given function name exists on the window.

NOTE: The function has to directly exist on the window and can not be nested.

Parameters:
Name Type Description
funcName string

The name of the function to check for. Has to be a string.

Since:
  • 1.0.0
Returns:
Type
boolean

# (static) getChromeVersion(fullVersionopt) → {number}

Returns the Chrome version as numeric value or 0, if either no version was found or the browser is not Chromium-based.

Parameters:
Name Type Attributes Default Description
fullVersion boolean <optional>
false

If set to true, the full version will be returned as string instead.

Since:
  • 1.0.0
Returns:
Type
number

# (static) getPercentageOf(value, percentageOf) → {number}

Returns what percentage the first parameter is of the second.

If you pass 10 and 50 you would get 20, since 10 is 20% of 50.

Parameters:
Name Type Description
value number
percentageOf number
Since:
  • 1.0.0
Returns:
Type
number

# (static) getRandomDecimal(min, max, decimalPlacesopt) → {number}

Generates and returns a random decimal number in the range of the given numbers.

You can also define how many decimal places you want to keep. (Defaults to 2)

The parameter values are inclusive, but possibly very unlikely to hit depending on the range and number of decimal places.

Parameters:
Name Type Attributes Default Description
min number

Minimum value of the range.

max number

Maximum value of the range.

decimalPlaces number <optional>
2

The number of decimal places you want to keep in the result

Since:
  • 1.0.0
Returns:
Type
number

# (static) getRandomHexColor() → {string}

Generates and returns a random color as hex-string.

Since:
  • 1.0.0
Returns:
Type
string

# (static) getRandomNumber(min, max) → {number}

Generates and returns a random integer in the range of the given numbers.

The parameter values are inclusive.

So, calling Utils.getRandomNumber(1, 3) returns either 1, 2 or 3.

Parameters:
Name Type Description
min number

Minimum value of the range.

max number

Maximum value of the range.

Since:
  • 1.0.0
Returns:
Type
number

# (static) getRandomRGBAColor(alphaopt) → {string}

Generates and returns a random color as RGBA-string.

You can pass the alpha value as parameter. (Defaults to 1)

Parameters:
Name Type Attributes Default Description
alpha number <optional>
1

The decimal value for the alpha-channel (transparency) between 0 and 1.

Since:
  • 1.0.0
Returns:
Type
string

# (static) getRandomRGBColor() → {string}

Generates and returns a random color as RGB-string.

Since:
  • 1.0.0
Returns:
Type
string

# (static) isBrowserSource() → {boolean}

Returns whether the current window is inside of an OBS-BrowserSource.

Since:
  • 1.0.0
Returns:
Type
boolean

# (static) isChrome() → {boolean}

Returns whether the current browser is Chromium-based.

Since:
  • 1.0.0
Returns:
Type
boolean

# (static) isset(field, noEmptyStringopt) → {boolean}

Returns whether the parameter is neither undefined, an empty string nor null.

The second parameter is an optional check for empty strings, in case you need to allow those in certain scenarios.

Parameters:
Name Type Attributes Default Description
field any

The value you want to check.

noEmptyString boolean <optional>
true

If set to false, this will not check for empty strings.

Since:
  • 1.0.0
Returns:
Type
boolean

# (static) isString(value) → {boolean}

Returns whether the passed value is of type string.

Parameters:
Name Type Description
value *

The value you want to check

Since:
  • 1.0.0
Returns:
Type
boolean

# (static) isWholeNumber(number) → {boolean}

Returns whether the given number is a whole number (integer).

This also includes negative numbers.

E.g. 1 returns true, 1.5 returns false

Parameters:
Name Type Description
number

The number to check

Since:
  • 1.0.0
Returns:
Type
boolean

# (static) kebabCaseToCamelCase(kebabCase) → {string}

Converts a kebab case string to camel case. If no "-" character was found, this will just return the original string.

E.g. the string "hello-world" becomes "helloWorld", but "helloworld" remains unchanged.

Parameters:
Name Type Description
kebabCase string

The kebab case string you want to convert.

Since:
  • 1.0.0
Returns:
Type
string

# (static) matchesRegex(text, regex) → {boolean}

Returns whether the text matches the given regular expression.

Parameters:
Name Type Description
text string

The text to perform the regular expression test on.

regex RegExp

The regular expression to check for. Can either be an instance of RexExp or in literal notation.

Since:
  • 1.0.0
Returns:
Type
boolean

# (static) matchRegexGroups(text, regex) → {object|null}

Tries to match the given RegExp groups to the text and returns the result as object.

If no matches were found, this returns null.

Parameters:
Name Type Description
text string

The text to perform the RegExp on.

regex RegExp

The regular expression to check for. Can either be an instance of RexExp or in literal notation.

Since:
  • 1.0.0
Returns:
Type
object | null

# (static) nextIterator(i, max, stepopt) → {number}

Returns either the counter value incremented by the given step value or starts over at 0 if the counter reached the max value.

Parameters:
Name Type Attributes Default Description
i number

Current iterator value

max number

Maximum value the iterator should not exceed.

step number <optional>
1

The value you want to increment the counter by in each iteration.

Since:
  • 1.0.0
Returns:
Type
number

# (static) parseTier(value, primeAsTier1opt) → {number|string}

Parses the given tier value and returns it either as a number between 1 and 3 or as the string "prime".

Invalid inputs will return 0.

Parameters:
Name Type Attributes Default Description
value string | number

The tier value you want to parse.

primeAsTier1 boolean <optional>
false

If set to true, this will return prime tiers as tier 1 regardless.

Returns:
Type
number | string

# (static) resolves(path, item) → {boolean}

Returns whether the given object path exists on the item.

NOTE: The path has to be a string to prevent the browser from potentially throwing an error.

Also the path should not start with the name of the base item.

So, if you want to check if a.b.c would resolve, you would have to call resolve("b.c", a) instead of resolve("a.b.c", a).

Parameters:
Name Type Description
path string

The path you want to check.

item object

The base object you want to run the check on.

Since:
  • 1.0.0
Returns:
Type
boolean

# (static) resumeSEQueue()

Wrapper function for the default SE_API.resumeQueue() function to ensure availability.

Calling this will manually release the StreamElements queue hold-time, if a widget duration was set in the widgets fields.

Since:
  • 1.0.0

# (static) trimSpaces(text) → {string}

Removes spaces at the end & start of the string and replaces multiple consecutive spaces with only one.

Parameters:
Name Type Description
text string

The string you want to remove whitespaces from.

Since:
  • 1.0.0
Returns:
Type
string