diff --git a/README.md b/README.md index 615f33e..fda832a 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,8 @@ Schema generated: ## TypeScript +### CommonJS + With `"esModuleInterop": true` activated in the `tsconfig.json`: ```typescript @@ -153,6 +155,19 @@ const schema = S.object() .valueOf() ``` +### ESM + +A named export is also available to work with native ESM modules: + +```typescript +import { S } from 'fluent-json-schema' + +const schema = S.object() + .prop('foo', S.string()) + .prop('bar', S.number()) + .valueOf() +``` + ## Validation Fluent schema **does not** validate a JSON schema. However, many libraries can do that for you. diff --git a/src/FluentJSONSchema.js b/src/FluentJSONSchema.js index feefeba..326e40c 100644 --- a/src/FluentJSONSchema.js +++ b/src/FluentJSONSchema.js @@ -199,3 +199,4 @@ const fluentSchema = { } module.exports = fluentSchema module.exports.default = fluentSchema +module.exports.S = fluentSchema diff --git a/types/FluentJSONSchema.d.ts b/types/FluentJSONSchema.d.ts index fba1db0..0f40a09 100644 --- a/types/FluentJSONSchema.d.ts +++ b/types/FluentJSONSchema.d.ts @@ -256,5 +256,6 @@ export interface S extends BaseSchema { FORMATS: FORMATS } -declare var s: S -export default s +export declare var S: S + +export default S