Options
All
  • Public
  • Public/Protected
  • All
Menu

@rxluz/js-enum

Index

Functions

createEnum

  • createEnum(items: []): object
  • Creates the enum itself

    Parameters

    • items: []

      The items that will be addded in enum.

    Returns object

    Returns an object with key and value.

getKey

  • getKey(item: string | ReadonlyArray<any>): any
  • Get the key name that will be used to create the ENUM object, this could be the item case the item is a string or the first element of array case the item is a array

    Parameters

    • item: string | ReadonlyArray<any>

      The string or array that correspond to the current item

    Returns any

    Return true case the items are valid, or false case there are no items

getValue

  • getValue(item: string | ReadonlyArray<string>, index: any): string
  • Get the value that will be used to create the ENUM object, this value could be the index number or a custom value sent in item array

    Parameters

    • item: string | ReadonlyArray<string>

      The string or array that correspond to the current item

    • index: any

      The current index that will be used case the user didn't send a custom value

    Returns string

    Return true case the items are valid, or false case there are no items

isValidItems

  • isValidItems(items: ReadonlyArray<any>): boolean
  • Verify if the received items are valid to create an enum, emits an error case the items schema is invalid

    Parameters

    • items: ReadonlyArray<any>

      The items that will be addded in enum.

    Returns boolean

    Return true case the items are valid, or false case there are no items

jsENUM

  • jsENUM(...items: any): object
  • An ENUM implementation in JS

    Example (es module)

    import jsENUM from '@rxluz/js-enum';
    
    const direction = jsENUM('UP', 'DOWN', 'LEFT', 'RIGHT');
    const myDirection = direction.DOWN;

    Example (commonjs)

    var jsENUM = require('@rxluz/js-enum').default;
    
    const direction = jsENUM('UP', 'DOWN', 'LEFT', 'RIGHT');
    const myDirection = direction.DOWN;
    compability

    Works in the browser as well as node.

    Parameters

    • Rest ...items: any

    Returns object

    Returns an object with key and value.

Generated using TypeDoc