Browse Source

EAGLESIX-2651: Value: add getType helper

Kyle P Davis 11 years ago
parent
commit
22ac3a1af7
1 changed files with 6 additions and 3 deletions
  1. 6 3
      lib/pipeline/Value.js

+ 6 - 3
lib/pipeline/Value.js

@@ -200,10 +200,15 @@ klass.consume = function consume(consumed) {
 	return consumed.splice(0);
 };
 
-//NOTE: DEVIATION FROM MONGO: these are inlined using the below code or perhaps not relevant since we are not boxing
+//NOTE: DEVIATION FROM MONGO: many of these do not apply or are inlined (code where relevant)
 // missing(val):  val == undefined
 // nullish(val):  val == null || val == undefined
 // numeric(val):  typeof val == "number"
+klass.getType = function getType(v) {
+	var t = typeof v;
+	if (t == "object") t = (v === null ? "null" : v.constructor.name || t);
+	return t;
+};
 // getArrayLength(arr): arr.length
 // getString(val): val.toString()   //NOTE: same for getStringData(val) I think
 // getOid
@@ -218,8 +223,6 @@ klass.consume = function consume(consumed) {
 // getLong
 //NOTE: also, because of this we are not throwing if the type does not match like the mongo code would but maybe that's okay
 
-//SKIPPED: getType -- need this or something like it? would be some more stuff from bsontypes
-
 // from bsontypes
 klass.canonicalize = function canonicalize(x) {
 	var xType = typeof(x);