tv4-mongodb

Helper module for tv4 to validate against MongoDB ObjectId.

Usage no npm install needed!

<script type="module">
  import tv4Mongodb from 'https://cdn.skypack.dev/tv4-mongodb';
</script>

README

tv4-mongodb

About

Helper module for tv4 to validate against MongoDB ObjectId.

Install

$ npm install --save tv4 tv4-mongodb

Usage

const assert = require("assert");
const tv4 = require("tv4");

const validator = tv4.freshApi();
validator.addFormat(require("tv4-mongodb"));

const schema = { type: "string", format: "bson-objectid" };

assert(validator.validate("585d4f15d890997a4fb0d2e8", schema)); // Valid ObjectId
assert(!validator.validate("585d4f15d890997a4fb0d2z8", schema)); // Invalid ObjectId