From 286ca0f08b7c14f2e01d5f5e6199f323f0503238 Mon Sep 17 00:00:00 2001 From: weiran Date: Tue, 22 Dec 2020 11:10:46 +0800 Subject: [PATCH 1/2] docs: add pre-es6 usage (fixes #1364) --- docs/faq.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/faq.md b/docs/faq.md index 25e2213fe..e1811b98d 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -76,6 +76,12 @@ This problem is related to the problem explained above - properties treated as a See the example in [Filtering Data](https://github.com/ajv-validator/ajv#filtering-data) section of readme. +#### Using ajv v7 in ES5 environments + + As of ajv v7, to support pre-ES6 env you will need to: + * recompile Typescript to es5 target - it's set to 2018 in the bundled compiled code. + * generate es5 code `(new Ajv({code:{es5:true}}))`, refs [Advanced options](https://github.com/ajv-validator/ajv/blob/master/docs/api.md#advanced-options). + ## Generating schemas with resolved references (\$ref) See [#22](https://github.com/ajv-validator/ajv/issues/22), [#125](https://github.com/ajv-validator/ajv/issues/125), [#146](https://github.com/ajv-validator/ajv/issues/146), [#228](https://github.com/ajv-validator/ajv/issues/228), [#336](https://github.com/ajv-validator/ajv/issues/336), [#454](https://github.com/ajv-validator/ajv/issues/454). From c44597e3e19f711c1892eea04807ca0c67b11d95 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 2 Jan 2021 10:40:51 +0000 Subject: [PATCH 2/2] docs: move "using in ES5 env" to readme --- README.md | 14 ++++++++++++++ docs/faq.md | 6 ------ lib/vocabularies/applicator/oneOf.ts | 6 +++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ee3c1ab7d..65368f5fe 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ Please review [Contributing guidelines](./CONTRIBUTING.md) and [Code components] - [Frequently Asked Questions](./docs/faq.md) - [Using in browser](#using-in-browser) - [Content Security Policy](./docs/security.md#content-security-policy) +- [Using in ES5 environment](#using-in-es5-environment) - [Command line interface](#command-line-interface) - [API reference](./docs/api.md) - [Methods](./docs/api.md#ajv-constructor-and-methods) @@ -307,6 +308,19 @@ The browser bundle is available on [cdnjs](https://cdnjs.com/libraries/ajv). **Please note**: some frameworks, e.g. Dojo, may redefine global require in a way that is not compatible with CommonJS module format. In this case Ajv bundle has to be loaded before the framework and then you can use global `ajv` (see issue [#234](https://github.com/ajv-validator/ajv/issues/234)). +## Using in ES5 environment + +You need to: + +- recompile Typescript to ES5 target - it is set to 2018 in the bundled compiled code. +- generate ES5 validation code: + +```javascript +const ajv = new Ajv({code: {es5: true}}) +``` + +See [Advanced options](https://github.com/ajv-validator/ajv/blob/master/docs/api.md#advanced-options). + ## Command line interface CLI is available as a separate npm package [ajv-cli](https://github.com/ajv-validator/ajv-cli). It supports: diff --git a/docs/faq.md b/docs/faq.md index e1811b98d..25e2213fe 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -76,12 +76,6 @@ This problem is related to the problem explained above - properties treated as a See the example in [Filtering Data](https://github.com/ajv-validator/ajv#filtering-data) section of readme. -#### Using ajv v7 in ES5 environments - - As of ajv v7, to support pre-ES6 env you will need to: - * recompile Typescript to es5 target - it's set to 2018 in the bundled compiled code. - * generate es5 code `(new Ajv({code:{es5:true}}))`, refs [Advanced options](https://github.com/ajv-validator/ajv/blob/master/docs/api.md#advanced-options). - ## Generating schemas with resolved references (\$ref) See [#22](https://github.com/ajv-validator/ajv/issues/22), [#125](https://github.com/ajv-validator/ajv/issues/125), [#146](https://github.com/ajv-validator/ajv/issues/146), [#228](https://github.com/ajv-validator/ajv/issues/228), [#336](https://github.com/ajv-validator/ajv/issues/336), [#454](https://github.com/ajv-validator/ajv/issues/454). diff --git a/lib/vocabularies/applicator/oneOf.ts b/lib/vocabularies/applicator/oneOf.ts index f34c2dc97..268c2376e 100644 --- a/lib/vocabularies/applicator/oneOf.ts +++ b/lib/vocabularies/applicator/oneOf.ts @@ -9,7 +9,11 @@ import {_, Name} from "../../compile/codegen" import {alwaysValidSchema} from "../../compile/util" import {SchemaCxt} from "../../compile" -export type OneOfError = ErrorObject<"oneOf", {passingSchemas: [number, number] | null}, AnySchema[]> +export type OneOfError = ErrorObject< + "oneOf", + {passingSchemas: [number, number] | null}, + AnySchema[] +> const error: KeywordErrorDefinition = { message: "should match exactly one schema in oneOf",