LittleJS Utility Classes and Functions
- General purpose utilities
- Timer - tracks time automatically
- Source
Methods
(async, static) fetchJSON(url) → {Promise.<object>}
Fetches a JSON file from a URL and returns the parsed JSON object. Must be used with await!
Parameters:
| Name | Type | Description |
|---|---|---|
url | string | URL of JSON file |
- Source
Returns:
- Type:
- Promise.<object>
(static) formatTime(t) → {string}
Formats seconds to mm:ss style for display purposes
Parameters:
| Name | Type | Description |
|---|---|---|
t | number | time in seconds |
- Source
Returns:
- Type:
- string
(static) saveCanvas(canvas, filenameopt, typeopt)
Save a canvas to disk
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
canvas | HTMLCanvasElement | | |||
filename | string | <optional> | screenshot | |
type | string | <optional> | image/png |
- Source
(static) saveDataURL(url, filenameopt, revokeTimeopt)
Save a data url to disk
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url | string | |||
filename | string | <optional> | download | |
revokeTime | number | <optional> | how long before revoking the url |
- Source
(static) saveText(text, filenameopt, typeopt)
Save a text file to disk
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
text | string | |||
filename | string | <optional> | text | |
type | string | <optional> | text/plain |
- Source
(static) shareURL(title, url, callbackopt)
Share content using the native share dialog if available
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
title | string | title of the share | |
url | string | url to share | |
callback | function | <optional> | Called when share is complete |
- Source