import { TokenPayload } from "../models/token" ; const createModalRoot = ( ) => { const modalRoot = document . createElement ( "div" ) ; modalRoot . setAttribute ( "id" , "modal-root" ) ; document . body . appendChild ( modalRoot ) ; return modalRoot ; } ; export const SETTINGS_KEY = "settings" ; export const MODAL_ROOT = document . getElementById ( "modal-root" ) || createModalRoot ( ) ; export interface SavedSettings { lang : string ; darkMode : boolean ; } /**
 * merges previous with new settings and saves it to local storage
 */ export function saveSettings ( settings ) { const prevSettings = retrieveSettings ( ) ; const newSettings = { ... prevSettings , ... settings , } ; localStorage . setItem ( SETTINGS_KEY , JSON . stringify ( newSettings ) ) ; } /**
 * Retrieves settings from local storage and parses them into a  SavedSettings object.
 *  returns export function retrieveSettings ( ) { const settingString = localStorage . getItem ( SETTINGS_KEY ) ; if ( settingString ) { const settings = JSON . parse ( settingString ) ; return settings ; } return null ; } param props returns export function checkPropsUndefined ( props ) { let someUndefined = false ; Object . values ( props ) . forEach ( ( prop ) => { if ( prop === null || prop === undefined ) { someUndefined = true ; } } ) ; return someUndefined ; } export function parseJwt ( token ) { const base64Url = token . split ( "." ) [ 1 ] ; const base64 = base64Url . replace ( /-/g , "+" ) . replace ( /_/g , "/" ) ; const jsonPayload = decodeURIComponent ( atob ( base64 ) . split ( "" ) . map ( ( c ) => "%" + ( "00" + c . charCodeAt ( 0 ) . toString ( 16 ) ) . slice ( - 2 ) ) . join ( "" ) ) ; return JSON . parse ( jsonPayload ) ; }