New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ajv-error-messages

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ajv-error-messages

Normalise AJV error messages

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ajv-error-messages

Normalise errors from ajv to a simpler format.

Takes ajv errors and returns a simpler object. Inspired by https://github.com/MauriceButler/jayschema-error-messages

AJV Version

v2 of ajv-error-messages has been upgraded to work with v8 of ajv

Usage

var normalise = require('ajv-error-messages');
var SchemaValidator = require('ajv');
var schemaValidator = SchemaValidator({ allErrors: true });

var schema = {
    description: 'test schema',
    type: 'object',
    additionalProperties: false,
    required: ['foo'],
    properties: {
        foo: {
            type: 'string',
        },
    },
};
var invalidData = {
    foo: 2,
};

var validator = schemaValidator.compile(schema);

function validatingData(data) {

    var valid = validator(data);
    var normalisedErrors;
    if (!valid) {
        var ajvErrors = validator.errors
        normalisedErrors = normalise(ajvErrors);
    }

    return valid || normalisedErrors;
}

console.log(JSON.stringify(validatingData(invalidData)));

results in

{
    fields: {
        'foo': ['Must be string']
    }
}

Keywords

FAQs

Package last updated on 14 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc