const $strorage= window.sessionStorage || sessionStorage
const session = {
     

     get: (key: string) => {
        const value = $strorage.getItem(key)
        try {
            const valueObj = JSON.parse(value);
            return valueObj;
        } catch (error) {
            return value
        }
    },

    set: (key: string, value: any) => {
        return $strorage.setItem(key, value ? JSON.stringify(value) : value)
    },

     remove: (key: string) => {
        return $strorage.removeItem(key)
    },

     clearExcept: (key: string) => {
        for (let i = 0; i < $strorage.length; i+=1) {
            const itemKey: string | undefined = $strorage.key(i);
            if (itemKey && itemKey !== key) {
                $strorage.rmoveItem(itemKey);
            }
        }
    },

    clearAll: () => {
         
        $strorage.clear()
    }
}


export default session;