The Matter.Common module contains utility functions that are common to all modules.

Hierarchy

  • default

Constructors

Properties

_baseDelta: number = ...
_decomp: null = null
_nextId: number = 0
_nowStartTime: number = +new Date()
_seed: number = 0
_warnedOnce: Record<string, boolean> = {}
logLevel: LogLevel = LogLevel.Debug

The console logging level to use, where each level includes all levels above and excludes the levels below. The default level is 'debug' which shows all console messages.

Methods

  • Type Parameters

    Parameters

    • node: keyof T
    • visited: Record<keyof T, boolean>
    • temp: Record<keyof T, boolean>
    • graph: T
    • result: (keyof T)[]

    Returns void

  • Takes n functions as arguments and returns a new function that calls them in order. The arguments applied when calling the new function will also be applied to every function passed. The value of this refers to the last value returned in the chain that was not undefined. Therefore if a passed function does not return a value, the previously returned value is maintained. After all passed functions have been called the new function returns the last returned value (if any). If any of the passed functions are a chain, then the chain will be flattened.

    Parameters

    • Rest ...params: Function[]

      The functions to chain.

    Returns Function

    A new function that calls the passed functions in order.

  • Chains a function to excute after the original function on the given path relative to base. See also docs for Common.chain.

    Type Parameters

    • T extends Record<string, any>

    Parameters

    • base: T

      The base object

    • path: string

      The path relative to base

    • func: Function

      The function to chain after the original

    Returns T[keyof T]

    The chained function that replaced the original

  • Chains a function to excute before the original function on the given path relative to base. See also docs for Common.chain.

    Type Parameters

    Parameters

    • base: T

      The base object

    • path: string

      The path relative to base

    • func: Function

      The function to chain before the original

    Returns Function

    The chained function that replaced the original

  • Randomly chooses a value from a list with equal probability. The function uses a seeded random generator.

    Type Parameters

    • T

    Parameters

    • choices: T[]

    Returns T

    A random choice object from the array

  • Returns the given value clamped between a minimum and maximum value.

    Parameters

    • value: number
    • min: number
    • max: number

    Returns number

    The value clamped between min and max inclusive

  • Creates a new clone of the object, if deep is true references will also be cloned.

    Type Parameters

    Parameters

    • obj: T
    • Optional deep: boolean

    Returns T

    obj cloned

  • Parameters

    • colorString: string

    Returns number

  • Shows a deprecated console warning when the function on the given object is called. The target function will be replaced with a new function that first shows the warning and then calls the original function.

    Type Parameters

    Parameters

    • obj: T

      The object or module

    • prop: keyof T
    • warning: string

      The one-time message to show if the function is called

    Returns void

  • Extends the object in the first argument using the object in the second argument.

    Type Parameters

    Parameters

    • obj: T
    • Optional deep: boolean | E
    • Rest ...params: E[]

    Returns T & E

    obj extended

  • Type Parameters

    Parameters

    • obj: DeepPartial<T>
    • Optional deep: boolean | T
    • Rest ...params: T[]

    Returns T

  • Type Parameters

    Parameters

    Returns T

  • Gets a value from base relative to the path string.

    Type Parameters

    Parameters

    • obj: T

      The base object

    • path: string

      The path relative to base, e.g. 'Foo.Bar.baz'

    • Optional begin: number

      Path slice begin

    • Optional end: number

      Path slice end

    Returns T

    The object at the given path

  • Returns the poly-decomp library module provided through Common.setDecomp, otherwise returns the global decomp if set.

    Returns any

    The poly-decomp library module if provided.

  • Shows a console.info message only if the current Common.logLevel allows it. The message will be prefixed with 'matter-ts' to make it easily identifiable.

    Parameters

    • Rest ...params: string[]

      The objects to log.

    Returns void

  • Returns true if the object is an array.

    Type Parameters

    • T

    Parameters

    • obj: T | T[]

    Returns obj is T[]

    True if the object is an array, otherwise false

    Method

    isArray

  • Returns true if the object is a HTMLElement, otherwise false.

    Parameters

    • obj: any

    Returns obj is HTMLElement

    True if the object is a HTMLElement, otherwise false

    Method

    isElement

  • Returns true if the object is an Object.

    Parameters

    • value: unknown

    Returns value is ObjectLike<any>

    True if the object is an Object, otherwise false

    Method

    isObject

  • Returns the list of keys for the given object.

    Type Parameters

    Parameters

    • obj: T

    Returns (keyof T)[]

    keys

    Method

    keys

  • Shows a console.log message only if the current Common.logLevel allows it. The message will be prefixed with 'matter-ts' to make it easily identifiable.

    Parameters

    • Rest ...params: string[]

      The objects to log.

    Returns void

  • Returns the current timestamp since the time origin (e.g. from page load). The result is in milliseconds and will use high-resolution timing if available.

    Returns number

    the current timestamp in milliseconds

    Method

    now

  • Parameters

    • min: number = 0
    • max: number = 1

    Returns number

  • Sets a value on base relative to the given path string.

    Type Parameters

    • T

    Parameters

    • obj: ObjectLike<T>

      The base object

    • path: string

      The path relative to base, e.g. 'Foo.Bar.baz'

    • val: T

      The value to set

    • Optional begin: number

      Path slice begin

    • Optional end: number

      Path slice end

    Returns T

    Pass through val for chaining

  • Provide the poly-decomp library module to enable concave vertex decomposition support when using Bodies.fromVertices e.g. Common.setDecomp(require('poly-decomp')).

    Parameters

    Returns void

  • Shuffles the given array in-place. The function uses a seeded random generator.

    Type Parameters

    • T

    Parameters

    • array: T[]

    Returns T[]

    array shuffled randomly

  • Returns the sign of the given value.

    Parameters

    • value: number

    Returns 1 | -1

    -1 if negative, +1 if 0 or positive

    Method

    sign

  • Takes a directed graph and returns the partially ordered set of vertices in topological order. Circular dependencies are allowed.

    Type Parameters

    Parameters

    • graph: T

    Returns (keyof T)[]

    Partially ordered set of vertices in topological order.

  • Returns the list of values for the given object.

    Type Parameters

    • T

    Parameters

    Returns T[]

    Array of the objects property values

    Method

    values

  • Shows a console.warn message only if the current Common.logLevel allows it. The message will be prefixed with 'matter-js' to make it easily identifiable.

    Parameters

    • Rest ...params: string[]

      The objects to log.

    Returns void

  • Uses Common.warn to log the given message one time only.

    Parameters

    • Rest ...params: string[]

      The objects to log.

    Returns void

Generated using TypeDoc