Skip to content

Commit

Permalink
0.0.849
Browse files Browse the repository at this point in the history
  • Loading branch information
bahrus committed Nov 6, 2024
1 parent 1cddb1c commit 3d370cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 35 deletions.
28 changes: 10 additions & 18 deletions XV/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ const cache = {
sessionStorage: Symbol.for('yx84OGtTMU2GufafFtsZLw'),
localStorage: Symbol.for('eFljX6VSOkOAmcNJyph1sw')
};
const initialized = Symbol('1IBxCFcbCUW3KQllamedmw');
const initialized = {
sessionStorage: Symbol('1IBxCFcbCUW3KQllamedmw'),
localStorage: Symbol('H2lL+vYErUGixatKub3nWA')
};
const isLoaded = navigator.deviceMemory > 1;
export function init(whichStorage, win = window) {
const aWin = win;
if (aWin[initialized])
const initializedKey = initialized[whichStorage];
if (aWin[initializedKey])
return;
aWin[initialized] = true;
aWin[initializedKey] = true;
if (!aWin[cache[whichStorage]] && isLoaded) {
aWin[cache[whichStorage]] = {};
}
if (isLoaded) {
const originalGetItem = win[whichStorage].getItem;
const boundGetItem = originalGetItem.bind(win[whichStorage]);
win.sessionStorage.getItem = function (key) {
win[whichStorage].getItem = function (key) {
const item = boundGetItem(key);
if (item === null)
return null;
Expand Down Expand Up @@ -72,20 +76,8 @@ export function init(whichStorage, win = window) {
init('localStorage');
init('sessionStorage');
export async function get(key, splitPath, protocol) {
// const head = splitPath.shift();
// if(head === undefined) throw 400;
const sessionStr = window[protocol].getItem(key)?.trim();
if (sessionStr === undefined)
return undefined;
const start = sessionStr[0];
const last = sessionStr[-1];
if ((start === '[' && last === ']') || (start === '{' && last === '}')) {
const baseVal = JSON.parse(sessionStr);
return baseVal;
}
else {
return sessionStr;
}
let returnObj = window[protocol].getItem(key);
return returnObj;
}
export async function set(key, splitPath, protocol) {
const head = splitPath.shift();
Expand Down
27 changes: 11 additions & 16 deletions XV/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ const cache = {
sessionStorage: Symbol.for('yx84OGtTMU2GufafFtsZLw'),
localStorage: Symbol.for('eFljX6VSOkOAmcNJyph1sw')
};
const initialized = Symbol('1IBxCFcbCUW3KQllamedmw');
const initialized = {
sessionStorage: Symbol('1IBxCFcbCUW3KQllamedmw'),
localStorage: Symbol('H2lL+vYErUGixatKub3nWA')
};

const isLoaded = (<any>navigator).deviceMemory > 1;

export function init(whichStorage: 'sessionStorage' | 'localStorage', win: Window = window, ){
const aWin = win as any;
if(aWin[initialized]) return;
aWin[initialized] = true;
const initializedKey = initialized[whichStorage];
if(aWin[initializedKey]) return;
aWin[initializedKey] = true;
if(!aWin[cache[whichStorage]] && isLoaded){
aWin[cache[whichStorage]] = {};
}

if(isLoaded){
const originalGetItem = win[whichStorage].getItem;
const boundGetItem = originalGetItem.bind(win[whichStorage]);
win.sessionStorage.getItem = function(key: string){
win[whichStorage].getItem = function(key: string){
const item = boundGetItem(key);
if(item === null) return null;
if(!isLoaded) return item;
Expand Down Expand Up @@ -74,18 +78,9 @@ init('localStorage');
init('sessionStorage');

export async function get(key: string, splitPath: Array<string>, protocol: 'sessionStorage' | 'localStorage'){
// const head = splitPath.shift();
// if(head === undefined) throw 400;
const sessionStr = window[protocol].getItem(key)?.trim();
if(sessionStr === undefined) return undefined;
const start = sessionStr[0];
const last = sessionStr[-1];
if((start === '[' && last === ']') || (start === '{' && last === '}')){
const baseVal = JSON.parse(sessionStr);
return baseVal;
}else{
return sessionStr;
}
let returnObj = window[protocol].getItem(key);
return returnObj;

}

export async function set(key: string, splitPath: Array<string>, protocol: 'sessionStorage' | 'localStorage'){
Expand Down
2 changes: 1 addition & 1 deletion XV/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function get(usl: USL){
case 'localStorage':
case 'sessionStorage':
const {get} = await import('./Storage.js');
const [key] = uspParts
const [key] = uspParts;
ctxObj = await get(key, [], protocol);
break;
default:
Expand Down

0 comments on commit 3d370cc

Please sign in to comment.