Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/singingwolfboy/ajv-base64
Ajv plugin to validate base64 strings
https://github.com/singingwolfboy/ajv-base64
Last synced: 27 days ago
JSON representation
Ajv plugin to validate base64 strings
- Host: GitHub
- URL: https://github.com/singingwolfboy/ajv-base64
- Owner: singingwolfboy
- License: mit
- Created: 2020-03-02T12:17:53.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-02T13:32:38.000Z (almost 5 years ago)
- Last Synced: 2024-11-16T17:24:46.348Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 55.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ajv-base64
Adds a `base64` format to [Ajv](https://ajv.js.org).
## Install
```
npm install ajv-base64
```or
```
yarn add ajv-base64
```Note that this package isn't very useful without [Ajv](https://ajv.js.org) itself, so you should install that as well.
## Setup
```js
const Ajv = require("ajv");
const ajv = new Ajv();
require("ajv-base64")(ajv);
```## Usage
When defining your JSON schema, use the [`format` keyword](https://ajv.js.org/keywords.html#format) with the value set to `base64`. For example:
```json
{
"type": "object",
"properties": {
"cursor": {
"type": "string",
"format": "base64"
}
}
}
```Valid data:
- `{ cursor: "YWJj" }`
- `{ cursor: "SGVsbG8sIHdvcmxkIQ==" }`Invalid data:
- `{ cursor: "" }`
- `{ cursor: "Hello, world!" }`
- `{ cursor: "🔥" }`