Socket
Socket
Sign inDemoInstall

hoek

Package Overview
Dependencies
0
Maintainers
2
Versions
116
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.7.0 to 0.7.1

78

lib/index.js

@@ -33,3 +33,3 @@ // Load modules

else if (obj[i] instanceof RegExp) {
var flags = '' + (obj[i].global ? 'g' : '') + (obj[i].ignoreCase ? 'i' : '') + (obj[i].multiline ? 'm' : '') + (obj[i].sticky ? 'y' : '');
var flags = '' + (obj[i].global ? 'g' : '') + (obj[i].ignoreCase ? 'i' : '') + (obj[i].multiline ? 'm' : '');
newObj[i] = new RegExp(obj[i].source, flags);

@@ -51,44 +51,47 @@ }

if (source) {
if (source instanceof Array) {
if (isMergeArrays !== false) { // Defaults to true
target = (target || []).concat(source);
exports.assert(target && typeof target == 'object', 'Invalid target value: must be an object');
exports.assert(source === null || source === undefined || typeof source === 'object', 'Invalid source value: must be null, undefined, or an object');
if (!source) {
return target;
}
if (source instanceof Array) {
exports.assert(target instanceof Array, 'Cannot merge array onto an object');
if (isMergeArrays === false) { // isMergeArrays defaults to true
target.length = 0; // Must not change target assignment
}
source.forEach(function (item) {
target.push(item);
});
return target;
}
Object.keys(source).forEach(function (key) {
var value = source[key];
if (value &&
typeof value === 'object') {
if (!target[key] ||
typeof target[key] !== 'object') {
target[key] = exports.clone(value);
}
else {
target = source;
exports.merge(target[key], source[key], isNullOverride, isMergeArrays);
}
}
else {
target = target || {};
for (var key in source) {
if (source.hasOwnProperty(key)) {
var value = source[key];
if (value &&
typeof value === 'object') {
if (value instanceof Date) {
target[key] = new Date(value.getTime());
}
else if (value instanceof RegExp) {
var flags = '' + (value.global ? 'g' : '') + (value.ignoreCase ? 'i' : '') + (value.multiline ? 'm' : '') + (value.sticky ? 'y' : '');
target[key] = new RegExp(value.source, flags);
}
else {
target[key] = exports.merge(target[key], source[key], isNullOverride, isMergeArrays);
}
}
else {
if (value !== null && value !== undefined) { // Explicit to preserve empty strings
target[key] = value;
}
else if (isNullOverride !== false) { // Defaults to true
target[key] = value;
}
}
}
if (value !== null && value !== undefined) { // Explicit to preserve empty strings
target[key] = value;
}
else if (isNullOverride !== false) { // Defaults to true
target[key] = value;
}
}
}
});

@@ -103,2 +106,5 @@ return target;

exports.assert(defaults && typeof defaults == 'object', 'Invalid defaults value: must be an object');
exports.assert(!options || options === true || typeof options === 'object', 'Invalid options value: must be true, falsy or an object');
if (!options) { // If no options, return null

@@ -105,0 +111,0 @@ return null;

{
"name": "hoek",
"description": "General purpose node utilities",
"version": "0.7.0",
"version": "0.7.1",
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)",

@@ -20,11 +20,7 @@ "contributors":[

"devDependencies": {
"mocha": "1.x.x",
"chai": "1.x.x",
"blanket": "1.0.x",
"travis-cov": "0.2.x"
"lab": "0.0.x",
"complexity-report": "0.x.x"
},
"scripts": {
"test": "make test && make test-cov",
"blanket": { "pattern": "//^((?!\/node_modules\/)(?!\/test\/).)*$/ig", "onlyCwd": true, "data-cover-flags": { "branchTracking": true } },
"travis-cov": { "threshold": 100 }
"test": "make test-cov"
},

@@ -31,0 +27,0 @@ "licenses": [

// Load modules
var Chai = require('chai');
var Lab = require('lab');
var Hoek = require('../lib');

@@ -14,3 +14,7 @@

var expect = Chai.expect;
var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;

@@ -21,7 +25,9 @@

var nestedObj = {
w: /^something$/ig,
w: /^something$/igm,
x: {
a: [1, 2, 3],
b: 123456,
c: new Date()
c: new Date(),
d: /hi/igm,
e: /hello/
},

@@ -42,6 +48,6 @@ y: 'y',

expect(a).to.deep.equal(b)
expect(a).to.deep.equal(b);
expect(a.z.getTime()).to.equal(b.z.getTime());
done();
})
});

@@ -54,3 +60,3 @@ it('should clone a null object', function (done) {

done();
})
});
});

@@ -60,2 +66,77 @@

it('does not throw if source is null', function (done) {
var a = {};
var b = null;
var c = null;
expect(function () {
c = Hoek.merge(a, b);
}).to.not.throw();
expect(c).to.equal(a);
done();
});
it('does not throw if source is undefined', function (done) {
var a = {};
var b = undefined;
var c = null;
expect(function () {
c = Hoek.merge(a, b);
}).to.not.throw();
expect(c).to.equal(a);
done();
});
it('throws if source is not an object', function (done) {
expect(function () {
var a = {};
var b = 0;
Hoek.merge(a, b);
}).to.throw('Invalid source value: must be null, undefined, or an object');
done();
});
it('throws if target is not an object', function (done) {
expect(function () {
var a = 0;
var b = {};
Hoek.merge(a, b);
}).to.throw('Invalid target value: must be an object');
done();
});
it('throws if target is not an array and source is', function (done) {
expect(function () {
var a = {};
var b = [1, 2];
Hoek.merge(a, b);
}).to.throw('Cannot merge array onto an object');
done();
});
it('returns the same object when merging arrays', function (done) {
var a = [];
var b = [1, 2];
expect(Hoek.merge(a, b)).to.equal(a);
done();
});
it('should combine an empty object with a non-empty object', function (done) {

@@ -74,4 +155,4 @@

var a = { x: 1, y: 2, z: 3, v: 5 };
var b = { x: null, z: 4, v: 0 };
var a = { x: 1, y: 2, z: 3, v: 5, t: 'test', m: 'abc' };
var b = { x: null, z: 4, v: 0, t: { u: 6 }, m: '123' };

@@ -83,4 +164,21 @@ var c = Hoek.merge(a, b);

expect(c.v).to.equal(0);
expect(c.m).to.equal('123');
expect(c.t).to.deep.equal({ u: 6 });
done();
});
it('should override values in target (flip)', function (done) {
var a = { x: 1, y: 2, z: 3, v: 5, t: 'test', m: 'abc' };
var b = { x: null, z: 4, v: 0, t: { u: 6 }, m: '123' };
var d = Hoek.merge(b, a);
expect(d.x).to.equal(1);
expect(d.y).to.equal(2);
expect(d.z).to.equal(3);
expect(d.v).to.equal(5);
expect(d.m).to.equal('abc');
expect(d.t).to.deep.equal('test');
done();
});
});

@@ -97,3 +195,4 @@

},
f: 6
f: 6,
g: 'test'
};

@@ -122,3 +221,6 @@

},
f: 0
f: 0,
g: {
h: 5
}
};

@@ -131,2 +233,3 @@

expect(result.f).to.equal(0);
expect(result.g).to.deep.equal({ h: 5 });
done();

@@ -361,2 +464,17 @@ });

});
it('should include constructor functions correctly', function (done) {
var Something = function (next) {
next();
};
var something = new Something(function () {
var stack = Hoek.displayStack();
expect(stack[1]).to.contain('new Something');
done();
});
});
});

@@ -373,8 +491,8 @@

process.env.NODE_ENV = 'nottatest';
process.stdout.write = function () {};
process.stdout.write = function () { };
process.exit = function (state) {
process.exit = exit;
process.env.NODE_ENV = env;
process.stdout.write = write;
process.exist = exit;

@@ -402,3 +520,3 @@ expect(state).to.equal(1);

process.env.NODE_ENV = env;
done();

@@ -415,3 +533,3 @@ });

process.exit = function () {};
process.exit = function () { };
process.env.NODE_ENV = '';

@@ -441,3 +559,3 @@ process.stdout.write = function (message) {

process.exit = function () {};
process.exit = function () { };
process.env.NODE_ENV = '';

@@ -444,0 +562,0 @@ process.stdout.write = function (message) {

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc