mongoose-diff-tracking
Version:
Manage Mongo Collection diff History and versions
38 lines (30 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.normalizeQueryCondition = normalizeQueryCondition;
/**
* QueryCondition | EqCondition => QueryCondition
*/
function normalizeQueryCondition(condition) {
if (condition == null) {
return { $eq: null };
}
if (isRegExp(condition)) {
// $FlowIssue(only-regex-comes-here)
return { $regex: condition };
}
if ((typeof condition === 'undefined' ? 'undefined' : _typeof(condition)) != 'object' || Array.isArray(condition)) {
return { $eq: condition };
}
var keys = Object.keys(condition);
// if empty, regarded as QueryCondition
if (keys[0] == null) {
return condition;
}
return keys[0].charAt(0) === '$' ? condition : { $eq: condition };
}
function isRegExp(val) {
return val && val.constructor === RegExp;
}