Comparing version 0.1.9 to 0.1.10
@@ -19,3 +19,3 @@ 'use strict'; | ||
}, | ||
set: function(k, v) { | ||
set: function(k, v, opts) { | ||
var ks, ref; | ||
@@ -25,3 +25,3 @@ ks = (ref = cookies.getJSON(key('_keys'))) != null ? ref : []; | ||
cookies.set(key('_keys'), ks); | ||
return cookies.set(key(k), v); | ||
return cookies.set(key(k, opts), v); | ||
}, | ||
@@ -45,12 +45,27 @@ remove: function(k) { | ||
var storage = function(backend) { | ||
var root, store; | ||
var err, root, store; | ||
root = typeof window === 'undefined' ? global : window; | ||
store = root[backend + 'Storage']; | ||
try { | ||
store = root[backend + 'Storage']; | ||
} catch (error) { | ||
return { | ||
get: function() { | ||
return void 0; | ||
}, | ||
set: function() { | ||
return void 0; | ||
}, | ||
remove: function() { | ||
return void 0; | ||
}, | ||
clear: function() { | ||
return void 0; | ||
} | ||
}; | ||
} | ||
return { | ||
get: function(k) { | ||
var err; | ||
try { | ||
return JSON.parse(store.getItem(k)); | ||
} catch (error) { | ||
err = error; | ||
console.error('Unable to parse', k); | ||
@@ -60,3 +75,3 @@ return void 0; | ||
}, | ||
set: function(k, v) { | ||
set: function(k, v, opts) { | ||
return store.setItem(k, JSON.stringify(v)); | ||
@@ -76,2 +91,31 @@ }, | ||
// src/pretend-storage.coffee | ||
var pretendStorage = (function() { | ||
var key, postFix, pretendStorage; | ||
pretendStorage = {}; | ||
postFix = md5(window.location.host); | ||
key = function(k) { | ||
return k + "_" + postFix; | ||
}; | ||
return { | ||
get: function(k) { | ||
return pretendStorage[key(k)]; | ||
}, | ||
set: function(k, v, opts) { | ||
return pretendStorage[key(k)] = v; | ||
}, | ||
remove: function(k) { | ||
return delete pretendStorage[key(k)]; | ||
}, | ||
clear: function() { | ||
var results; | ||
results = []; | ||
for (key in pretendStorage) { | ||
results.push(delete pretendStorage[key(k)]); | ||
} | ||
return results; | ||
} | ||
}; | ||
})(); | ||
// src/index.coffee | ||
@@ -89,3 +133,2 @@ var supported; | ||
} catch (error) { | ||
err = error; | ||
return false; | ||
@@ -98,4 +141,6 @@ } | ||
return localStorage; | ||
} else if (supported(cookieStorage)) { | ||
return cookieStorage; | ||
} else { | ||
return cookieStorage; | ||
return pretendStorage; | ||
} | ||
@@ -102,0 +147,0 @@ })(); |
{ | ||
"name": "akasha", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "Cross-browser storage with cookie-based fallback. Inspired by [store.js](https://github.com/marcuswestin/store.js/).", | ||
@@ -44,6 +44,6 @@ "main": "lib/akasha.js", | ||
"devDependencies": { | ||
"coffee-script": "1.12.5", | ||
"sake-bundle": "^0.5.1", | ||
"sake-cli": "^0.5.6", | ||
"sake-outdated": "^0.1.27", | ||
"coffee-script": "1.12.7", | ||
"sake-bundle": "^0.6.0", | ||
"sake-cli": "^0.5.21", | ||
"sake-outdated": "^0.1.28", | ||
"sake-publish": "^0.1.16", | ||
@@ -50,0 +50,0 @@ "sake-version": "^0.1.19" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
21306
13
264