Skip to content

Commit

Permalink
doc: Change examples to use named exports
Browse files Browse the repository at this point in the history
  • Loading branch information
cj-christoph-gysin committed Dec 7, 2023
1 parent 88bae6e commit fb6f379
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ In JavaScript:

```javascript
// or ESM/TypeScript import
import Ajv from "ajv"
import { Ajv } from "ajv"
// Node.js require:
const Ajv = require("ajv")
const Ajv } = require("ajv")

const ajv = new Ajv() // options can be passed, e.g. {allErrors: true}

Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Properties not defined in the schema will not be included in serialized JSON, un
If you use JTD with typescript, the type for the schema can be derived from the data type, and generated serializer would only accept correct data type in this case:

```typescript
import Ajv, {JTDSchemaType} from "ajv/dist/jtd"
import {Ajv, JTDSchemaType} from "ajv/dist/jtd"
const ajv = new Ajv()

interface MyData {
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/combining-schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ const strictTreeSchema = {
unevaluatedProperties: false,
}

import Ajv2019 from "ajv/dist/2019"
// const Ajv2019 = require("ajv/dist/2019")
import {Ajv2019} from "ajv/dist/2019"
// const {Ajv2019} = require("ajv/dist/2019")
const ajv = new Ajv2019({
schemas: [treeSchema, strictTreeSchema],
})
Expand Down
8 changes: 4 additions & 4 deletions docs/guide/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To add all formats from this plugin:
<code-group>
<code-block title="JavaScript">
```javascript
const Ajv = require("ajv")
const {Ajv} = require("ajv")
const addFormats = require("ajv-formats")

const ajv = new Ajv()
Expand All @@ -19,7 +19,7 @@ addFormats(ajv)

<code-block title="TypeScript">
```typescript
import Ajv from "ajv"
import {Ajv} from "ajv"
import addFormats from "ajv-formats"

const ajv = new Ajv()
Expand Down Expand Up @@ -91,14 +91,14 @@ If you define your own formats, for standalone code generation to work you need
<code-group>
<code-block title="JavaScript">
```javascript
const {default: Ajv, _} = require("ajv")
const {Ajv, _} = require("ajv")
const ajv = new Ajv({code: {formats: _`require("./my_formats")`}})
```
</code-block>

<code-block title="TypeScript">
```typescript
import Ajv, {_} from "ajv"
import {Ajv, _} from "ajv"
const ajv = new Ajv({code: {formats: _`require("./my_formats")`}})
```
</code-block>
Expand Down
8 changes: 4 additions & 4 deletions docs/guide/managing-schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The simplest approach is to compile all your schemas when the application starts
<code-group>
<code-block title="JavaScript">
```javascript
const Ajv = require("ajv").default
const {Ajv} = require("ajv").default
const schema_user = require("./schema_user.json")
const ajv = new Ajv()
const validate_user = ajv.compile(schema_user)
Expand All @@ -65,7 +65,7 @@ app.post("/user", async (cxt) => {

<code-block title="TypeScript">
```javascript
import Ajv from "ajv"
import {Ajv} from "ajv"
import * as schema_user from "./schema_user.json"
const ajv = new Ajv()
const validate_user = ajv.compile<User>(schema_user)
Expand Down Expand Up @@ -106,7 +106,7 @@ You can load all schemas and add them to Ajv instance in a single `validation` m
<code-group>
<code-block title="validation.js">
```javascript
const Ajv = require("ajv")
const {Ajv} = require("ajv")
const schema_user = require("./schema_user.json")
const schema_document = require("./schema_document.json")
const ajv = exports.ajv = new Ajv()
Expand All @@ -117,7 +117,7 @@ ajv.addSchema(schema_document, "document")

<code-block title="validation.ts">
```typescript
import Ajv from "ajv"
import {Ajv} from "ajv"
import * as schema_user from "./schema_user.json"
import * as schema_document from "./schema_document.json"
export const ajv = new Ajv()
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/schema-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ You can migrate schemas from draft-04 to draft-07 using [ajv-cli](https://github
These are the most widely used versions of JSON Schema specification, and they are supported with the main ajv export.

```javascript
import Ajv from "ajv"
import {Ajv} from "ajv"
const ajv = new Ajv()
```

Expand All @@ -55,7 +55,7 @@ The main advantage of this JSON Schema version over draft-07 is the ability to s
To use Ajv with the support of all JSON Schema draft-2019-09/2020-12 features you need to use a different export:

```javascript
import Ajv2019 from "ajv/dist/2019"
import {Ajv2019} from "ajv/dist/2019"
const ajv = new Ajv2019()
```

Expand Down
10 changes: 5 additions & 5 deletions docs/guide/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ For the same example as in [Getting started](./getting-started):
<code-group>
<code-block title="JSON Schema">
```typescript
import Ajv, {JSONSchemaType} from "ajv"
import {Ajv, JSONSchemaType} from "ajv"
const ajv = new Ajv()

interface MyData {
Expand Down Expand Up @@ -61,7 +61,7 @@ if (validate(data)) {

<code-block title="JSON Type Definition">
```typescript
import Ajv, {JTDSchemaType} from "ajv/dist/jtd"
import {Ajv, JTDSchemaType} from "ajv/dist/jtd"
const ajv = new Ajv()

interface MyData {
Expand Down Expand Up @@ -110,7 +110,7 @@ You can use JTD schema to construct the type of data using utility type `JTDData
<code-group>
<code-block title="JSON Type Definition">
```typescript
import Ajv, {JTDDataType} from "ajv/dist/jtd"
import {Ajv, JTDDataType} from "ajv/dist/jtd"
const ajv = new Ajv()

const schema = {
Expand Down Expand Up @@ -214,7 +214,7 @@ This example uses the same data and schema types as above:
<code-group>
<code-block title="JSON Type Definition">
```typescript
import Ajv, {JTDSchemaType} from "ajv/dist/jtd"
import {Ajv, JTDSchemaType} from "ajv/dist/jtd"
const ajv = new Ajv()

interface MyData {
Expand Down Expand Up @@ -290,7 +290,7 @@ Here's a more detailed example showing several union types:
<code-group>
<code-block title="JSON Schema">
```typescript
import Ajv, {JSONSchemaType} from "ajv"
import {Ajv, JSONSchemaType} from "ajv"
const ajv = new Ajv()

type MyUnion = {prop: boolean} | string | number
Expand Down
20 changes: 10 additions & 10 deletions docs/json-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ This version is provided as default export:
<code-group>
<code-block title="JavaScript">
```javascript
const Ajv = require("ajv")
const {Ajv} = require("ajv")
const ajv = new Ajv()
```
</code-block>

<code-block title="TypeScript">
```typescript
import Ajv from "ajv"
import {Ajv} from "ajv"
const ajv = new Ajv()
```
</code-block>
Expand All @@ -48,14 +48,14 @@ To use draft-2019-09 schemas you need to import a different Ajv class:
<code-group>
<code-block title="JavaScript">
```javascript
const Ajv2019 = require("ajv/dist/2019")
const {Ajv2019} = require("ajv/dist/2019")
const ajv = new Ajv2019()
```
</code-block>

<code-block title="TypeScript">
```typescript
import Ajv2019 from "ajv/dist/2019"
import {Ajv2019} from "ajv/dist/2019"
const ajv = new Ajv2019()
```
</code-block>
Expand Down Expand Up @@ -96,14 +96,14 @@ To use draft-2020-12 schemas you need to import a different Ajv class:
<code-group>
<code-block title="JavaScript">
```javascript
const Ajv2020 = require("ajv/dist/2020")
const {Ajv2020} = require("ajv/dist/2020")
const ajv = new Ajv2020()
```
</code-block>

<code-block title="TypeScript">
```typescript
import Ajv2020 from "ajv/dist/2020"
import {Ajv2020} from "ajv/dist/2020"
const ajv = new Ajv2020()
```
</code-block>
Expand All @@ -116,7 +116,7 @@ You can use JSON Schema draft-06 schemas with Ajv v7/8. If your schemas use `$sc
<code-group>
<code-block title="JavaScript">
```javascript
const Ajv = require("ajv")
const {Ajv} = require("ajv")
const draft6MetaSchema = require("ajv/dist/refs/json-schema-draft-06.json")

const ajv = new Ajv()
Expand All @@ -126,7 +126,7 @@ ajv.addMetaSchema(draft6MetaSchema)

<code-block title="TypeScript">
```typescript
import Ajv from "ajv"
import {Ajv} from "ajv"
import * as draft6MetaSchema from "ajv/dist/refs/json-schema-draft-06.json"

const ajv = new Ajv()
Expand All @@ -142,14 +142,14 @@ You can use JSON Schema draft-04 schemas with Ajv from v8.5.0 and the additional
<code-group>
<code-block title="JavaScript">
```javascript
const Ajv = require("ajv-draft-04")
const {Ajv} = require("ajv-draft-04")
const ajv = new Ajv()
```
</code-block>

<code-block title="TypeScript">
```typescript
import Ajv from "ajv-draft-04"
import {Ajv} from "ajv-draft-04"
const ajv = new Ajv()
```
</code-block>
Expand Down
4 changes: 2 additions & 2 deletions docs/json-type-definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ To use JTD schemas you need to import a different Ajv class:
<code-group>
<code-block title="JavaScript">
```javascript
const Ajv = require("ajv/dist/jtd")
const {Ajv} = require("ajv/dist/jtd")
const ajv = new Ajv()
```
</code-block>

<code-block title="TypeScript">
```typescript
import Ajv from "ajv/dist/jtd"
import {Ajv} from "ajv/dist/jtd"
const ajv = new Ajv()
```
</code-block>
Expand Down
8 changes: 4 additions & 4 deletions docs/standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ npm install ajv
```javascript
const fs = require("fs")
const path = require("path")
const Ajv = require("ajv")
const {Ajv} = require("ajv")
const standaloneCode = require("ajv/dist/standalone").default

const schema = {
Expand Down Expand Up @@ -72,7 +72,7 @@ fs.writeFileSync(path.join(__dirname, "../consume/validate-cjs.js"), moduleCode)
```javascript
const fs = require("fs")
const path = require("path")
const Ajv = require("ajv")
const {Ajv} = require("ajv")
const standaloneCode = require("ajv/dist/standalone").default

const schemaFoo = {
Expand Down Expand Up @@ -107,7 +107,7 @@ fs.writeFileSync(path.join(__dirname, "../consume/validate-cjs.js"), moduleCode)
```javascript
const fs = require("fs")
const path = require("path")
const Ajv = require("ajv")
const {Ajv} = require("ajv")
const standaloneCode = require("ajv/dist/standalone").default

const schemaFoo = {
Expand Down Expand Up @@ -243,7 +243,7 @@ To support standalone code generation:

```javascript
import myFormats from "./my-formats"
import Ajv, {_} from "ajv"
import {Ajv, _} from "ajv"
const ajv = new Ajv({
formats: myFormats,
code: {
Expand Down

0 comments on commit fb6f379

Please sign in to comment.