@ciruxx/joi-extension-objectid

A Joi extension for validate ObjectId

Usage no npm install needed!

<script type="module">
  import ciruxxJoiExtensionObjectid from 'https://cdn.skypack.dev/@ciruxx/joi-extension-objectid';
</script>

README

joi-extension-objectid

version license

ObjectId extension for the Joi validation library

Usage

const JoiExtensionObjectId = require('@ciruxx/joi-extension-objectid');
const Joi = require('joi').extend(JoiExtensionObjectId);

const schema = Joi.object({
    objectIdKey: Joi.objectId()
});

const validatedData = await schema.validateAsync({
    objectIdKey: "5fd777d57fcb54c356763034"
})

data.objectIdKey instanceof ObjectID // true!

offrex