storage-factory
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -5,3 +5,10 @@ "use strict"; | ||
let inMemoryStorage = {}; | ||
const length = 0; | ||
const def = { | ||
getItem, | ||
setItem, | ||
removeItem, | ||
clear, | ||
key, | ||
length: 0 | ||
}; | ||
function isSupported() { | ||
@@ -25,2 +32,3 @@ try { | ||
} | ||
updateLength(); | ||
} | ||
@@ -51,2 +59,3 @@ function getItem(name) { | ||
} | ||
updateLength(); | ||
} | ||
@@ -60,12 +69,14 @@ function setItem(name, value) { | ||
} | ||
updateLength(); | ||
} | ||
return { | ||
getItem, | ||
setItem, | ||
removeItem, | ||
clear, | ||
key, | ||
length, | ||
}; | ||
function updateLength() { | ||
if (isSupported()) { | ||
def.length = storage.length; | ||
} | ||
else { | ||
def.length = Object.keys(inMemoryStorage).length; | ||
} | ||
} | ||
return def; | ||
} | ||
exports.storageFactory = storageFactory; |
{ | ||
"name": "storage-factory", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"main": "lib/index.js", | ||
@@ -18,3 +18,4 @@ "typings": "lib/index.d.ts", | ||
"build": "tsc", | ||
"test": "jest" | ||
"test": "jest", | ||
"test:watch": "jest --watchAll" | ||
}, | ||
@@ -21,0 +22,0 @@ "jest": { |
@@ -5,3 +5,3 @@ # storage-factory | ||
**Warning**: `length` property and array access are not yet implemented. PR welcome 🚀 | ||
**Warning**: object access (e.g. `localStorage.foo`) is not yet implemented 💥 | ||
@@ -30,1 +30,5 @@ ## Usage | ||
``` | ||
## Contribute | ||
Do you want to contribute? Awesome! Please, create an issue first and tell me about it. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4014
5
79
33