storage-factory
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -0,1 +1,5 @@ | ||
# 0.0.3 | ||
* Update development dependencies | ||
# 0.0.2 | ||
@@ -2,0 +6,0 @@ |
@@ -5,10 +5,2 @@ "use strict"; | ||
let inMemoryStorage = {}; | ||
const def = { | ||
getItem, | ||
setItem, | ||
removeItem, | ||
clear, | ||
key, | ||
length: 0 | ||
}; | ||
function isSupported() { | ||
@@ -32,3 +24,2 @@ try { | ||
} | ||
updateLength(); | ||
} | ||
@@ -59,3 +50,2 @@ function getItem(name) { | ||
} | ||
updateLength(); | ||
} | ||
@@ -69,14 +59,22 @@ function setItem(name, value) { | ||
} | ||
updateLength(); | ||
} | ||
function updateLength() { | ||
function length() { | ||
if (isSupported()) { | ||
def.length = storage.length; | ||
return storage.length; | ||
} | ||
else { | ||
def.length = Object.keys(inMemoryStorage).length; | ||
return Object.keys(inMemoryStorage).length; | ||
} | ||
} | ||
return def; | ||
return { | ||
getItem, | ||
setItem, | ||
removeItem, | ||
clear, | ||
key, | ||
get length() { | ||
return length(); | ||
}, | ||
}; | ||
} | ||
exports.storageFactory = storageFactory; |
{ | ||
"name": "storage-factory", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "lib/index.js", | ||
@@ -10,6 +10,7 @@ "typings": "lib/index.d.ts", | ||
"devDependencies": { | ||
"@types/jest": "^23.3.2", | ||
"@types/jest": "^23.3.9", | ||
"jest": "^23.6.0", | ||
"ts-jest": "^23.10.2", | ||
"typescript": "^3.0.3" | ||
"prettier": "1.14.3", | ||
"ts-jest": "^23.10.5", | ||
"typescript": "^3.1.6" | ||
}, | ||
@@ -20,3 +21,4 @@ "scripts": { | ||
"test": "jest", | ||
"test:watch": "jest --watchAll" | ||
"test:watch": "jest --watchAll", | ||
"format": "prettier --write src/*.ts" | ||
}, | ||
@@ -33,2 +35,5 @@ "jest": { | ||
}, | ||
"prettier": { | ||
"trailingComma": "es5" | ||
}, | ||
"keywords": [], | ||
@@ -35,0 +40,0 @@ "author": "Michal Zalecki <michal@michalzalecki.com>", |
4109
5
77