Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

Latest commit

 

History

History
292 lines (182 loc) · 8.22 KB

src-pwa_Core.md

File metadata and controls

292 lines (182 loc) · 8.22 KB

Module pwa/Core

category:test

Source file

Class Core

Core utility methods

Methods

clone(obj) ►

modifier: private modifier: static

Clone an object.

Parameters Type Description
obj Object **
return undefined cloned object.

fingerprint() ► String

modifier: private modifier: static

Generates a device fingerprint based on rendering data on a canvas element - See https://en.wikipedia.org/wiki/Canvas_fingerprinting

Parameters Type Description
return String - An identifier known to be relatively unique per device

dataURLtoBlob(dataurl) ►

modifier: private modifier: static

Converts a data URL to a Blob and returns a Blob URL.

Parameters Type Description
dataurl URL **
return undefined Blob URL

blobToDataURL(blob) ►

modifier: private modifier: static

Converts a Blob into a dataUrl

Parameters Type Description
blob * **
return undefined data URL

getObjectValue(obj, path, def) ►

modifier: private modifier: static

Parameters Type Description
obj Object the object to get a property from
path String path to the property
def Any default to return if the property is undefined
return undefined The value of the property as retrieved

stringifyJs(jsLiteral, replacer, indent) ►

modifier: private modifier: static

Does JS code stringification comparable to JSON.stringify()

Parameters Type Description
jsLiteral Object the JavaScript literal to stringify
replacer function **
indent Number **
return undefined String

quoteKeyIfNeeded(key) ►

modifier: private modifier: static

Returns appropriate use of the given key for identifiers

Parameters Type Description
key * **
return undefined The adequately quoted or non-quoted identifier name

isValidVarName(name) ►

modifier: private modifier: static

Returns true if the given name is valid as variable name

Parameters Type Description
name * **
return undefined Boolean value indicating whether the given name is a valid variable name

scopeEval(scope, script) ►

modifier: private modifier: static

Evaluates a script in the given scope

Parameters Type Description
scope Object the 'this' scope for the script to run in
script String the script to execute
return undefined The return value of the script, if any

resolveVariables(str, cb, ar) ►

modifier: private modifier: static

Resolve variables in strings

Parameters Type Description
str * the string to parse
cb * callback for each var replacement
ar * array to fill with matches
return undefined the string with the resolved variables

acquireState(data, options) ►

modifier: private modifier: static

Acquire state from multiple possible sources.

Parameters Type Description
data Any input data. Can be either direct data, URL, function or Promise
options * optional options to pass to Promise, function
return undefined Object or Array

isUrl(txt) ►

modifier: private modifier: static

Checks whether the fiven string is a valid URL.

Parameters Type Description
txt String the string to evaluate
return undefined Boolean indeicating whether the string is a URL.

setObjectValue(obj, path, value)

modifier: private modifier: static

Counterpart of GetObjectValue

Parameters Type Description
obj Object the object to set a shallow or deep property on
path String the path to the property to set
value Any the value to set

deepMerge(obj1, obj2)

modifier: private modifier: static

Does a deep merge of two objects, whereas using the spread operator (...) only does a shallow merge.

Parameters Type Description
obj1 Object the object to be merged into
obj2 Object the object to be merged from

stringToPath(path) ►

modifier: private modifier: static

Helper for GetObjectProperty and GetObjectProperty

Parameters Type Description
path String **
return undefined Array

compare(operator, a, b) ►

modifier: private modifier: static

Compares values using the built in operator table

Parameters Type Description
operator String **
a Object **
b Object **
return undefined Boolean

guid() ►

modifier: private modifier: static

Returns a random GUID

Parameters Type Description
return undefined string (36 characters)

hashFromString(s) ►

modifier: private modifier: static

Returns a hash code from the given string

Parameters Type Description
s String **
return undefined hash code

waitFor(f, timeoutMs, intervalMs) ►

modifier: private modifier: static

Waits for a given condition in a promise.

Parameters Type Description
f function the function to evaluate whether waiting should end
timeoutMs Number total time to wait if the given function still doesn't return true
intervalMs Number interval to wait between each function evaluation (in milliseconds) - Defaults to 20.
return undefined Promise that resolves when the evaluating function provided return true, or gets rejected when the timeout is reached.

formatByteSize(size) ►

modifier: private modifier: static

Formats a number as human-friendly byte size

Parameters Type Description
size Number **
return undefined String like 20KB, 1.25MB, 6.25GB, etc.

Members

Name Type Description
Events undefined Events Class
MarkDown undefined MarkDown wrapper
SimpleCache undefined Caching class