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

mongojs-hooks

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongojs-hooks - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

22

mongojs-hooks.js

@@ -120,2 +120,24 @@ var mongojs = require("mongojs");

return newObject;
},
// Flattens an object into dot-notation
flatten: function (object) {
var result = { };
for (var i in object) {
if (!object.hasOwnProperty(i)) continue;
if (isObject(object[i])) {
var flatObject = this.flatten(object[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
result[i + '.' + x] = flatObject[x];
}
} else {
result[i] = object[i];
}
}
return result;
}

@@ -122,0 +144,0 @@ };

2

package.json
{
"name": "mongojs-hooks",
"description": "Wrap monogjs in pre and post hooks",
"version": "0.1.7",
"version": "0.1.8",
"main": "./mongojs-hooks",

@@ -6,0 +6,0 @@ "author": {

@@ -269,2 +269,63 @@ var mongo = require("../mongojs-hooks");

});
describe("flatten()", function () {
describe("when an object", function () {
it("and nested", function () {
var object = {
first: {
second: "value"
}
};
var flattened = mongo.util.flatten(object);
flattened.should.deep.equal({
"first.second": "value"
});
});
it("with multiple values", function () {
var object = {
first: {
second: "value",
third: "val"
}
};
var flattened = mongo.util.flatten(object);
flattened.should.deep.equal({
"first.second": "value",
"first.third": "val"
});
});
it("and contains an Array", function () {
var object = {
first: {
second: [ "el1", "el2", "el3" ]
}
};
var flattened = mongo.util.flatten(object);
flattened.should.deep.equal({
"first.second": [ "el1", "el2", "el3" ]
});
});
it("should not mutate original object", function () {
var object = {
first: {
second: "value"
}
};
mongo.util.flatten(object);
object.should.not.have.property("first.second");
object.should.deep.equal({
first: {
second: "value"
}
});
});
});
});
});
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