Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Dec 21, 2023 via pnpm

ajv-keywords 3.4.1

Custom JSON-Schema keywords for Ajv validator
Package summary
Share
0
issues
0
licenses
Package created
5 Jun 2016
Version published
6 Jul 2019
Maintainers
1
Total deps
0
Direct deps
0
License
MIT

Issues

0
This package has no issues

Frequently Asked Questions

What does ajv-keywords do?

Ajv-keywords is a custom JSON-Schema keywords utility for Ajv validator. This utility comes handy to extend the functionality of Ajv, which is a fast JSON schema validator. Custom keywords provided by ajv-keywords package include typeof, instanceof, range, regex, among others, which offer extended validation mechanisms, hence providing users with more robust ways of validating JSON data.

How do you use ajv-keywords?

Using Ajv-keywords in your project involves a few steps. First, you'll need to install it using npm with the following command: npm install ajv-keywords. Next, in your JavaScript file, you'll require Ajv and ajv-keywords and create an instance of Ajv. You can then add all available keywords from ajv-keywords. Below is a basic example of how to validate a JSON using ajv-keywords:

const Ajv = require("ajv")
const ajv = new Ajv()
require("ajv-keywords")(ajv)

// Use extra keywords from ajv-keywords in your schema
const schema = { instanceof: 'RegExp' }

// Validate 
ajv.validate(schema, /.*/) // returns true
ajv.validate(schema, '.*') // returns false

You can also add specific keywords instead of all available ones, for instance, adding the "instanceof" keyword would look like this:

require("ajv-keywords")(ajv, "instanceof")

Or multiple keywords like so:

require("ajv-keywords")(ajv, ["typeof", "instanceof"])

Where are the ajv-keywords docs?

The documentation for ajv-keywords can be found on its GitHub repository README file: https://github.com/epoberezkin/ajv-keywords. This document provides comprehensive information about all available keywords, installation instructions, usage examples and options, among other details. Following the examples and explanations provided in these docs will give you a deeper understanding of how to leverage ajv-keywords in JSON validation tasks.