项目作者: saucecodee

项目描述 :
MongoDB ObjectId validator for Joi
高级语言: TypeScript
项目地址: git://github.com/saucecodee/joi-objectid-validator.git
创建时间: 2021-03-17T22:58:32Z
项目社区:https://github.com/saucecodee/joi-objectid-validator

开源协议:MIT License

下载


Joi Objectid validator

MongoDB ObjectId validator for Joi.

Installation

  1. npm install joi-objectid-validator --save

Usage

The joi-objectid-validator validates only valid MongoDB ObjectId so it accepts either a 24 character hexadecimal String or an ObjectId type

  1. const Joi = require('@hapi/joi')
  2. // Add joi-objectid-validator to Joi object
  3. Joi.objectId = require('joi-objectid-validator')(Joi)
  4. const schema = Joi.object({
  5. id: Joi.objectId("Custom error message here"),
  6. })
  7. // VALID values
  8. //
  9. // new ObjectID()
  10. // new ObjectID("ccd563780134d5678901234a")
  11. // '6053a49e634e0ec405295ba8'
  12. // INVALID values
  13. //
  14. // '$bcd56778c9a345678901234'
  15. // ' bcd56789012345678901234'
  16. // '6053a49e634e0ec405g95ba8'
  17. // 748397383836789234567823
  18. // { }
  19. // null

Development

Testing

  • npm test

License

MIT