Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dom-storage

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-storage - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

17

lib/index.js

@@ -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);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc