2.0.6 • Published 1 year ago

joi-mongodb-oid v2.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

joi-mongodb-oid

Custom Joi validator for MongoDB ObjectId.

Install

npm install joi-mongodb-oid

CommonJS Usage

In your application's entry point (index.js/server.js/app.js):

const Joi = require('joi-mongodb-oid')();

Then the objectId() validator can be used just like any other Joi validator:

const schema = Joi.object({
  _id: Joi.objectId(),
  name: Joi.string(),
  date: Joi.date(),
});

ESM Usage

In your application's entry point (index.js/server.js/app.js):

import JoiMongoDB from 'joi-mongodb-oid';
const Joi = JoiMongoDB();

Then the objectId() validator can be used just like any other Joi validator:

const schema = Joi.object({
  _id: Joi.objectId(),
  name: Joi.string(),
  date: Joi.date(),
});

TS Usage

Inject the objectId validator:

import JoiMongoDB from 'joi-mongodb-oid';
const Joi = JoiMongoDB();

Then the objectId() validator can be used just like any other Joi validator:

const schema = Joi.object({
  _id: Joi.objectId(),
  name: Joi.string(),
  date: Joi.date(),
});

Similar Packages

2.0.6

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago