Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EnumCursor<E, K>

Type parameters

  • E

  • K: string

Hierarchy

Implements

Index

Constructors

constructor

  • new EnumCursor(enumObject: {}, n?: number): EnumCursor
  • Parameters

    • enumObject: {}

      The full enumeration.

    • Default value n: number = 0

      The starting position of the cursor. Defaults to 0.

    Returns EnumCursor

Properties

Protected cursor

cursor: number

Protected default

default: number | (() => number)

Protected enumObject

enumObject: any

Readonly event

event: IEventEmitter<this, IEnumCursorEvents<E>> = new EventEmitter<this, E>(this)

Protected values

values: E[]

Methods

filter

  • filter(filter: (name: string, value: E) => boolean): this
  • Filters the valid enum entries. This causes the internal list of enum entries to be refreshed. If the cursor has been set previously, it will likely be moved to a different entry.

    Parameters

    • filter: (name: string, value: E) => boolean

      A function that takes a name and enum value and returns whether the entry should be included.

        • (name: string, value: E): boolean
        • Parameters

          • name: string
          • value: E

          Returns boolean

    Returns this

get

  • get(): E
  • Returns the entry at the cursor position.

    Returns E

getRandomPosition

  • getRandomPosition(): number
  • Retrieves a random cursor position

    Returns number

move

  • move(amt: number): E
  • If the given amount is positive, moves forward that many entries. If the given amount is negative, moves backward that many entries.

    Parameters

    • amt: number

    Returns E

    The entry at the new cursor position.

moveTo

  • moveTo(n: number): this
  • Sets the cursor position.

    Parameters

    • n: number

    Returns this

moveToDefault

  • moveToDefault(): E
  • Moves to the default cursor position.

    Returns E

moveToEnumEntry

  • moveToEnumEntry(entry: E): E
  • Sets the cursor position to the position of this enum entry in the filtered list.

    Parameters

    • entry: E

    Returns E

    The entry at the new cursor position.

moveToRandom

  • moveToRandom(): E
  • Moves the cursor to a random entry, then returns that entry.

    Returns E

next

  • next(): E
  • Moves the cursor forward one entry, and returns the new entry.

    Returns E

previous

  • previous(): E
  • Moves the cursor backward one entry, and returns the new entry.

    Returns E

refresh

  • refresh(): this
  • Refreshes the internal list of enum entries. If the full enumeration has changed, the cursor may be moved to a different entry.

    Returns this

setDefault

  • setDefault(n: number): this
  • setDefault(generator: () => number): this
  • setDefault(defaultGenerator: EnumCursorDefaultGenerator): this
  • Sets the default cursor position.

    Parameters

    • n: number

    Returns this

  • Sets a handler for retrieving the default cursor position.

    Parameters

    • generator: () => number
        • (): number
        • Returns number

    Returns this

  • Sets a handler for retrieving the default cursor position to a pre-implemented method by EnumCursorDefaultGenerator entry.

    Parameters

    Returns this

setDefaultToEntry

  • setDefaultToEntry(entry: E): this
  • Sets the default cursor position to the position of the given entry in this cursor.

    Parameters

    • entry: E

    Returns this

Generated using TypeDoc