isomorphic-localstorage
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -0,0 +0,0 @@ const getStorage = (_path) => { |
46
node.js
"use strict"; | ||
const { LocalStorage } = require("node-localstorage"); | ||
const fs = require("fs"); | ||
class MockLocalStorage { | ||
_store; | ||
constructor() { | ||
this._store = {}; | ||
} | ||
getItem(key) { | ||
if (typeof key !== "string") { | ||
throw new Error("Key must be a string!"); | ||
} | ||
return this._store?.[key] ?? null; | ||
} | ||
removeItem(key) { | ||
if (typeof key !== "string") { | ||
throw new Error("Key must be a string!"); | ||
} | ||
if (typeof this._store?.[key] !== "undefined") { | ||
this._store[key] = undefined; | ||
} | ||
} | ||
setItem(key, value) { | ||
if (typeof key !== "string" || typeof value !== "string") { | ||
throw new Error("Both key and value must be strings!"); | ||
} | ||
this._store[key] = value; | ||
} | ||
} | ||
const getStorage = (location) => { | ||
@@ -13,12 +46,15 @@ let storage; | ||
if (typeof error.code !== "undefined" && error.code === "ENOENT") { | ||
fs.chmodSync(location, 0o755) | ||
storage = new LocalStorage(location); | ||
console.log( | ||
"[isomorphic-localstorage] Unable to instantiate localStorage in given location due to lack of permissions; mock will be used instead." | ||
); | ||
storage = new MockLocalStorage(); | ||
} else { | ||
throw error | ||
throw error; | ||
} | ||
} | ||
return storage | ||
return storage; | ||
}; | ||
module.exports = getStorage; |
{ | ||
"name": "isomorphic-localstorage", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"main": "node.js", | ||
@@ -5,0 +5,0 @@ "browser": "browser.js", |
# isomorphic-localstorage | ||
Isomorphic implementation of localStorage |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2024
55
1