2
0

mongo-id.ts 361 B

12345678910
  1. const MONGO_ID_PATTERN = /^[0-9a-f]{24}$/i;
  2. /**
  3. * Check if a string is a valid MongoDB ObjectID (24-char hex string).
  4. * Lightweight replacement for validator.isMongoId() to avoid pulling
  5. * the entire validator package (113 modules) into the client bundle.
  6. */
  7. export const isMongoId = (value: string): boolean => {
  8. return MONGO_ID_PATTERN.test(value);
  9. };