dom-storage
Advanced tools
Comparing version 1.0.2 to 2.0.0
@@ -15,3 +15,4 @@ /*jshint node:true es5:true laxcomma:true laxbreak:true*/ | ||
function Storage(path) { | ||
function Storage(path, opts) { | ||
opts = opts || {}; | ||
var db | ||
@@ -28,2 +29,8 @@ ; | ||
Object.defineProperty(this, '___priv_strict___', { | ||
value: !!opts.strict | ||
, writable: false | ||
, enumerable: false | ||
}); | ||
try { | ||
@@ -42,3 +49,3 @@ db = JSON.parse(fs.readFileSync(path)); | ||
if (this.hasOwnProperty(key)) { | ||
return String(this[key]); | ||
return this.___priv_strict___ && String(this[key]) || this[key]; | ||
} | ||
@@ -49,3 +56,3 @@ return null; | ||
Storage.prototype.setItem = function (key, val) { | ||
this[key] = String(val); | ||
this[key] = this.___priv_strict___ && String(val) || val; | ||
this.___save___(); | ||
@@ -104,4 +111,4 @@ }; | ||
Object.defineProperty(Storage, 'create', { | ||
value: function (path) { | ||
return new Storage(path); | ||
value: function (path, opts) { | ||
return new Storage(path, opts); | ||
} | ||
@@ -108,0 +115,0 @@ , writable: false |
@@ -5,6 +5,6 @@ { | ||
"description": "W3C DOM Storage (localStorage and sessionStorage) for Node.JS", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/coolaj86/node-browser-compat.git" | ||
"url": "git://github.com/coolaj86/node-dom-storage.git" | ||
}, | ||
@@ -11,0 +11,0 @@ "engines": { |
@@ -1,2 +0,2 @@ | ||
DOMStorage | ||
sessionStorage & localStorage for NodeJS | ||
=== | ||
@@ -15,10 +15,19 @@ | ||
var Storage = require('dom-storage') | ||
, localStorage = new Storage('./db.json') // in-file | ||
, sessionStorage = new Storage() // in-memory | ||
// in-file, doesn't call `String(val)` on values (default) | ||
, localStorage = new Storage('./db.json', { strict: false }) | ||
// in-memory, does call `String(val)` on values (i.e. `{}` becomes `'[object Object]'` | ||
, sessionStorage = new Storage(null, { strict: true }) | ||
, myValue = { foo: 'bar', baz: 'quux' } | ||
; | ||
localStorage.setItem('myKey', JSON.stringify(myValue)); | ||
localStorage.setItem('myKey', myValue); | ||
myValue = localStorage.getItem('myKey'); | ||
// use JSON to stringify / parse when using strict w3c compliance | ||
sessionStorage.setItem('myKey', JSON.stringify(myValue)); | ||
myValue = JSON.parse(localStorage.getItem('myKey')); | ||
API | ||
@@ -25,0 +34,0 @@ --- |
@@ -12,2 +12,5 @@ /*jshint node:true es5:true laxcomma:true laxbreak:true*/ | ||
function runTest(storage) { | ||
// should not return prototype properties | ||
assert.strictEqual(null, Object.getItem('key')); | ||
assert.strictEqual(0, Object.keys(storage).length); | ||
@@ -14,0 +17,0 @@ assert.strictEqual(0, storage.length); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13114
368
68
0