Every line of 'check if localstorage exists' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
54 export function localStorageExists() { 55 return lsExists; 56 }
257 function checkForLocalStorage() { 258 try { 259 localStorage.setItem('test', 'test'); 260 localStorage.removeItem('test'); 261 return true; 262 } catch (e) { 263 return false; 264 } 265 }
35 function isLocalStorageAvailable() { 36 try { 37 return 'localStorage' in window && window['localStorage'] !== null; 38 } catch (e) { 39 console.log("localStorage_failed:", e); 40 return false; 41 } 42 };
331 checkIsLocalStorageSupported_() { 332 try { 333 if (!('localStorage' in this.win)) { 334 return false; 335 } 336 337 // We do not care about the value fetched from local storage; we only care 338 // whether the call throws an exception or not. As such, we can look up 339 // any arbitrary key. 340 this.win.localStorage.getItem('test'); 341 return true; 342 } catch (e) { 343 return false; 344 } 345 }
18 function exists (filename, callback) { 19 localforage.getItem(filename, function (err, value) { 20 if (value !== null) { // Even if value is undefined, localforage returns null 21 return callback(true); 22 } else { 23 return callback(false); 24 } 25 }); 26 }
115 export function localStorageAvailable() { 116 try { 117 const storage = window.localStorage; 118 const x = '__storage_test__'; 119 storage.setItem(x, x); 120 storage.removeItem(x); 121 return true; 122 } catch (e) { 123 return false; 124 } 125 }
44 exists(key) { 45 return this.get(this.getKey(key)) || false; 46 }
44 exists() { 45 return fse.pathExists(this.registryFile); 46 }
38 has(key: string) { 39 try { 40 return localStorage.getItem(key) != null; 41 } catch (err) { 42 console.error(err); 43 return false; 44 } 45 }
84 public static isAvailable(): boolean { 85 return typeof global.localStorage !== 'undefined'; 86 }