isomorphic-localstorage
Advanced tools
Comparing version 0.0.8 to 1.0.0
@@ -0,0 +0,0 @@ const getStorage = (_path) => { |
61
node.js
@@ -1,59 +0,8 @@ | ||
"use strict"; | ||
'use strict' | ||
const { LocalStorage } = require("node-localstorage"); | ||
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) => { | ||
const { LocalStorage } = require('node-localstorage') | ||
return new LocalStorage(location) | ||
} | ||
const getStorage = (location) => { | ||
let storage; | ||
try { | ||
storage = new LocalStorage(location); | ||
} catch (error) { | ||
if (typeof error.code !== "undefined" && error.code === "ENOENT") { | ||
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; | ||
} | ||
} | ||
return storage; | ||
}; | ||
module.exports = getStorage; | ||
module.exports = getStorage |
{ | ||
"name": "isomorphic-localstorage", | ||
"version": "0.0.8", | ||
"version": "1.0.0", | ||
"main": "node.js", | ||
"browser": "browser.js", | ||
"typings": "typings.d.ts", | ||
"repository": "https://github.com/nightly-labs/isomorphic-localstorage.git", | ||
@@ -16,3 +17,6 @@ "author": "Adrian Wójciak <adrianwojciak@interia.pl>", | ||
"README.md" | ||
] | ||
], | ||
"devDependencies": { | ||
"typescript": "^5.1.3" | ||
} | ||
} |
# isomorphic-localstorage | ||
Isomorphic implementation of localStorage |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
982
1
16