Comparing version 0.0.6 to 0.0.7
@@ -26,3 +26,10 @@ // Load modules | ||
if (obj.hasOwnProperty(i)) { | ||
if (obj[i] && typeof obj[i] === 'object') { | ||
if (obj[i] instanceof Date) { | ||
newObj[i] = new Date(obj[i].getTime()); | ||
} | ||
else if (obj[i] instanceof RegExp) { | ||
var flags = '' + (obj[i].global ? 'g' : '') + (obj[i].ignoreCase ? 'i' : '') + (obj[i].multiline ? 'm' : '') + (obj[i].sticky ? 'y' : ''); | ||
newObj[i] = new RegExp(obj[i].source, flags); | ||
} | ||
else if (typeof obj[i] === 'object') { | ||
newObj[i] = exports.clone(obj[i]); | ||
@@ -29,0 +36,0 @@ } |
{ | ||
"name": "hoek", | ||
"description": "General purpose node utilities", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "contributors":[ |
@@ -0,0 +0,0 @@ hoek |
@@ -6,88 +6,90 @@ var assert = require('assert'); | ||
describe("hoek", function(){ | ||
var emptyObj = {}; | ||
var nestedObj = { | ||
x: 'x', | ||
y: 'y' | ||
} | ||
var dupsArray = [nestedObj, {z:'z'}, nestedObj]; | ||
var reducedDupsArray = [nestedObj, {z:'z'}]; | ||
describe("#clone", function(){ | ||
it("should clone a nested object", function(done){ | ||
var a = nestedObj; | ||
var b = hoek.clone(a); | ||
assert.deepEqual(a, b); | ||
done(); | ||
describe("hoek", function () { | ||
var emptyObj = {}; | ||
var nestedObj = { | ||
x: 'x', | ||
y: 'y', | ||
z: new Date() | ||
} | ||
var dupsArray = [nestedObj, { z: 'z' }, nestedObj]; | ||
var reducedDupsArray = [nestedObj, { z: 'z' }]; | ||
describe("#clone", function () { | ||
it("should clone a nested object", function (done) { | ||
var a = nestedObj; | ||
var b = hoek.clone(a); | ||
assert.deepEqual(a, b); | ||
b.z.should.equal(a.z); | ||
done(); | ||
}) | ||
}) | ||
}) | ||
describe("#merge", function(){ | ||
it("should", function(done){ | ||
var a = emptyObj; | ||
var b = nestedObj; | ||
var c = hoek.merge(a, b); | ||
assert.deepEqual(a, b); | ||
assert.deepEqual(c, b); | ||
done(); | ||
describe("#merge", function () { | ||
it("should", function (done) { | ||
var a = emptyObj; | ||
var b = nestedObj; | ||
var c = hoek.merge(a, b); | ||
assert.deepEqual(a, b); | ||
assert.deepEqual(c, b); | ||
done(); | ||
}) | ||
}) | ||
}) | ||
describe("#unique", function(){ | ||
it("should ensure uniqueness within array of objects based on subkey", function(done){ | ||
var a = hoek.unique(dupsArray, 'x'); | ||
assert.deepEqual(a, reducedDupsArray); | ||
done(); | ||
describe("#unique", function () { | ||
it("should ensure uniqueness within array of objects based on subkey", function (done) { | ||
var a = hoek.unique(dupsArray, 'x'); | ||
assert.deepEqual(a, reducedDupsArray); | ||
done(); | ||
}) | ||
}) | ||
}) | ||
describe("#mapToObject", function () { | ||
it("should convert basic array to existential object", function(done){ | ||
var keys = [1,2,3,4]; | ||
var a = hoek.mapToObject(keys); | ||
for(var i in keys){ | ||
a[keys[i]].should.equal(true); | ||
} | ||
done(); | ||
describe("#mapToObject", function () { | ||
it("should convert basic array to existential object", function (done) { | ||
var keys = [1, 2, 3, 4]; | ||
var a = hoek.mapToObject(keys); | ||
for (var i in keys) { | ||
a[keys[i]].should.equal(true); | ||
} | ||
done(); | ||
}) | ||
it("should convert array of objects to existential object", function (done) { | ||
var keys = [{ x: 1 }, { x: 2 }, { x: 3 }]; | ||
var subkey = 'x'; | ||
var a = hoek.mapToObject(keys, subkey); | ||
for (var i in keys) { | ||
a[keys[i][subkey]].should.equal(true); | ||
} | ||
done(); | ||
}) | ||
}) | ||
it("should convert array of objects to existential object", function(done){ | ||
var keys = [{x:1}, {x:2}, {x:3}]; | ||
var subkey = 'x'; | ||
var a = hoek.mapToObject(keys, subkey); | ||
for(var i in keys){ | ||
a[keys[i][subkey]].should.equal(true); | ||
} | ||
done(); | ||
}) | ||
}) | ||
describe("#removeKeys", function(){ | ||
var objWithHiddenKeys = { | ||
location: { | ||
name: 'San Bruno' | ||
}, | ||
company: { | ||
name: "@WalmartLabs" | ||
} | ||
} | ||
it("should delete params with definition's hide set to true", function(done){ | ||
var a = hoek.removeKeys(objWithHiddenKeys, ['location']); | ||
should.not.exist(objWithHiddenKeys.location); | ||
should.exist(objWithHiddenKeys.company); | ||
done(); | ||
describe("#removeKeys", function () { | ||
var objWithHiddenKeys = { | ||
location: { | ||
name: 'San Bruno' | ||
}, | ||
company: { | ||
name: "@WalmartLabs" | ||
} | ||
} | ||
it("should delete params with definition's hide set to true", function (done) { | ||
var a = hoek.removeKeys(objWithHiddenKeys, ['location']); | ||
should.not.exist(objWithHiddenKeys.location); | ||
should.exist(objWithHiddenKeys.company); | ||
done(); | ||
}) | ||
}) | ||
}) | ||
describe("#assert", function() { | ||
it('should throw an Error when using assert in a test', function(done) { | ||
(function() { | ||
hoek.assert(false, 'my error message') | ||
}).should.throw('my error message'); | ||
done(); | ||
describe("#assert", function () { | ||
it('should throw an Error when using assert in a test', function (done) { | ||
(function () { | ||
hoek.assert(false, 'my error message') | ||
}).should.throw('my error message'); | ||
done(); | ||
}) | ||
}) | ||
}) | ||
}) |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
14509
311
0