From 04dd0d3a9c7e011d678de2d20f0f6cee085892c0 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Wed, 18 Sep 2013 18:05:21 -0700 Subject: [PATCH] Put logical operators where they belong, in match --- lib/model.js | 19 ++++++++++++++++--- test/model.test.js | 6 +++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/model.js b/lib/model.js index e0e6516..f409e15 100644 --- a/lib/model.js +++ b/lib/model.js @@ -131,6 +131,20 @@ function deepCopy (obj) { } +/** + * Tells if an object is a primitive type or a "real" object + * Arrays are considered primitive + */ +function isPrimitiveType (obj) { + return ( typeof obj === 'boolean' || + typeof obj === 'number' || + typeof obj === 'string' || + obj === null || + util.isDate(obj) || + util.isArray(obj)); +} + + /** * Utility functions for comparing things * Assumes type checking was already done (a and b already have the same type) @@ -600,7 +614,7 @@ logicalOperators.$not = function (obj, query) { /** - * Tell if a given document matches a query + * Tell if a given document matches a query * @param {Object} obj Document to check * @param {Object} query */ @@ -631,8 +645,7 @@ function match (obj, query) { */ function matchQueryPart (obj, queryKey, queryValue) { var objValue = getDotValue(obj, queryKey) - , i - , keys, firstChars, dollarFirstChars + , i, keys, firstChars, dollarFirstChars ; // Check if the object value is an array treat it as an array of { obj, query } diff --git a/test/model.test.js b/test/model.test.js index 5f13dfa..8751b92 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -165,6 +165,10 @@ describe('Model', function () { model.checkObject(obj); }); + + it.only('Can check if an object is a primitive or not', function () { + + }); }); // ==== End of 'Object checking' ==== // @@ -200,7 +204,7 @@ describe('Model', function () { }); }); // ==== End of 'Deep copying' ==== // - + describe('Modifying documents', function () {