|
|
@@ -8,7 +8,7 @@
|
|
|
* @constructor
|
|
|
**/
|
|
|
var Value = module.exports = function Value(){
|
|
|
- if(this.constructor == Value) throw new Error("Never create instances of this! Use the static helpers only.");
|
|
|
+ if(this.constructor === Value) throw new Error("Never create instances of this! Use the static helpers only.");
|
|
|
}, klass = Value, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
|
var Document; // loaded lazily below //TODO: a dirty hack; need to investigate and clean up
|
|
|
@@ -27,7 +27,7 @@ var Document; // loaded lazily below //TODO: a dirty hack; need to investigate
|
|
|
* @static
|
|
|
*/
|
|
|
klass.coerceToBool = function coerceToBool(value) {
|
|
|
- if (typeof(value) == "string") return true;
|
|
|
+ if (typeof value === "string") return true;
|
|
|
return !!value; // including null or undefined
|
|
|
};
|
|
|
|
|
|
@@ -71,7 +71,7 @@ klass.coerceToDate = function coerceToDate(value) {
|
|
|
//SKIPPED: tmToISODateString -- not required; just use Date
|
|
|
klass.coerceToString = function coerceToString(value) {
|
|
|
var type = typeof(value);
|
|
|
- if (type == "object") type = value === null ? "null" : value.constructor.name;
|
|
|
+ if (type === "object") type = value === null ? "null" : value.constructor.name;
|
|
|
switch (type) {
|
|
|
//TODO: BSON numbers?
|
|
|
case "number":
|
|
|
@@ -131,7 +131,7 @@ klass.compare = function compare(l, r) {
|
|
|
}
|
|
|
// Compare MinKey and MaxKey cases
|
|
|
if (l instanceof Object && ["MinKey", "MaxKey"].indexOf(l.constructor.name) !== -1) {
|
|
|
- if (l.constructor.name == r.constructor.name) {
|
|
|
+ if (l.constructor.name === r.constructor.name) {
|
|
|
return 0;
|
|
|
} else if (l.constructor.name === "MinKey") {
|
|
|
return -1;
|
|
|
@@ -154,7 +154,7 @@ klass.compare = function compare(l, r) {
|
|
|
case "string":
|
|
|
return klass.cmp(l, r);
|
|
|
case "boolean":
|
|
|
- return l == r ? 0 : l ? 1 : -1;
|
|
|
+ return l === r ? 0 : l ? 1 : -1;
|
|
|
case "undefined": //NOTE: deviation from mongo code: we are comparing null to null or undefined to undefined (otherwise the ret stuff above would have caught it)
|
|
|
case "null":
|
|
|
return 0;
|
|
|
@@ -201,12 +201,12 @@ klass.consume = function consume(consumed) {
|
|
|
};
|
|
|
|
|
|
//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"
|
|
|
+// 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);
|
|
|
+ if (t === "object") t = (v === null ? "null" : v.constructor.name || t);
|
|
|
return t;
|
|
|
};
|
|
|
// getArrayLength(arr): arr.length
|
|
|
@@ -226,7 +226,7 @@ klass.getType = function getType(v) {
|
|
|
// from bsontypes
|
|
|
klass.canonicalize = function canonicalize(x) {
|
|
|
var xType = typeof(x);
|
|
|
- if (xType == "object") xType = x === null ? "null" : x.constructor.name;
|
|
|
+ if (xType === "object") xType = x === null ? "null" : x.constructor.name;
|
|
|
switch (xType) {
|
|
|
case "MinKey":
|
|
|
return -1;
|