applicaster-utils
v1.0.1
Published
Applicaster js utilities package
Downloads
1
Readme
applicaster-utils-js
Set of utilities for Applicaster javascript project.
How to use
- install with npm
$ npm i -S applicaster-utils
- import in your js code
import utils from "applicaster-utils";
const UQUrlWithPayload = '' // ...
const UQJsonFile = utils.decodePayloadFromUrl(UQUrlWithPayload);
you can also import only the functions you need
import {decodePayloadFromUrl} from "applicaster-utils";
const UQUrlWithPayload = '' // ...
const UQJsonFile = decodePayloadFromUrl(UQUrlWithPayload);
list of available functions :
hasLocalStorage : true || false
Boolean operator which tests the availability of localStorage.
setPersist(key, data) : null
Uses utils.hasLocalStorage
to store a string or an object in localStorage or cookies, depending on what's available.
getPersist(key) : Object
Returns a string or an object previously stored to localStorage or cookies with the utils.setPersist
method.
getUrlParamByName(name, source) : String || null
Returns the string of a given url parameter. If the source parameter is omitted, the search will be done on location.search
decodePayload(payload) : Object
Stringifies and encodes an object with javascript's atob()
method;
encodePayload(object) : String
Decodes a string encoded with javascript's btoa()
method, and parses it to return an object
decodePayloadFromUrl(urlString) : String
Returns the json file URL (questionUrl
property) in a UQ url with appli-payload
getQuestionIdFromUrlString(urlString) : String
Returns the UQ id from a UQ json file url.
getViewPort() : Object(w: width, h: height, device: device name)
Returns current viewPorts' width and height, plus a device name based on the following map :
if (viewPort.w < 322) {
if (viewPort.h < 490) {
viewPort.device = "iphone4";
} else {
viewPort.device = "iphone5";
}
} else if (viewPort.w < 365) {
if (viewPort.h < 525) {
viewPort.device = "g3";
} else {
viewPort.device = "s6";
}
} else if (viewPort.w < 450) {
viewPort.device = "iphone6";
} else if (viewPort.w < 1030) {
if (viewPort.h < 580) {
viewPort.device = "stab3";
} else {
viewPort.device = "ipad";
}
} else if (viewPort.w < 1300) {
viewPort.device = "androidTab";
} else {
viewPort.device = "default";
}