ajv-base64

1.0.0 • Public • Published

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: "🔥" }

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i ajv-base64

    Weekly Downloads

    223

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    4.32 kB

    Total Files

    5

    Last publish

    Collaborators

    • singingwolfboy