joi-mongoose-objectid

2.0.1 • Public • Published

joi-mongoose-objectid

Joi extension to validate MongoDB objectId with mongoose

use

joi-mongoose-objectid give you the Joi.objectId() function that validate the input with mongoose.Types.ObjectId.isValid(value).

It is a Joi extension so you should extends Joi with it. Then you can extend Joi with other extensions.

let Joi = require('@hapi/joi');
const joiObjectIdExtension = require('joi-mongoose-objectid');
 
Joi = Joi.extend((Joi) => joiObjectIdExtension);
 
const schema = Joi.object({
  id: Joi.objectId(),
  name: Joi.string().max(100),
  date: Joi.date()
});
 
schema.validate();
 

Installation

npm install joi-mongoose-objectid

OR

yarn add joi-mongoose-objectid

Tests

There is two simple tests on the test.js file. One for success and one for failure. To run tests :

npm run test

OR

yarn test

License

MIT

Dependents (0)

Package Sidebar

Install

npm i joi-mongoose-objectid

Weekly Downloads

0

Version

2.0.1

License

MIT

Unpacked Size

2.38 kB

Total Files

4

Last publish

Collaborators

  • florian_varrin