payload
Version:
Node, React, Headless CMS and Application Framework built on Next.js
22 lines (21 loc) • 642 B
JavaScript
import ObjectIdImport from 'bson-objectid';
const ObjectId = ObjectIdImport.default || ObjectIdImport;
export const isValidID = (value, type)=>{
if (type === 'text' && value) {
if ([
'object',
'string'
].includes(typeof value)) {
const isObjectID = ObjectId.isValid(value);
return typeof value === 'string' || isObjectID;
}
return false;
}
if (typeof value === 'number' && !Number.isNaN(value)) {
return true;
}
if (type === 'ObjectID') {
return ObjectId.isValid(String(value));
}
};
//# sourceMappingURL=isValidID.js.map