This commit is contained in:
2022-03-04 18:34:48 +01:00
parent a614974a35
commit a0810fbee1
2 changed files with 46 additions and 36 deletions

View File

@@ -1,41 +1,48 @@
const capitalize = (string) => { const capitalize = string => {
return string.includes(' ') ? if (!string) return;
string.split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1).replace('_', ' ')).join(' ')
: string.charAt(0).toUpperCase() + string.slice(1)
}
const setDocumentTitle = (state) => { return string.includes(" ")
document.title = `${state.emoji} ${state.titlePrefix} | ${capitalize(state.title)}` ? string
} .split(" ")
.map(
word => word.charAt(0).toUpperCase() + word.slice(1).replace("_", " ")
)
.join(" ")
: string.charAt(0).toUpperCase() + string.slice(1);
};
const setDocumentTitle = state => {
document.title = `${state.emoji} ${state.titlePrefix} | ${capitalize(
state.title
)}`;
};
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
emoji: '', emoji: "",
titlePrefix: 'seasoned', titlePrefix: "seasoned",
title: undefined title: undefined
}, },
getters: { getters: {
title: (state) => { title: state => state.title
return state.title
}
}, },
mutations: { mutations: {
SET_EMOJI: (state, emoji) => { SET_EMOJI: (state, emoji) => {
state.emoji = emoji state.emoji = emoji;
setDocumentTitle(state) setDocumentTitle(state);
}, },
SET_TITLE: (state, title) => { SET_TITLE: (state, title) => {
state.title = title state.title = title;
setDocumentTitle(state) setDocumentTitle(state);
} }
}, },
actions: { actions: {
updateEmoji({ commit }, emoji) { updateEmoji({ commit }, emoji) {
commit('SET_EMOJI', emoji) commit("SET_EMOJI", emoji);
}, },
updateTitle({ commit }, title) { updateTitle({ commit }, title) {
commit('SET_TITLE', title) commit("SET_TITLE", title);
} }
} }
} };

View File

@@ -1,23 +1,26 @@
const sortableSize = (string) => { const sortableSize = string => {
const UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const [numStr, unit] = string.split(' '); const [numStr, unit] = string.split(" ");
if (UNITS.indexOf(unit) === -1) if (UNITS.indexOf(unit) === -1) return string;
return string
const exponent = UNITS.indexOf(unit) * 3 const exponent = UNITS.indexOf(unit) * 3;
return numStr * (Math.pow(10, exponent)) return numStr * Math.pow(10, exponent);
}; };
const parseJwt = (token) => { const parseJwt = token => {
var base64Url = token.split('.')[1]; var base64Url = token.split(".")[1];
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); var base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
var jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) { var jsonPayload = decodeURIComponent(
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); atob(base64)
}).join('')); .split("")
.map(function (c) {
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
})
.join("")
);
return JSON.parse(jsonPayload); return JSON.parse(jsonPayload);
}; };
export { sortableSize, parseJwt };
export { sortableSize, parseJwt }