prettier --write

This commit is contained in:
RainLoop Team 2019-07-04 22:19:24 +03:00
parent 450528ff00
commit 8a0be3212d
164 changed files with 7053 additions and 9008 deletions

View file

@ -1,4 +1,3 @@
import window from 'window';
const STORAGE_KEY = '__rlA';
@ -8,65 +7,55 @@ const TIME_KEY = '__rlT';
* @param {string} storageName
* @returns {boolean}
*/
export function isStorageSupported(storageName)
{
export function isStorageSupported(storageName) {
let storageIsAvailable = false;
try
{
try {
// at: window[storageName] firefox throws SecurityError: The operation is insecure. when in iframe
storageIsAvailable = storageName in window && window[storageName] && window[storageName].setItem;
}
catch (e) {} // eslint-disable-line no-empty
} catch (e) {} // eslint-disable-line no-empty
if (storageIsAvailable)
{
const
s = window[storageName],
if (storageIsAvailable) {
const s = window[storageName],
key = 'testLocalStorage_' + window.Math.random();
try
{
try {
s.setItem(key, key);
if (key === s.getItem(key))
{
if (key === s.getItem(key)) {
s.removeItem(key);
return true;
}
}
catch (e) {} // eslint-disable-line no-empty
} catch (e) {} // eslint-disable-line no-empty
}
return false;
}
const SESS_STORAGE = isStorageSupported('sessionStorage') ? (window.sessionStorage || null) : null;
const SESS_STORAGE = isStorageSupported('sessionStorage') ? window.sessionStorage || null : null;
const WIN_STORAGE = window.top || window || null;
const __get = (key) => {
let result = null;
if (SESS_STORAGE)
{
if (SESS_STORAGE) {
result = SESS_STORAGE.getItem(key) || null;
}
else if (WIN_STORAGE && window.JSON)
{
const data = WIN_STORAGE.name && '{' === WIN_STORAGE.name.toString().substr(0, 1) ? window.JSON.parse(WIN_STORAGE.name.toString()) : null;
result = data ? (data[key] || null) : null;
} else if (WIN_STORAGE && window.JSON) {
const data =
WIN_STORAGE.name && '{' === WIN_STORAGE.name.toString().substr(0, 1)
? window.JSON.parse(WIN_STORAGE.name.toString())
: null;
result = data ? data[key] || null : null;
}
return result;
};
const __set = (key, value) => {
if (SESS_STORAGE)
{
if (SESS_STORAGE) {
SESS_STORAGE.setItem(key, value);
}
else if (WIN_STORAGE && window.JSON)
{
let data = WIN_STORAGE.name && '{' === WIN_STORAGE.name.toString().substr(0, 1) ? window.JSON.parse(WIN_STORAGE.name.toString()) : null;
} else if (WIN_STORAGE && window.JSON) {
let data =
WIN_STORAGE.name && '{' === WIN_STORAGE.name.toString().substr(0, 1)
? window.JSON.parse(WIN_STORAGE.name.toString())
: null;
data = data || {};
data[key] = value;
@ -74,30 +63,27 @@ const __set = (key, value) => {
}
};
const timestamp = () => window.Math.round((new window.Date()).getTime() / 1000);
const timestamp = () => window.Math.round(new window.Date().getTime() / 1000);
const setTimestamp = () => __set(TIME_KEY, timestamp());
const getTimestamp = () => {
const time = __get(TIME_KEY, 0);
return time ? (window.parseInt(time, 10) || 0) : 0;
return time ? window.parseInt(time, 10) || 0 : 0;
};
/**
* @returns {string}
*/
export function getHash()
{
export function getHash() {
return __get(STORAGE_KEY);
}
/**
* @returns {void}
*/
export function setHash()
{
const
key = 'AuthAccountHash',
export function setHash() {
const key = 'AuthAccountHash',
appData = window.__rlah_data();
__set(STORAGE_KEY, appData && appData[key] ? appData[key] : '');
@ -107,8 +93,7 @@ export function setHash()
/**
* @returns {void}
*/
export function clearHash()
{
export function clearHash() {
__set(STORAGE_KEY, '');
setTimestamp();
}
@ -116,10 +101,9 @@ export function clearHash()
/**
* @returns {boolean}
*/
export function checkTimestamp()
{
if (timestamp() > getTimestamp() + 1000 * 60 * 60) // 60m
{
export function checkTimestamp() {
if (timestamp() > getTimestamp() + 1000 * 60 * 60) {
// 60m
clearHash();
return true;
}