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

localstorage-memory

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

localstorage-memory - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

56

lib/localstorage-memory.js

@@ -1,4 +0,4 @@

(function(root) {
var localStorageMemory = {};
var cache = {};
(function (root) {
var localStorageMemory = {}
var cache = {}

@@ -8,3 +8,3 @@ /**

*/
localStorageMemory.length = 0;
localStorageMemory.length = 0

@@ -18,6 +18,10 @@ /**

*/
localStorageMemory.getItem = function(key) {
return cache[key] || null;
};
localStorageMemory.getItem = function (key) {
if (key in cache) {
return cache[key]
}
return null
}
/**

@@ -32,13 +36,13 @@ * sets item for key to passed value, as String

*/
localStorageMemory.setItem = function(key, value) {
localStorageMemory.setItem = function (key, value) {
if (typeof value === 'undefined') {
localStorageMemory.removeItem(key);
localStorageMemory.removeItem(key)
} else {
if (!(cache.hasOwnProperty(key))) {
localStorageMemory.length++;
localStorageMemory.length++
}
cache[key] = '' + value;
cache[key] = '' + value
}
};
}

@@ -52,8 +56,8 @@ /**

*/
localStorageMemory.removeItem = function(key) {
localStorageMemory.removeItem = function (key) {
if (cache.hasOwnProperty(key)) {
delete cache[key];
localStorageMemory.length--;
delete cache[key]
localStorageMemory.length--
}
};
}

@@ -67,5 +71,5 @@ /**

*/
localStorageMemory.key = function(index) {
return Object.keys(cache)[index] || null;
};
localStorageMemory.key = function (index) {
return Object.keys(cache)[index] || null
}

@@ -77,12 +81,12 @@ /**

*/
localStorageMemory.clear = function() {
cache = {};
localStorageMemory.length = 0;
};
localStorageMemory.clear = function () {
cache = {}
localStorageMemory.length = 0
}
if (typeof exports === 'object') {
module.exports = localStorageMemory;
module.exports = localStorageMemory
} else {
root.localStorageMemory = localStorageMemory;
root.localStorageMemory = localStorageMemory
}
})(this);
})(this)

@@ -5,14 +5,8 @@ {

"main": "lib/localstorage-memory.js",
"directories": {
"test": "tests"
},
"scripts": {
"jshint": "jshint -c .jshintrc lib/localstorage-memory.js bin/ tests/",
"test": "npm run jshint && npm run test-browser",
"test-browser": "node ./bin/test-browser.js",
"test-node": "sh bin/test-node.sh",
"dev-server": "http-server -a 127.0.0.1 -p 8000",
"pretest": "standard",
"test": "mocha tests",
"docs": "doxx --source lib/ --target docs/ --template docs/template.jade",
"deploy": "gh-pages-deploy ",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
"update-docs": "gh-pages-deploy",
"semantic-release": "semantic-release"
},

@@ -35,18 +29,14 @@ "repository": {

"devDependencies": {
"chai": "^1.10.0",
"doxx": "^1.2.1",
"expect.js": "^0.3.1",
"gh-pages-deploy": "^0.1.1",
"http-server": "^0.7.4",
"jshint": "^2.5.11",
"mocha": "^2.1.0",
"request": "^2.51.0",
"sauce-connect-launcher": "^0.9.3",
"wd": "^0.3.11",
"semantic-release": "^6.0.3"
"semantic-release": "^15.12.0",
"standard": "^12.0.1"
},
"gh-pages-deploy": {
"staticpath": "docs"
"staticpath": "docs",
"noprompt": true
},
"version": "1.0.2"
}
"version": "1.0.3"
}

@@ -1,75 +0,83 @@

/* global localStorageMemory, beforeEach, describe, it, expect */
'use strict';
/* global beforeEach, describe, it */
const expect = require('expect.js')
const localStorageMemory = require('../lib/localstorage-memory')
describe('localStorageMemory()', function () {
beforeEach(function() {
localStorageMemory.clear();
});
beforeEach(function () {
localStorageMemory.clear()
})
describe('localStorageMemory.getItem("foo")', function () {
describe('"foo" has been set before', function () {
beforeEach(function() {
localStorageMemory.setItem('foo', 'bar');
});
beforeEach(function () {
localStorageMemory.setItem('foo', 'bar')
})
it('returns true', function () {
expect(localStorageMemory.getItem('foo')).to.be('bar');
});
});
expect(localStorageMemory.getItem('foo')).to.be('bar')
})
})
describe('foo has not been set before', function () {
it('returns null', function () {
expect(localStorageMemory.getItem('foo')).to.be(null);
});
});
});
expect(localStorageMemory.getItem('foo')).to.be(null)
})
})
describe('foo can take empty string value', function () {
it('returns empty string, not a null or undefined', function () {
localStorageMemory.setItem('foo', '')
expect(localStorageMemory.getItem('foo')).to.be('')
})
})
})
describe('localStorageMemory.setItem(123, 456)', function () {
it('stores key & value as string', function () {
localStorageMemory.setItem(123, null);
expect(localStorageMemory.getItem('123')).to.be('null');
});
});
localStorageMemory.setItem(123, null)
expect(localStorageMemory.getItem('123')).to.be('null')
})
})
describe('localStorageMemory.removeItem(123)', function () {
it('removes item "123"', function() {
localStorageMemory.setItem('123', 'foo');
localStorageMemory.removeItem(123);
expect(localStorageMemory.getItem(123)).to.be(null);
});
});
it('removes item "123"', function () {
localStorageMemory.setItem('123', 'foo')
localStorageMemory.removeItem(123)
expect(localStorageMemory.getItem(123)).to.be(null)
})
})
describe('localStorageMemory.key(0)', function () {
describe('"foo" has been set before as only item', function () {
beforeEach(function() {
localStorageMemory.setItem('foo', 'bar');
});
beforeEach(function () {
localStorageMemory.setItem('foo', 'bar')
})
it('returns foo', function () {
expect(localStorageMemory.key(0)).to.be('foo');
});
});
expect(localStorageMemory.key(0)).to.be('foo')
})
})
describe('no item has been set', function () {
it('returns null', function () {
expect(localStorageMemory.key(0)).to.be(null);
});
});
});
expect(localStorageMemory.key(0)).to.be(null)
})
})
})
describe('localStorageMemory.clear()', function () {
it('removes all items', function() {
localStorageMemory.setItem('123', 'foo');
localStorageMemory.setItem(456, 'bar');
localStorageMemory.clear();
expect(localStorageMemory.length).to.be(0);
expect(localStorageMemory.getItem(123)).to.be(null);
expect(localStorageMemory.getItem(456)).to.be(null);
});
});
it('removes all items', function () {
localStorageMemory.setItem('123', 'foo')
localStorageMemory.setItem(456, 'bar')
localStorageMemory.clear()
expect(localStorageMemory.length).to.be(0)
expect(localStorageMemory.getItem(123)).to.be(null)
expect(localStorageMemory.getItem(456)).to.be(null)
})
})
describe('localStorageMemory.length', function () {
it ('duplicate puts don\'t increase length', function () {
localStorageMemory.setItem('123', 'foo');
localStorageMemory.setItem('123', 'foo');
expect(localStorageMemory.length).to.be(1);
});
it ('remove non-existent item doesn\'t decrease length', function () {
localStorageMemory.setItem('123', 'foo');
localStorageMemory.removeItem('abc');
expect(localStorageMemory.length).to.be(1);
});
});
});
it('duplicate puts don\'t increase length', function () {
localStorageMemory.setItem('123', 'foo')
localStorageMemory.setItem('123', 'foo')
expect(localStorageMemory.length).to.be(1)
})
it('remove non-existent item doesn\'t decrease length', function () {
localStorageMemory.setItem('123', 'foo')
localStorageMemory.removeItem('abc')
expect(localStorageMemory.length).to.be(1)
})
})
})

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

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