Skip to content
This repository was archived by the owner on Oct 4, 2025. It is now read-only.

BaseProvider.js

William edited this page Jul 31, 2024 · 8 revisions

BaseProvider

BaseProvider module This module should be used as the basis for new providers

Author: William Leemans
Copyright: William Leemans 2024

BaseProvider.providerError

An error class to use for raising Provider-related errors

Kind: static class of BaseProvider

new exports.providerError(className, methodName, message, [errorClassName])

Param Type Default Description
className string The name of the class the error is related to
methodName string The name of the method the error is related to
message string An error message
[errorClassName] string "'providerError'" the name of the error class raising the error

BaseProvider.baseProvider

The base Provider class with required basic functionality for all providers

Kind: static class of BaseProvider

new exports.baseProvider(actor)

Param Type Description
actor Object The Foundry VTT actor object.

baseProvider.providerFullFilePath ⇒ string

Get the full path to the provider being used

Kind: instance property of baseProvider
Returns: string - the correct URL to the provider

baseProvider.cleanFoundryMarkup(value, helper) ⇒ string

Cleanup Foundry Markup entries

Kind: instance method of baseProvider
Returns: string - Returns the cleaned string

Param Type Description
value string the string to be cleaned
helper object the helper object to use to clean up the value

baseProvider.clone() ⇒ Object

Deep clone the Provider

Kind: instance method of baseProvider

baseProvider.createFile() ⇒ Promise

Create a new file

Kind: instance method of baseProvider
Returns: Promise - must return a promise with the attribute ok set to true if it is ok.

baseProvider.download(providerRootPath, providerFilePath, providerDestinationFileName, [postDownloadFunction])

The default function to download whatever provider is used and save it This is here to not fail when the provider definition doesn't have it.

Kind: instance method of baseProvider

Param Type Default Description
providerRootPath string the URI of the provider
providerFilePath string the URI of the file to use, relative to the providerPath
providerDestinationFileName string the name of the file to be saved
[postDownloadFunction] function Function the function to be executed after execution

baseProvider.loadImage(src) ⇒ Promise.<HTMLImageElement>

A function to fetch an image and return an image object promise

Kind: instance method of baseProvider
Returns: Promise.<HTMLImageElement> - - A promise that resolves with the loaded image.
Throws:

  • Error - Throws an error if the image fails to load.
Param Type Description
src string The URL to the image to be used.

baseProvider.notify(severity, message, [options])

Notifier to display messages while parsing data. Will use the Foundry VTT notifier by default but falls back on console if ui.notifications is not available.

Kind: instance method of baseProvider

Param Type Description
severity string The severity of the message (debug, error, warning, info).
message string The message to display.
[options] Object Additional options for ui.notifications.

baseProvider.parseValue(value, parser) ⇒

asynchronously parse a value through a function

Kind: instance method of baseProvider
Returns: the parsed value

Param Type Description
value any | Promise the value to be parsed
parser function the parser function, arguments passed are the (awaited) value and this

baseProvider.saveFile()

Save the file

Kind: instance method of baseProvider

baseProvider.updateFile()

Update the file

Kind: instance method of baseProvider

baseProvider.uploadCustomProviderFile() ⇒ Promise

Upload the file and return it as an ArrayBuffer

Kind: instance method of baseProvider

baseProvider.urlExists(url) ⇒ boolean

Check if a given URL exists

Kind: instance method of baseProvider
Returns: boolean - whether or not the URL exists

Param Type Description
url string a correct url

Clone this wiki locally