MCPcopy
hub / github.com/Pythagora-io/pythagora / isObjectId

Function isObjectId

src/utils/common.js:31–43  ·  view source on GitHub ↗
(value)

Source from the content-addressed store, hash-verified

29const mongoIdRegex = /^[0-9a-fA-F]{24}$/;
30
31const isObjectId = (value) => {
32 try {
33 return (!value || !value.toString || Array.isArray(value)) ? false :
34 (
35 value.constructor.name === 'ObjectId' ||
36 value.constructor.name === 'ObjectID' ||
37 mongoIdRegex.test(value.toString()) ||
38 objectIdAsStringRegex.test(value.toString())
39 );
40 } catch (e) {
41 return false;
42 }
43}
44
45const isLegacyObjectId = (value) => {
46 return !value || !value.constructor ? false : value.constructor.name === 'ObjectID' && isJSONObject(value.id);

Callers 4

compareJsonFunction · 0.85
compareJsonDetailedFunction · 0.85
mongoObjToJsonFunction · 0.85
isObjectId.test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected