Gathering detailed insights and metrics for awesome-ajv-errors
Gathering detailed insights and metrics for awesome-ajv-errors
Gathering detailed insights and metrics for awesome-ajv-errors
Gathering detailed insights and metrics for awesome-ajv-errors
npm install awesome-ajv-errors
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
26 Stars
34 Commits
2 Watching
1 Branches
1 Contributors
Updated on 12 Oct 2024
TypeScript (95.57%)
JavaScript (4.43%)
Cumulative downloads
Total Downloads
Last day
-2.5%
7,818
Compared to previous day
Last week
3.9%
36,712
Compared to previous week
Last month
8.8%
142,841
Compared to previous month
Last year
96.6%
1,374,042
Compared to previous year
awesome-ajv-errors pretty-prints ajv errors
It has a gorgeous human-understandable output, predicts human errors and suggests fixes.
awesome-ajv-errors/node
explicitly (if you have e.g. webpack DefinePlugin configured to hack around missing things like process is not defined
), orawesome-ajv-errors/try-styled
which has a promise-based prettify
function (prettifyTryStyled
) or a promise which will eventually resolve to a synchronous function (styledPrettify
).@babel/code-frame
failed. This will likely be entirely resolved once Babel 8 is released; then awesome output will by default work in browsers too.awesome-ajv-errors
for auto-detecting node vs browserawesome-ajv-errors/dist/index-node.js
or awesome-ajv-errors/dist/index-browser.js
for explicit importing depending on environmentawesome-ajv-errors/dist/index-try-styled.js
for dynamic trying to load color support (e.g. in browsers)@babel/code-frame
with awesome-code-frame
which uses later versions of upstream dependencies - works out-of-the-box in browsers now.awesome-ajv-errors/plain
explicitly to have colors and code frame output disabled, or use the options to prettify()
to disable per call.Suggest similar properties
schema.json
1{ 2 "title": "Second-level two similar properties", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "type": "object", 7 "properties": { 8 "bar": {}, 9 "bak": {} 10 }, 11 "additionalProperties": false 12 } 13 } 14}
data.json
1{ 2 "foo": { 3 "bar": "42", 4 "baz": "33" 5 } 6}
Suggests multiple valid property names
schema.json
1{ 2 "title": "Second-level three similar properties", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "type": "object", 7 "properties": { 8 "bar": {}, 9 "bak": {}, 10 "bam": {} 11 }, 12 "additionalProperties": false 13 } 14 } 15}
data.json
1{ 2 "foo": { 3 "bar": "42", 4 "baz": "33" 5 } 6}
Suggests the valid value type when mistaken
schema.json
1{ 2 "title": "One option (number to string)", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "anyOf": [ 7 { 8 "type": "string" 9 } 10 ] 11 } 12 } 13}
data.json
1{ 2 "foo": 42 3}
Suggests the valid value type when mistaken
schema.json
1{ 2 "title": "One option (string to number)", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "anyOf": [ 7 { 8 "type": "number" 9 } 10 ] 11 } 12 } 13}
data.json
1{ 2 "foo": "42" 3}
When the type mismatch, and one type is much "better" than the rest (as in probably the right solution), it will be suggested for conversion
schema.json
1{ 2 "title": "Two options", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "anyOf": [ 7 { 8 "type": "string" 9 }, 10 { 11 "type": "boolean" 12 } 13 ] 14 } 15 } 16}
data.json
1{ 2 "foo": 42 3}
schema.json
1{ 2 "title": "Three options", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "anyOf": [ 7 { 8 "type": "string" 9 }, 10 { 11 "type": "boolean" 12 }, 13 { 14 "type": "null" 15 } 16 ] 17 } 18 } 19}
data.json
1{ 2 "foo": 42 3}
schema.json
1{ 2 "title": "2 too few", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "type": "array", 7 "minItems": 3 8 } 9 } 10}
data.json
1{ 2 "foo": [ 3 1 4 ] 5}
schema.json
1{ 2 "title": "Less than or equal to", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "type": "number", 7 "maximum": 17 8 } 9 } 10}
data.json
1{ 2 "foo": 42 3}
schema.json
1{ 2 "title": "One value of same type", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "enum": [ 7 41 8 ] 9 } 10 } 11}
data.json
1{ 2 "foo": 42 3}
schema.json
1{ 2 "title": "Two options (one of different type)", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "enum": [ 7 41, 8 "42" 9 ] 10 } 11 } 12}
data.json
1{ 2 "foo": 42 3}
schema.json
1{ 2 "title": "Four options (one of different type)", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "enum": [ 7 "falso", 8 "other", 9 "False", 10 false 11 ] 12 } 13 } 14}
data.json
1{ 2 "foo": "false" 3}
schema.json
1{ 2 "title": "time invalid", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "type": "string", 7 "format": "time" 8 } 9 } 10}
data.json
1{ 2 "foo": "11:22:334" 3}
schema.json
1{ 2 "title": "email invalid", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "type": "string", 7 "format": "email" 8 } 9 } 10}
data.json
1{ 2 "foo": "quite@invalid@email.com" 3}
schema.json
1{ 2 "title": "if-then on first-level object", 3 "properties": { 4 "foo": { 5 "if": { 6 "properties": { 7 "firstName": { 8 "const": true 9 } 10 } 11 }, 12 "then": { 13 "required": [ 14 "lastName" 15 ] 16 } 17 } 18 } 19}
data.json
1{ 2 "foo": { 3 "firstName": true 4 } 5}
schema.json
1{ 2 "title": "Multiple of", 3 "type": "object", 4 "properties": { 5 "foo": { 6 "type": "number", 7 "multipleOf": 4 8 } 9 } 10}
data.json
1{ 2 "foo": 17 3}
schema.json
1{ 2 "title": "Root-level required", 3 "type": "object", 4 "properties": { 5 "foo": {} 6 }, 7 "required": [ 8 "foo" 9 ] 10}
data.json
1{ 2 "bar": 42 3}
Import the ajv
package, and prettify
from awesome-ajv-errors
:
1import * as Ajv from 'ajv' 2import { prettify } from 'awesome-ajv-errors'
Create an ajv instance and validate objects:
1const ajv = new Ajv( { allErrors: true } ); // allErrors is optional 2 3let data, schema; // Get the JSON schema and the JSON data from somewhere 4 5const validate = ajv.compile( schema ); 6validate( data );
Now, the validation error is stored on the validate
function. Use prettify
to pretty-print the errors, and provide the data so that awesome-ajv-errors can suggest fixes:
1console.log( prettify( validate, { data } ) );
Instead of auto-detecting based on the platform (Node.js or a browser), you can turn on/off colors, location printing (the json-snippet of the error) and whether to print big ascii numbers to the left of each error, if there are more than one error.
With the options object containing data
provided to prettify
you can include colors
, location
and bigNumbers
as booleans, to override the defaults.
Turning colors explicitly on will only enable colors if it's detected to be supported by the platform, but turning them off will always output non-colored text.
Turning location on will also only enable the location printing if colors are detected to be supported by the underlying platform (this is a limitation in the current @babel/code-frame
and will likely be resolved in Babel 8).
bigNumbers
will only be enabled if location printing is enabled, but can be explicitly turned off.
Example:
1const colors = false; 2const location = false; 3const explanation = prettify( validate, { data, colors, location } );
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/27 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
12 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More