periodicjs.core.data
Version:
Core data is the ORM wrapping component of periodicjs.core.controller that provides database adapters for commonly used databases (ie. mongo, sql, postgres). Adapters provide a standard set of methods and options regardless of the type of database and so
12 lines • 441 B
JavaScript
;
const mongoose = require('mongoose');
/**
* Determines if value is a valid mongo id
* @param {*} value Any value to test
* @return {Boolean} Returns true if value is a valid mongo id
*/
module.exports = function isObjectId (value) {
if (!value) return false;
value = (typeof value === 'string') ? value : value.toString();
return /^[0-9a-fA-F]{24,32}$/.test(value) && mongoose.Types.ObjectId.isValid(value);
};