diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..86ea372 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,32 @@ +import {JSONSchema4, JSONSchema6, JSONSchema7} from 'json-schema'; +import {ErrorObject} from 'ajv'; + +type Schema = JSONSchema4 | JSONSchema6 | JSONSchema7; +type PostFormatter = (formattedError: string, error: ErrorObject) => string; + +declare namespace SchemaUtils { + class ValidateError extends Error { + constructor(errors: Array, schema: Schema, configuration?: Partial); + + name: string; + errors: Array; + schema: Schema; + headerName: string; + baseDataPath: string; + postFormatter: PostFormatter | null; + message: string; + } + + interface ValidateErrorConfiguration { + name: string, + baseDataPath: string, + postFormatter: PostFormatter + } +} + +declare var validate: { + (schema: Schema, options: Array | object, configuration?: Partial): void; + ValidateError: typeof SchemaUtils.ValidateError +} + +export = validate; diff --git a/package-lock.json b/package-lock.json index 69a47c7..02c31ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1442,6 +1442,12 @@ "@types/istanbul-lib-report": "*" } }, + "@types/json-schema": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.3.tgz", + "integrity": "sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==", + "dev": true + }, "@types/minimatch": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", diff --git a/package.json b/package.json index 8f796ec..956c2bc 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "homepage": "https://github.com/webpack/schema-utils", "bugs": "https://github.com/webpack/schema-utils/issues", "main": "dist/index.js", + "types": "index.d.ts", "engines": { "node": ">= 8.9.0" }, @@ -43,6 +44,7 @@ "@babel/preset-env": "^7.6.2", "@commitlint/cli": "^8.2.0", "@commitlint/config-conventional": "^8.2.0", + "@types/json-schema": "^7.0.3", "@webpack-contrib/defaults": "^5.0.2", "@webpack-contrib/eslint-config-webpack": "^3.0.0", "babel-jest": "^24.9.0",