Files
NodeBB/src/database/mongo/helpers.js

37 lines
724 B
JavaScript
Raw Normal View History

"use strict";
2014-10-12 18:04:16 -04:00
var helpers = {};
helpers.toMap = function(data) {
var map = {};
2016-10-13 11:42:29 +02:00
for (var i = 0; i < data.length; ++i) {
map[data[i]._key] = data[i];
data[i]._key = undefined;
}
return map;
};
helpers.fieldToString = function(field) {
if(field === null || field === undefined) {
return field;
}
if(typeof field !== 'string') {
field = field.toString();
}
// if there is a '.' in the field name it inserts subdocument in mongo, replace '.'s with \uff0E
field = field.replace(/\./g, '\uff0E');
return field;
};
helpers.valueToString = function(value) {
if(value === null || value === undefined) {
return value;
}
return value.toString();
};
2014-09-03 01:13:28 -04:00
helpers.noop = function() {};
module.exports = helpers;