Skip to content

API Documentation

Mubarrat edited this page Dec 29, 2023 · 5 revisions

Scripts-Loader JavaScript Library API Documentation

detectFormatXmlOrJson

  • Description: Determines the format (XML or JSON) of the provided script configuration.
  • Parameters:
    • data: string: The script configuration data as a string.
  • Returns: A string indicating the detected format ("xml" or "json"). Or, an empty string if it's neither XML nor JSON.

loadScript

  • Description: Loads scripts using the Scripts Loader library based on the specified rendering mode.
  • Parameters:
    • data: ScriptArray: An array of script objects containing script details.
    • renderer: "document" | "ajax" | "fetch": The chosen rendering mode ("document", "ajax", or "fetch").
  • Returns: None

ScriptArray

  • Description: Represents an array structure for managing script objects.
  • Properties:
    • add(scriptObject): number: Adds a script object to the ScriptArray.
    • names: string[]: An array containing names of the script objects.

ScriptObject

  • Description: Defines the structure of a single script object.
  • Properties:
    • name: string: A string representing the name of the script.
    • sources: string[]: An array of strings containing script sources.
    • dependencies: string[]: An array of strings representing dependencies.
    • promises: Promise<void>[]: An array of promises used for script loading.

$ls (Load Scripts) Shortcut

Methods for XML Handling

  • $ls.xml.document(data) or $ls.xml(data)

    • Description: Loads scripts in document mode from XML data.
    • Parameters:
      • data: string: XML data as a string.
  • $ls.xml.ajax(data)

    • Description: Loads scripts in AJAX mode from XML data.
    • Parameters:
      • data: string: XML data as a string.
  • $ls.xml.fetch(data) Added In Version 1.1.0

    • Description: Fetches scripts from XML data.
    • Parameters:
      • data: string: XML data as a string.

Methods for JSON Handling

  • $ls.json.document(data) or $ls.json(data)

    • Description: Loads scripts in document mode from JSON data.
    • Parameters:
      • data: string: JSON data as a string.
  • $ls.json.ajax(data)

    • Description: Loads scripts in AJAX mode from JSON data.
    • Parameters:
      • data: string: JSON data as a string.
  • $ls.json.fetch(data) Added In Version 1.1.0

    • Description: Fetches scripts from JSON data.
    • Parameters:
      • data: string: JSON data as a string.

Methods for Generic Handling

  • $ls.document(data) or $ls(data)

    • Description: Loads scripts in document mode.
    • Parameters:
      • data: {}[]: Array of script objects.
  • $ls.ajax(data)

    • Description: Loads scripts in AJAX mode.
    • Parameters:
      • data: {}[]: Array of script objects.
  • $ls.fetch(data) Added In Version 1.1.0

    • Description: Fetches scripts.
    • Parameters:
      • data: {}[]: Array of script objects.

Methods for Loading Data from Url

  • $ls.url.document(url) or $ls.url(url)

    • Description: Loads scripts in document mode.
    • Parameters:
      • url: string: The URL where is the data.
  • $ls.url.ajax(url)

    • Description: Loads scripts in AJAX mode.
    • Parameters:
      • url: string: The URL where is the data.
  • $ls.url.fetch(url) Added In Version 1.1.0

    • Description: Fetches scripts.
    • Parameters:
      • url: string: The URL where is the data.

Validation Functions

validateAsScriptArray

  • Description: Validates data as a ScriptArray.
  • Parameters:
    • data: {}[]: Data to be validated.
  • Returns: A validated ScriptArray.

validateJsonAsScriptArray

  • Description: Validates JSON data as a ScriptArray.
  • Parameters:
    • data: string: JSON data as a string.
  • Returns: A validated ScriptArray.

validateXmlAsScriptArray

  • Description: Validates XML data as a ScriptArray.
  • Parameters:
    • data: string: XML data as a string.
  • Returns: A validated ScriptArray.