Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Util

JMap.Util

Here you'll find all JMap utility methods

Index

Functions

asyncProcess

  • asyncProcess(callback: function, timeoutsInMilliseconds: number[]): function
  • JMap.Util.asyncProcess

    Run the parameter function after one or multiple delays.

    You can cancel the repetition by running the function returned by asyncProcess

    throws

    if callback is not a function, if timeoutsInMilliseconds is not a non-empty array of number

    example
    
    // Print "Hello World" 4 times then cancel it before printing the last repetition
    const myHelloWorldFunction = () => console.log("Hello World")
    const stopProcessing = JMap.Util.asyncProcess(myHelloWorldFunction, [1000, 1000, 1000, 1000, 1000])
    setTimeout(() => stopProcessing(), 4100)

    Parameters

    • callback: function

      The function to run

        • (): any
        • Returns any

    • timeoutsInMilliseconds: number[]

      An array of delay in milliseconds

    Returns function

    a function that will cancel the process if called

      • (): void
      • Returns void

checkJmapId

  • checkJmapId(id: any, message?: undefined | string): void
  • JMap.Util.checkJmapId

    Throws an Error if the passed Id is not a valid JMap Id, otherwise does nothing. You can use this method as a safeguard in your methods that accept JMap Ids. JMap.Util.checkJmapId always run a strict check on the passed value, i.e. the string "123" will not pass. If you want the value to be compliant, you can use JMap.Util.getJmapIdAsIntegerIfPossible to transform it.

    throws

    Error if the passed value is not a valid JMap Id

    example
    
    JMap.Util.checkJmapId("")
    // Error thrown "Invalid JMap Id"
    
    JMap.Util.checkJmapId("", "My custom error message")
    // Error thrown "My custom error message"
    
    JMap.Util.checkJmapId(4)
    // undefined

    Parameters

    • id: any

      The JMap Id to validate

    • Optional message: undefined | string

      Optional message that will be used in the thrown error if the passed value doesn't pass the check.

    Returns void

getJmapIdAsIntegerIfPossible

  • getJmapIdAsIntegerIfPossible(id: any): JId
  • JMap.Util.getJmapIdAsIntegerIfPossible

    Converts the passed Id as a numeric JMap Id if possible. This utility function can be used to transform serialized or otherwise stringified JMap Ids that would normally be expressed as integers. For instance, if you extract a JMap Id from a query string, the query param "3" would be returned a an integer (3). If the passed value cannot be converted to a valid JMap numeric Id, it will be returned as-is, if valid. If not valid, an error is thrown.

    throws

    Error if the passed Id is not a valid JMap Id

    example
    
    JMap.Util.getJmapIdAsIntegerIfPossible("1")
    // 1
    
    JMap.Util.getJmapIdAsIntegerIfPossible("1.4")
    // throw Error
    
    JMap.Util.getJmapIdAsIntegerIfPossible("f3af01ab-4042-4ccf-be04-33dc96228ce7")
    // "f3af01ab-4042-4ccf-be04-33dc96228ce7"

    Parameters

    • id: any

      The JMap Id to convert

    Returns JId

isJMapId

  • isJMapId(id: any, allowStringNumber?: undefined | false | true): boolean
  • JMap.Util.isJMapId

    Validates if the value passed is either a string uuid (for instance, "f3af01ab-4042-4ccf-be04-33dc96228ce7"), or a numeric ID (integer, can be negative) If the allowStringNumber param is true, the string "123" will be considered as a valid numeric ID. allowStringNumber is false by default

    example
    
    JMap.Util.isJMapId(1)
    // true
    
    JMap.Util.isJMapId("1")
    // false
    
    JMap.Util.isJMapId("1", true)
    // true
    
    JMap.Util.isJMapId("f3af01ab-4042-4ccf-be04-33dc96228ce7")
    // true

    Parameters

    • id: any

      The JMap Id to validate

    • Optional allowStringNumber: undefined | false | true

      Optional parameter. false by default.

    Returns boolean

loadJSFile

  • loadJSFile(fileUrl: string): Promise<void>
  • JMap.Util.loadJSFile

    Load an external JS File then resolve when file has been loaded.

    example
    
    // load your custom JS file dynamically
    JMap.Util.loadJSFile("https://mysever/toLoadFile.js")

    Parameters

    • fileUrl: string

      the JS URL to load

    Returns Promise<void>