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

dry-underscore

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dry-underscore - npm Package Compare versions

Comparing version 0.20.0 to 0.21.1

287

lib/common.js

@@ -31,3 +31,120 @@ "use strict";

_.fatal = function(){ throw(_.exception("Fatal", "fatal: " + _.format.apply(null, arguments))); };
_.error = function(code, message, extra){
extra = extra || {};
if(_.isObject(message)){
var messageObj = message;
message = message.message;
extra = _.extend(messageObj, extra);
if(!message){ message = "*mising error message*"; }
}
if(extra.message){
extra.originalMessage = extra.message;
extra.original_message = extra.message;
}
if(extra.code){
extra.originalCode = extra.code;
extra.original_code = extra.code;
}
return(_.extend({
type: 'error',
stack: (new Error(message)).stack
}, extra, { code: code, message: message }));
};
_.exception = function(code, message, extra){
return(_.error(code, message, _.extend({}, extra, { type: 'exception' })));
};
function errors_obj(h){
this._errors = {};
this.hash(h ? h : {});
}
errors_obj.prototype.add = function(code, message){
if(!code){ _.fatal("error must have code."); }
if(!message){ _.fatal("error must have message."); }
this._errors[code] = message;
this[code] = function(m, extra){
if(_.isObject(m)){ extra = m; m = null; }
return(_.error(code, m ? m : message, extra));
};
};
errors_obj.prototype.hash = function(h){
var self = this;
if(!h){ return(_.jclone(this._errors)); }
_.each(this._errors, function(v, k){ delete self[k]; });
this._errors = {};
_.each(h, function(v, k){ self.add(k, v); });
};
_.errors = function(h){ return(new errors_obj(h)); };
_.error.message = function(err, add_context, exit_on_error){
if(!_.isArray(err)){ return(_.error._message(err, add_context, exit_on_error)); }
var error_messages = "";
var uuid = _.uuid();
var err_count = 0;
err = _.flatten(err);
_.each(err, function(e){
if(!_.isObject(e)){ return; }
err_count++;
error_messages += "\n";
error_messages += _.error._message(e, add_context, false);
error_messages += "\n";
});
var message = "start error stack: " + uuid;
if(err_count === 0){
message += "\nthere was an error array passed to _.error.message, but it didn't contain any errors: " + _.format(err);
}else{
message += ", " + err_count + " errors encountered.\n" + error_messages;
}
message += "end error stack: " + uuid + (exit_on_error ? ", process exiting." : "")
return(message);
};
_.error._message = function(err, add_context, exit_on_error){
var error_message = _.string_builder();
var uuid = _.uuid();
error_message.add_line("start error: " + uuid);
if(err.code){ error_message.add_line("code: ", err.code); }
if(err.message){ error_message.add_line("message: ", err.message); }
if(err.original_message){ error_message.add_line("original message: ", err.original_message); }
if(add_context){ add_context(error_message); }
if(err.stack){
var just_stack = err.stack.toString().split("\n");
just_stack.shift()
just_stack = just_stack.join("\n");
error_message.add_line("occurred: \n", just_stack); }
else{
error_message.add_line("object (no stack): ", err);
}
error_message.add_line("end error: ", uuid, (exit_on_error ? ", process exiting." : ""));
return(error_message.string());
};
_.deprecated = function(lib, f_name){
if(_.isString(lib)){ f_name = lib; lib = {}; }
var f = function(){ _.fatal(f_name + " is deprecated"); }
lib[f_name] = f;
return(f);
};
_.a = function(a){ return(_.toArray(a)); };
_.concat = function(){ return(Array.prototype.concat.apply([], arguments)); };
_.undef = function(x){ return(x === undefined); };

@@ -100,2 +217,4 @@ _.date = function(ts){

_.code = _.property_comparer("code");
_.timestamp = function(d){

@@ -390,113 +509,2 @@ if(_.isNumber(d)){ return(_.timestamp() + d); }

_.concat = function(){ return(Array.prototype.concat.apply([], arguments)); };
_.fatal = function(){ throw(_.exception("Fatal", "fatal: " + _.format.apply(null, arguments))); };
_.error = function(code, message, extra){
extra = extra || {};
if(_.isObject(message)){
var messageObj = message;
message = message.message;
extra = _.extend(messageObj, extra);
if(!message){ message = "*mising error message*"; }
}
if(extra.message){
extra.originalMessage = extra.message;
extra.original_message = extra.message;
}
if(extra.code){
extra.originalCode = extra.code;
extra.original_code = extra.code;
}
return(_.extend({
type: 'error',
stack: (new Error(message)).stack
}, extra, { code: code, message: message }));
};
_.exception = function(code, message, extra){
return(_.error(code, message, _.extend({}, extra, { type: 'exception' })));
};
function errors_obj(h){
this._errors = {};
this.hash(h ? h : {});
}
errors_obj.prototype.add = function(code, message){
if(!code){ _.fatal("error must have code."); }
if(!message){ _.fatal("error must have message."); }
this._errors[code] = message;
this[code] = function(m, extra){
if(_.isObject(m)){ extra = m; m = null; }
return(_.error(code, m ? m : message, extra));
};
};
errors_obj.prototype.hash = function(h){
var self = this;
if(!h){ return(_.jclone(this._errors)); }
_.each(this._errors, function(v, k){ delete self[k]; });
this._errors = {};
_.each(h, function(v, k){ self.add(k, v); });
};
_.errors = function(h){ return(new errors_obj(h)); };
_.code = _.property_comparer("code");
_.error.message = function(err, add_context, exit_on_error){
if(!_.isArray(err)){ return(_.error._message(err, add_context, exit_on_error)); }
var error_messages = "";
var uuid = _.uuid();
var err_count = 0;
err = _.flatten(err);
_.each(err, function(e){
if(!_.isObject(e)){ return; }
err_count++;
error_messages += "\n";
error_messages += _.error._message(e, add_context, false);
error_messages += "\n";
});
var message = "start error stack: " + uuid;
if(err_count === 0){
message += "\nthere was an error array passed to _.error.message, but it didn't contain any errors: " + _.format(err);
}else{
message += ", " + err_count + " errors encountered.\n" + error_messages;
}
message += "end error stack: " + uuid + (exit_on_error ? ", process exiting." : "")
return(message);
};
_.error._message = function(err, add_context, exit_on_error){
var error_message = _.string_builder();
var uuid = _.uuid();
error_message.add_line("start error: " + uuid);
if(err.code){ error_message.add_line("code: ", err.code); }
if(err.message){ error_message.add_line("message: ", err.message); }
if(err.original_message){ error_message.add_line("original message: ", err.original_message); }
if(add_context){ add_context(error_message); }
if(err.stack){
var just_stack = err.stack.toString().split("\n");
just_stack.shift()
just_stack = just_stack.join("\n");
error_message.add_line("occurred: \n", just_stack); }
else{
error_message.add_line("object (no stack): ", err);
}
error_message.add_line("end error: ", uuid, (exit_on_error ? ", process exiting." : ""));
return(error_message.string());
};
_.basicType = _.basic_type = function(o){

@@ -813,57 +821,20 @@ if(o === undefined){ return("undefined"); }

};
_.lock = function(f){
var running = false;
function lock(){
if(running){ return; }
running = true;
f.apply(null, arguments);
running = false;
}
return(lock);
};
_.lock.ui = function(f){
_.lock = function(f, no_ui){
var running = false;
var eventLock = function(e){
if(running){ return e.preventDefault(); }
else{
running = true;
f.call(this, e, function(){ running = false; });
}
};
return(eventLock);
};
_.lock.async = function(f, lockTest, lockModify, lockRelease){
var running = false;
function lock(){
var args = _.toArray(arguments);
if(lockTest){
var userTest = lockTest;
var testArgs = _.toArray(arguments);
lockTest = function(){
var testArgsCopy = _.toArray(testArgs);
testArgsCopy.unshift(running);
return(userTest.apply(null, testArgsCopy));
};
var lock = function(e){
if(running){
!no_ui && e && e.preventDefault && e.preventDefault();
return;
}else{
lockTest = function(){ return(running); };
running = true;
return f.apply(this, _.concat(function(){ running = false; }, _.a(arguments)));
}
lockModify = lockModify || function(){ running = true; }
lockRelease = lockRelease || function(){ running = false; };
if(lockTest()){ return; }
lockModify();
args.push(lockRelease);
f.apply(this, args);
}
return(lock);
};
_.deprecated(_, "lock.ui");
_.deprecated(_, "lock.async");
};
_.addProperties = _.add_properties = function(o, propArray, val){

@@ -870,0 +841,0 @@ _.each(propArray, function(prop){ o[prop] = val; });

@@ -223,2 +223,28 @@ "use strict";

test("lock", function(callback){
var rel = null;
var count = 0;
var unlocked_f = function(release, one, two, three){ rel = release; count++; eq(one, 1); eq(two, 2); eq(three, 3); return(5); }
var f = _.lock(unlocked_f);
_.nextTick(function(){
eq(5, f(1,2,3));
_.nextTick(function(){
eq(undefined, f());
_.nextTick(function(){
eq(undefined, f());
_.nextTick(function(){
rel();
eq(5, f(1,2,3));
eq(count, 2);
callback();
});
});
});
});
});
test("iso_date", function(){

@@ -225,0 +251,0 @@ var now = _.date();

{
"name": "dry-underscore",
"version": "0.20.0",
"version": "0.21.1",
"dependencies": {

@@ -5,0 +5,0 @@ "deep-diff": {

{
"name": "dry-underscore",
"version": "0.20.0",
"version": "0.21.1",
"main": "./index/node.index.js",

@@ -5,0 +5,0 @@ "description": "The DRY Undescore Library",

@@ -41,54 +41,2 @@ var fs = require('fs');

exports.testAsyncLockSimple = function(beforeExit){
var runs = 0;
function inc(releaseLock){ runs++; process.nextTick(releaseLock); }
var f = _.lock.async(inc);
f();
f();
process.nextTick(f);
beforeExit(function(){ assert.eql(runs, 2); });
}
exports.testAsyncLockExtraTest = function(beforeExit){
var runs = 0;
function inc(releaseLock){ runs++; process.nextTick(releaseLock); }
var disabled = false;
var f = _.lock.async(inc, function(def){ return(def || disabled); });
f();
f();
disabled = true;
process.nextTick(f);
process.nextTick(f);
disabled = false;
process.nextTick(f);
beforeExit(function(){ assert.eql(runs, 2); });
}
exports.testAsyncLockComplex = function(beforeExit){
var runs = 0;
function inc(releaseLock){ runs++; process.nextTick(releaseLock); }
var disabled = false;
var locked = false;
var f = _.lock.async(inc, function(){ return(disabled || locked); }, function(){ locked = true; }, function(){ locked = false; } );
f();
f();
disabled = true;
process.nextTick(f);
process.nextTick(f);
disabled = false;
process.nextTick(f);
beforeExit(function(){ assert.eql(runs, 2); });
}
exports.testIsObject = function(){

@@ -95,0 +43,0 @@

Sorry, the diff of this file is too big to display

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