Socket
Socket
Sign inDemoInstall

hoek

Package Overview
Dependencies
0
Maintainers
3
Versions
116
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.0 to 2.3.0

59

lib/index.js

@@ -156,2 +156,61 @@ // Load modules

// Clone an object except for the listed keys which are shallow copied
exports.cloneWithShallow = function (source, keys) {
if (!source ||
typeof source !== 'object') {
return source;
}
return internals.shallow(source, keys, function () {
return exports.clone(source);
});
};
// Apply options to defaults except for the listed keys which are shallow copied from option without merging
exports.applyToDefaultsWithShallow = function (defaults, options, keys) {
return internals.shallow(options, keys, function () {
return exports.applyToDefaults(defaults, options);
});
};
internals.shallow = function (source, keys, clone) {
// Move shallow copy items to storage
var storage = {};
for (var i = 0, il = keys.length; i < il; ++i) {
var key = keys[i];
if (source.hasOwnProperty(key)) {
storage[key] = source[key];
source[key] = undefined;
}
}
// Deep copy the rest
var copy = clone();
// Shallow copy the stored items
for (i = 0; i < il; ++i) {
var key = keys[i];
if (storage.hasOwnProperty(key)) {
source[key] = storage[key];
copy[key] = storage[key];
}
}
return copy;
};
// Remove duplicate items from array

@@ -158,0 +217,0 @@

2

package.json
{
"name": "hoek",
"description": "General purpose node utilities",
"version": "2.2.0",
"version": "2.3.0",
"repository": "git://github.com/spumko/hoek",

@@ -6,0 +6,0 @@ "main": "index",

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

it('should return null if options is false', function (done) {
it('returns null if options is false', function (done) {

@@ -494,3 +494,3 @@ var result = Hoek.applyToDefaults(defaults, false);

it('should return a copy of defaults if options is true', function (done) {
it('returns a copy of defaults if options is true', function (done) {

@@ -502,3 +502,3 @@ var result = Hoek.applyToDefaults(defaults, true);

it('should apply object to defaults', function (done) {
it('applies object to defaults', function (done) {

@@ -526,2 +526,96 @@ var obj = {

describe('#cloneWithShallow', function () {
it('deep clones except for listed keys', function (done) {
var source = {
a: {
b: 5
},
c: {
d: 6
}
};
var copy = Hoek.cloneWithShallow(source, ['c']);
expect(copy).to.deep.equal(source);
expect(copy).to.not.equal(source);
expect(copy.a).to.not.equal(source.a);
expect(copy.b).to.equal(source.b);
done();
});
it('returns immutable value', function (done) {
expect(Hoek.cloneWithShallow(5)).to.equal(5);
done();
});
it('returns null value', function (done) {
expect(Hoek.cloneWithShallow(null)).to.equal(null);
done();
});
it('returns undefined value', function (done) {
expect(Hoek.cloneWithShallow(undefined)).to.equal(undefined);
done();
});
it('deep clones except for listed keys (including missing keys)', function (done) {
var source = {
a: {
b: 5
},
c: {
d: 6
}
};
var copy = Hoek.cloneWithShallow(source, ['c', 'v']);
expect(copy).to.deep.equal(source);
expect(copy).to.not.equal(source);
expect(copy.a).to.not.equal(source.a);
expect(copy.b).to.equal(source.b);
done();
});
});
describe('#applyToDefaultsWithShallow', function () {
it('shallow copies the listed keys from options without merging', function (done) {
var defaults = {
a: {
b: 5,
e: 3
},
c: {
d: 7,
g: 1
}
};
var options = {
a: {
b: 4
},
c: {
d: 6,
f: 7
}
};
var merged = Hoek.applyToDefaultsWithShallow(defaults, options, ['a']);
expect(merged).to.deep.equal({ a: { b: 4 }, c: { d: 6, g: 1, f: 7 } });
expect(merged.a).to.equal(options.a);
expect(merged.a).to.not.equal(defaults.a);
expect(merged.c).to.not.equal(options.c);
expect(merged.c).to.not.equal(defaults.c);
done();
});
});
describe('#unique', function () {

@@ -545,3 +639,3 @@

it('should return null on null array', function (done) {
it('returns null on null array', function (done) {

@@ -575,3 +669,3 @@ var a = Hoek.mapToObject(null);

it('should return the common objects of two arrays', function (done) {
it('returns the common objects of two arrays', function (done) {

@@ -585,3 +679,3 @@ var array1 = [1, 2, 3, 4, 4, 5, 5];

it('should return just the first common object of two arrays', function (done) {
it('returns just the first common object of two arrays', function (done) {

@@ -604,3 +698,3 @@ var array1 = [1, 2, 3, 4, 4, 5, 5];

it('should return an empty array if either input is null', function (done) {
it('returns an empty array if either input is null', function (done) {

@@ -612,3 +706,3 @@ expect(Hoek.intersect([1], null).length).to.equal(0);

it('should return the common objects of object and array', function (done) {
it('returns the common objects of object and array', function (done) {

@@ -625,3 +719,3 @@ var array1 = [1, 2, 3, 4, 4, 5, 5];

it('should return a flat array', function (done) {
it('returns a flat array', function (done) {

@@ -733,3 +827,3 @@ var result = Hoek.flatten([1, 2, [3, 4, [5, 6], [7], 8], [9], [10, [11, 12]], 13]);

it('should return the full call stack', function (done) {
it('returns the full call stack', function (done) {

@@ -745,3 +839,3 @@ var stack = Hoek.callStack();

it('should return the full call stack for display', function (done) {
it('returns the full call stack for display', function (done) {

@@ -949,3 +1043,3 @@ var stack = Hoek.displayStack();

it('should return time elapsed', function (done) {
it('returns time elapsed', function (done) {

@@ -963,3 +1057,3 @@ var timer = new Hoek.Timer();

it('should return time elapsed', function (done) {
it('returns time elapsed', function (done) {

@@ -1034,3 +1128,3 @@ var timer = new Hoek.Bench();

it('should return error on undefined input', function (done) {
it('returns error on undefined input', function (done) {

@@ -1041,3 +1135,3 @@ expect(Hoek.base64urlDecode().message).to.exist;

it('should return error on invalid input', function (done) {
it('returns error on invalid input', function (done) {

@@ -1098,3 +1192,3 @@ expect(Hoek.base64urlDecode('*').message).to.exist;

it('should return empty string on falsy input', function (done) {
it('returns empty string on falsy input', function (done) {

@@ -1106,3 +1200,3 @@ var a = Hoek.escapeHtml('');

it('should return unchanged string on no reserved input', function (done) {
it('returns unchanged string on no reserved input', function (done) {

@@ -1109,0 +1203,0 @@ var a = Hoek.escapeHtml('abc');

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc