Skip to content

Commit

Permalink
📦 better-ajv-errors v1
Browse files Browse the repository at this point in the history
  • Loading branch information
torifat committed Nov 8, 2021
1 parent 233a33b commit 146a859
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
30 changes: 30 additions & 0 deletions .changeset/honest-guests-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
'better-ajv-errors': major
---

:package: better-ajv-errors v1

### Breaking Changes

- Dropped support for Node.js `< 12.13.0`
- Default import in CommonJS format no longer supported

**:no_entry_sign: Wrong**

```js
const betterAjvErrors = require('better-ajv-errors');
```

**:white_check_mark: Correct**

```js
const betterAjvErrors = require('better-ajv-errors').default;
// Or
const { default: betterAjvErrors } = require('better-ajv-errors');
```

### Other Changes
- Added ESM support
- Moved from `babel` to `esbuild` _(99% faster build: from `2170ms` to `20ms`)_
- https://github.com/atlassian/better-ajv-errors/pull/101#issuecomment-963129931
- Bumped all `dependencies` & `devDependencies`
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Main goal of this library is to provide relevant error messages like the followi
## Installation

```bash
$ yarn add better-ajv-errors
$ # Or
$ npm i better-ajv-errors
$ # Or
$ yarn add better-ajv-errors
```

Also make sure that you installed [ajv](https://www.npmjs.com/package/ajv) package to validate data against JSON schemas.
Expand All @@ -29,10 +29,12 @@ First, you need to validate your payload with `ajv`. If it's invalid then you ca
import Ajv from 'ajv';
import betterAjvErrors from 'better-ajv-errors';
// const Ajv = require('ajv');
// const betterAjvErrors = require('better-ajv-errors');
// const betterAjvErrors = require('better-ajv-errors').default;
// Or
// const { default: betterAjvErrors } = require('better-ajv-errors');

// You need to pass `jsonPointers: true`
const ajv = new Ajv({ jsonPointers: true });
// You need to pass `{ jsonPointers: true }` for older versions of ajv
const ajv = new Ajv();

// Load schema and data
const schema = ...;
Expand Down
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
"version": "0.8.2",
"description": "JSON Schema validation for Human",
"repository": "atlassian/better-ajv-errors",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
"main": "./lib/cjs/index.js",
"exports": {
".": {
"require": "./lib/cjs/index.js",
"default": "./lib/esm/index.js"
}
},
"module": "./lib/esm/index.js",
"engines": {
"node": ">= 12.13.0"
},
"keywords": [
"json-schema",
"ajv",
Expand All @@ -17,10 +26,9 @@
"Tong Li"
],
"license": "Apache-2.0",
"typings": "typings.d.ts",
"types": "./typings.d.ts",
"files": [
"lib",
"index.js",
"typings.d.ts"
],
"scripts": {
Expand All @@ -30,10 +38,10 @@
"build:esm": "node build.js",
"prerelease": "npm run build",
"release": "changeset publish",
"format": "prettier --write 'src/**/*.js' '.changeset/*.json'",
"format": "prettier --write './src/**/*.js' './.changeset/*.json'",
"test": "jest",
"test-ci": "jest --coverage --colors",
"screenshot": "svg-term --command='node screenshot' --out=media/screenshot.svg --padding=5 --width=80 --height=13 --at=1000 --no-cursor --term iterm2 --profile='deep' --window",
"screenshot": "svg-term --command='node screenshot' --out=./media/screenshot.svg --padding=5 --width=80 --height=13 --at=1000 --no-cursor --term iterm2 --profile='deep' --window",
"prepare": "husky install"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Ajv = require('ajv');
const schema = require('./src/__fixtures__/default/schema.json');
const data = require('./src/__fixtures__/default/data.json');

const betterAjvErrors = require('./lib/cjs').default;
const betterAjvErrors = require('.').default;

// options can be passed, e.g. {allErrors: true}
// const ajv = new Ajv({ allErrors: true, async: 'es7' });
Expand Down

0 comments on commit 146a859

Please sign in to comment.