1.0.0 • Published 4 years ago
ajv-base64 v1.0.0
ajv-base64
Adds a base64
format to Ajv.
Install
npm install ajv-base64
or
yarn add ajv-base64
Note that this package isn't very useful without Ajv itself, so you should install that as well.
Setup
const Ajv = require("ajv");
const ajv = new Ajv();
require("ajv-base64")(ajv);
Usage
When defining your JSON schema, use the format
keyword with the value set to base64
. For example:
{
"type": "object",
"properties": {
"cursor": {
"type": "string",
"format": "base64"
}
}
}
Valid data:
{ cursor: "YWJj" }
{ cursor: "SGVsbG8sIHdvcmxkIQ==" }
Invalid data:
{ cursor: "" }
{ cursor: "Hello, world!" }
{ cursor: "🔥" }
1.0.0
4 years ago