2020-01-21 05:56:04 +00:00
|
|
|
import { LANGUAGE } from '../constants';
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
return currentLng
|
|
|
|
? (i18n.language !== currentLng
|
|
|
|
? i18n.changeLanguage(currentLng)
|
|
|
|
: Promise.resolve((...args) => i18n.t(...args)))
|
|
|
|
: i18n.changeLanguage('en');
|
2020-01-21 05:56:04 +00:00
|
|
|
}
|
2020-09-18 08:12:09 +00:00
|
|
|
|
|
|
|
export function changeDocumentTitle(title) {
|
|
|
|
if (title !== document.title) {
|
|
|
|
document.title = title;
|
|
|
|
}
|
|
|
|
}
|