Utilities

LittleJS Utility Classes and Functions

  • General purpose utilities
  • Timer - tracks time automatically

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:
NameTypeDescription
urlstring

URL of JSON file

Returns:
Type: 
Promise.<object>

(static) formatTime(t) → {string}

Formats seconds to mm:ss style for display purposes

Parameters:
NameTypeDescription
tnumber

time in seconds

Returns:
Type: 
string

(static) saveCanvas(canvas, filenameopt, typeopt)

Save a canvas to disk

Parameters:
NameTypeAttributesDefaultDescription
canvasHTMLCanvasElement | OffscreenCanvas
filenamestring<optional>
screenshot
typestring<optional>
image/png

(static) saveDataURL(url, filenameopt, revokeTimeopt)

Save a data url to disk

Parameters:
NameTypeAttributesDefaultDescription
urlstring
filenamestring<optional>
download
revokeTimenumber<optional>

how long before revoking the url

(static) saveText(text, filenameopt, typeopt)

Save a text file to disk

Parameters:
NameTypeAttributesDefaultDescription
textstring
filenamestring<optional>
text
typestring<optional>
text/plain

(static) shareURL(title, url, callbackopt)

Share content using the native share dialog if available

Parameters:
NameTypeAttributesDescription
titlestring

title of the share

urlstring

url to share

callbackfunction<optional>

Called when share is complete