Commit 45d26e73 by James Cropcho

capitalizing types

parent 3693bc46
...@@ -15,13 +15,13 @@ So, let's see what we've got here: ...@@ -15,13 +15,13 @@ So, let's see what we've got here:
$ mongo test --eval "var collection = 'users'" variety.js $ mongo test --eval "var collection = 'users'" variety.js
{ "_id" : { "key" : "_id" }, "value" : { "types" : [ "objectId" ] }, "totalOccurrences" : 5, "percentContaining" : 100 } { "_id" : { "key" : "_id" }, "value" : { "types" : [ "ObjectId" ] }, "totalOccurrences" : 5, "percentContaining" : 100 }
{ "_id" : { "key" : "name" }, "value" : { "types" : [ "string" ] }, "totalOccurrences" : 5, "percentContaining" : 100 } { "_id" : { "key" : "name" }, "value" : { "types" : [ "String" ] }, "totalOccurrences" : 5, "percentContaining" : 100 }
{ "_id" : { "key" : "bio" }, "value" : { "types" : [ "string" ] }, "totalOccurrences" : 3, "percentContaining" : 60 } { "_id" : { "key" : "bio" }, "value" : { "types" : [ "String" ] }, "totalOccurrences" : 3, "percentContaining" : 60 }
{ "_id" : { "key" : "birthday" }, "value" : { "types" : [ "date" ] }, "totalOccurrences" : 2, "percentContaining" : 40 } { "_id" : { "key" : "birthday" }, "value" : { "types" : [ "Date" ] }, "totalOccurrences" : 2, "percentContaining" : 40 }
{ "_id" : { "key" : "pets" }, "value" : { "types" : [ "string", "array" ] }, "totalOccurrences" : 2, "percentContaining" : 40 } { "_id" : { "key" : "pets" }, "value" : { "types" : [ "String", "Array" ] }, "totalOccurrences" : 2, "percentContaining" : 40 }
{ "_id" : { "key" : "someBinData" }, "value" : { "type" : "binData" }, "totalOccurrences" : 1, "percentContaining" : 20 } { "_id" : { "key" : "someBinData" }, "value" : { "type" : "BinData" }, "totalOccurrences" : 1, "percentContaining" : 20 }
{ "_id" : { "key" : "someWeirdLegacyKey" }, "value" : { "type" : "string" }, "totalOccurrences" : 1, "percentContaining" : 20 } { "_id" : { "key" : "someWeirdLegacyKey" }, "value" : { "type" : "String" }, "totalOccurrences" : 1, "percentContaining" : 20 }
_("test" is the database containing the collection we are analyzing.)_ _("test" is the database containing the collection we are analyzing.)_
......
...@@ -51,26 +51,28 @@ varietyTypeOf = function(thing) { ...@@ -51,26 +51,28 @@ varietyTypeOf = function(thing) {
if (typeof thing === "undefined") { throw "varietyTypeOf() requires an argument"; } if (typeof thing === "undefined") { throw "varietyTypeOf() requires an argument"; }
if (typeof thing !== "object") { if (typeof thing !== "object") {
return typeof thing; // the messiness below capitalizes the first letter, so the output matches
// the other return values below. -JC
return (typeof thing)[0].toUpperCase() + (typeof thing).slice(1);
} }
else { else {
if (thing && thing.constructor === Array) { if (thing && thing.constructor === Array) {
return "array"; return "Array";
} }
else if (thing === null) { else if (thing === null) {
return "null"; return "null";
} }
else if (thing instanceof Date) { else if (thing instanceof Date) {
return "date"; return "Date";
} }
else if (thing instanceof ObjectId) { else if (thing instanceof ObjectId) {
return "objectId"; return "ObjectId";
} }
else if (thing instanceof BinData) { else if (thing instanceof BinData) {
return "binData"; return "BinData";
} }
else { else {
return "object"; return "Object";
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment