-
-
Notifications
You must be signed in to change notification settings - Fork 4
BaseProvider.js
BaseProvider module This module should be used as the basis for new providers
Author: William Leemans
Copyright: William Leemans 2024
-
BaseProvider
- .providerError
-
.baseProvider
- new exports.baseProvider(actor)
-
.providerFullFilePath ⇒
string -
.cleanFoundryMarkup(value, helper) ⇒
string -
.clone() ⇒
Object -
.createFile() ⇒
Promise - .download(providerRootPath, providerFilePath, providerDestinationFileName, [postDownloadFunction])
-
.loadImage(src) ⇒
Promise.<HTMLImageElement> - .notify(severity, message, [options])
- .parseValue(value, parser) ⇒
- .saveFile()
- .updateFile()
-
.uploadCustomProviderFile() ⇒
Promise -
.urlExists(url) ⇒
boolean
An error class to use for raising Provider-related errors
Kind: static class of BaseProvider
| 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 |
The base Provider class with required basic functionality for all providers
Kind: static class of BaseProvider
-
.baseProvider
- new exports.baseProvider(actor)
-
.providerFullFilePath ⇒
string -
.cleanFoundryMarkup(value, helper) ⇒
string -
.clone() ⇒
Object -
.createFile() ⇒
Promise - .download(providerRootPath, providerFilePath, providerDestinationFileName, [postDownloadFunction])
-
.loadImage(src) ⇒
Promise.<HTMLImageElement> - .notify(severity, message, [options])
- .parseValue(value, parser) ⇒
- .saveFile()
- .updateFile()
-
.uploadCustomProviderFile() ⇒
Promise -
.urlExists(url) ⇒
boolean
| Param | Type | Description |
|---|---|---|
| actor | Object |
The Foundry VTT actor object. |
Get the full path to the provider being used
Kind: instance property of baseProvider
Returns: string - the correct URL to the provider
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 |
Deep clone the Provider
Kind: instance method of baseProvider
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 |
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. |
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. |
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
|
Save the file
Kind: instance method of baseProvider
Update the file
Kind: instance method of baseProvider
Upload the file and return it as an ArrayBuffer
Kind: instance method of baseProvider
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 |