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

node-persist

Package Overview
Dependencies
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-persist - npm Package Compare versions

Comparing version 2.0.11 to 2.1.0

3

package.json
{
"name": "node-persist",
"version": "2.0.11",
"version": "2.1.0",
"description": "Super-easy (and fast) persistent data structures in Node.js, modeled after HTML5 localStorage",

@@ -39,2 +39,3 @@ "main": "./src/node-persist.js",

"dependencies": {
"is-absolute": "^0.2.6",
"mkdirp": "~0.5.1",

@@ -41,0 +42,0 @@ "q": "~1.1.1"

@@ -10,2 +10,3 @@ /*

mkdirp = require('mkdirp'),
isAbsolute = require('is-absolute'),
Q = require('q'),

@@ -162,3 +163,3 @@ pkg = require('../package.json'),

return this.keys().forEach(function(key) {
callback(key, this.data[key].value);
callback(key, this.getDataValue(key));
}.bind(this));

@@ -168,4 +169,4 @@ },

values: function() {
return this.keys().map(function(k) {
return this.data[k].value;
return this.keys().map(function(key) {
return this.getDataValue(key);
}.bind(this));

@@ -186,5 +187,5 @@ },

var values = [];
this.keys().forEach(function(k) {
if (filter(k)) {
values.push(this.data[k].value);
this.keys().forEach(function(key) {
if (filter(key)) {
values.push(this.getDataValue(key));
}

@@ -200,3 +201,3 @@ }.bind(this));

setItem: function (key, value, options, callback) {
setItem: function (key, dataValue, options, callback) {
if (typeof options == 'function') {

@@ -209,7 +210,6 @@ callback = options;

var logmsg = "set (" + key + ": " + this.stringify(value) + ")";
var deferred = Q.defer();
var deferreds = [];
var value = this.copy(dataValue);
// ttl is different that the other options because we can pass a different for each setItem, as well as have a default one.

@@ -232,6 +232,9 @@ var ttl = this.calcTTL(options.ttl);

this.log(logmsg);
if (instanceOptions.logging) {
this.log("set (" + key + ": " + this.stringify(value) + ")");
}
if (instanceOptions.interval || !instanceOptions.continuous) {
this.changes[key] = {onSuccess: onSuccess, onError: onError};
this.changes[key] = {onError: onError};
process.nextTick(onSuccess);
} else {

@@ -254,8 +257,11 @@ deferreds.push(this.persistKey(key));

setItemSync: function (key, value, options) {
setItemSync: function (key, dataValue, options) {
options = options || {};
var ttl = this.calcTTL(options.ttl);
var value = this.copy(dataValue);
this.data[key] = {key: key, value: value, ttl: ttl};
this.persistKeySync(key);
this.log("set (" + key + ": " + this.stringify(value) + ")");
if (this.options.logging) {
this.log("set (" + key + ": " + this.stringify(value) + ")");
}
},

@@ -282,4 +288,5 @@

} else {
callback(null, this.data[key] && this.data[key].value);
deferred.resolve(this.data[key] && this.data[key].value);
var value = this.getDataValue(key);
callback(null, value);
deferred.resolve(value);
}

@@ -293,6 +300,10 @@ return deferred.promise;

} else {
return this.data[key] && this.data[key].value;
return this.getDataValue(key);
}
},
getDataValue: function (key) {
return this.data[key] ? this.copy(this.data[key].value) : undefined;
},
del: function (key, callback) {

@@ -316,3 +327,3 @@ return this.removeItem(key, callback);

function() {
var value = this.data[key] && this.data[key].value;
var value = this.getDataValue(key);
delete this.data[key];

@@ -332,3 +343,3 @@ this.log('removed: ' + key);

removeItemSync: function (key) {
var value = this.data[key] && this.data[key].value;
var value = this.getDataValue(key);
this.removePersistedKeySync(key);

@@ -543,2 +554,10 @@ delete this.data[key];

copy: function (value) {
// don't copy literals since they're passed by value
if (typeof value != 'object') {
return value;
}
return this.parse(this.stringify(value));
},
parseStorageDir: function(callback) {

@@ -683,3 +702,3 @@ callback = isFunction(callback) ? callback : noop;

dir = path.normalize(dir);
if (path.isAbsolute(dir)) {
if (isAbsolute(dir)) {
return dir;

@@ -686,0 +705,0 @@ }

@@ -48,3 +48,3 @@

storage1.setItemSync("s1", 1111);
storage2.setItemSync("s2", 2222);
storage2.setItemSync("s2", {a: 1});

@@ -64,3 +64,3 @@ var storage11 = nodePersist.create({

storage2.getItem("s2").then(function(value) {
assert.equal(value, 2222, "write/read didn't work");
assert.deepEqual(value, {a: 1}, "write/read didn't work");
done();

@@ -364,8 +364,13 @@ })

storage.setItem("item999", 1).then(function() {
// 2 seconds later, that file should be there and that promise should resolve now.
var endTime = +new Date();
assert.approximately(endTime, startTime, 2500, "within 2.5s or so");
assert.equal(true, fs.existsSync(storage.options.dir + "/" + storage.md5("item999")));
done();
storage.setItem("item999", 1).then(function () {
// should resolve immediately but should not create the storate file immediately
assert.notEqual(true, fs.existsSync(storage.options.dir + "/" + storage.md5("item999")));
setTimeout(function() {
// 2 seconds later, that file should be there
var endTime = +new Date();
assert.approximately(endTime, startTime, 2500, "within 2.5s or so");
assert.equal(true, fs.existsSync(storage.options.dir + "/" + storage.md5("item999")));
done();
}, 2000);
});

@@ -372,0 +377,0 @@

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