2020-09-30 08:43:19 +00:00
|
|
|
import { LANGUAGE } from "../constants";
|
|
|
|
import sjcl from "sjcl";
|
2020-01-21 05:56:04 +00:00
|
|
|
|
2019-11-19 12:35:56 +00:00
|
|
|
export const toUrlParams = (obj, skipNull) => {
|
|
|
|
let str = "";
|
|
|
|
for (var key in obj) {
|
|
|
|
if (skipNull && !obj[key]) continue;
|
|
|
|
|
|
|
|
if (str !== "") {
|
|
|
|
str += "&";
|
|
|
|
}
|
|
|
|
|
|
|
|
str += key + "=" + encodeURIComponent(obj[key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
2020-09-30 08:43:19 +00:00
|
|
|
};
|
2019-11-19 12:35:56 +00:00
|
|
|
|
|
|
|
export function getObjectByLocation(location) {
|
|
|
|
if (!location.search || !location.search.length) return null;
|
|
|
|
|
|
|
|
const searchUrl = location.search.substring(1);
|
|
|
|
const object = JSON.parse(
|
|
|
|
'{"' +
|
|
|
|
decodeURIComponent(searchUrl)
|
|
|
|
.replace(/"/g, '\\"')
|
|
|
|
.replace(/&/g, '","')
|
|
|
|
.replace(/=/g, '":"') +
|
|
|
|
'"}'
|
|
|
|
);
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
2020-01-21 05:56:04 +00:00
|
|
|
|
2020-02-03 13:36:46 +00:00
|
|
|
export function changeLanguage(i18n) {
|
|
|
|
const currentLng = localStorage.getItem(LANGUAGE);
|
2020-09-30 08:43:19 +00:00
|
|
|
return currentLng
|
|
|
|
? i18n.language !== currentLng
|
|
|
|
? i18n.changeLanguage(currentLng)
|
|
|
|
: Promise.resolve((...args) => i18n.t(...args))
|
|
|
|
: i18n.changeLanguage("en");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createHashPassword(password, settings) {
|
|
|
|
const { size, iterations, salt } = settings;
|
|
|
|
|
|
|
|
let bits = sjcl.misc.pbkdf2(password, salt, iterations);
|
|
|
|
bits = bits.slice(0, size / 32);
|
|
|
|
const hash = sjcl.codec.hex.fromBits(bits);
|
|
|
|
|
|
|
|
return hash;
|
2020-01-21 05:56:04 +00:00
|
|
|
}
|