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

ajv-errors

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ajv-errors - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

.eslintrc.yml

34

package.json
{
"name": "ajv-errors",
"version": "0.0.1",
"version": "0.1.0",
"description": "Custom error messages in JSON-Schema for Ajv validator",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "node node_modules/ajv/scripts/compile-dots.js node_modules/ajv/lib lib",
"eslint": "eslint *.js spec",
"test-spec": "mocha spec/*.spec.js -R spec",
"test-cov": "nyc npm run test-spec",
"test": "npm run eslint && npm run build && npm run test-cov"
},

@@ -25,3 +29,27 @@ "repository": {

},
"homepage": "https://github.com/epoberezkin/ajv-errors#readme"
"homepage": "https://github.com/epoberezkin/ajv-errors#readme",
"peerDependencies": {
"ajv": ">=5.0.0"
},
"devDependencies": {
"ajv": "^5.0.0",
"coveralls": "^2.11.16",
"dot": "^1.1.1",
"eslint": "^3.17.0",
"glob": "^7.1.1",
"js-beautify": "^1.6.12",
"mocha": "^3.2.0",
"nyc": "^10.1.2",
"pre-commit": "^1.2.2"
},
"nyc": {
"exclude": [
"**/spec/**",
"node_modules"
],
"reporter": [
"lcov",
"text-summary"
]
}
}
# ajv-errors
Custom error messages in JSON-Schema for Ajv validator
[![Build Status](https://travis-ci.org/epoberezkin/ajv-errors.svg?branch=master)](https://travis-ci.org/epoberezkin/ajv-errors)
[![npm version](https://badge.fury.io/js/ajv-errors.svg)](http://badge.fury.io/js/ajv-errors)
[![Coverage Status](https://coveralls.io/repos/github/epoberezkin/ajv-errors/badge.svg?branch=master)](https://coveralls.io/github/epoberezkin/ajv-errors?branch=master)
[![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv)
## Install
```
npm install ajv-errors
```
## Usage
Add the keyword `errorMessages` to Ajv instance:
```javascript
var Ajv = require('ajv');
var ajv = new Ajv({allErrors: true}); // option allErrors is required
require('ajv-errors')(ajv);
```
#### Replace all errors in the current schema and subschemas with a single message:
```javascript
var schema = {
type: 'object',
required: ['foo'],
properties: {
foo: { type: 'integer' }
},
additionalProperties: false,
errorMessage: 'should be an object with an integer property foo only'
};
var validate = ajv.compile(schema);
console.log(validate({foo: 'a', bar: 2})); // false
console.log(validate.errors); // processed errors
```
Processed errors:
```javascript
[
{
keyword: 'errorMessage',
message: 'should be an object with an integer property foo only',
// ...
params: {
errors: [
{ keyword: 'additionalProperties', dataPath: '' /* , ... */ },
{ keyword: 'type', dataPath: '.foo' /* , ... */ }
]
}
}
]
```
#### Replace errors for certain keywords in the current schema only:
```javascript
var schema = {
type: 'object',
required: ['foo'],
properties: {
foo: { type: 'integer' }
},
additionalProperties: false,
errorMessage: {
type: 'should be an object', // will not replace internal "type" error for the property "foo"
required: 'should have property foo',
additionalProperties: 'should not have properties other than foo'
}
};
var validate = ajv.compile(schema);
console.log(validate({foo: 'a', bar: 2})); // false
console.log(validate.errors); // processed errors
```
Processed errors:
```javascript
[
{
// original error
keyword: type,
dataPath: '.foo',
// ...
message: 'should be integer'
},
{
// generated error
keyword: 'errorMessage',
message: 'should not have properties other than foo',
// ...
params: {
errors: [
{ keyword: 'additionalProperties' /* , ... */ }
]
},
}
]
```
## License
[MIT](https://github.com/epoberezkin/ajv-errors/blob/master/LICENSE)

Sorry, the diff of this file is not supported yet

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