Skip to content

Commit

Permalink
fix: typescript and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Oct 14, 2019
1 parent 0d12259 commit d38f223
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
31 changes: 20 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import {JSONSchema4, JSONSchema6, JSONSchema7} from 'json-schema';
import {ErrorObject} from 'ajv';
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<ErrorObject>, schema: Schema, configuration?: Partial<ValidateErrorConfiguration>);
class ValidationError extends Error {
constructor(
errors: Array<ErrorObject>,
schema: Schema,
configuration?: Partial<ValidationErrorConfiguration>
);

name: string;
errors: Array<ErrorObject>;
Expand All @@ -17,16 +21,21 @@ declare namespace SchemaUtils {
message: string;
}

interface ValidateErrorConfiguration {
name: string,
baseDataPath: string,
postFormatter: PostFormatter
interface ValidationErrorConfiguration {
name: string;
baseDataPath: string;
postFormatter: PostFormatter;
}
}

declare var validate: {
(schema: Schema, options: Array<object> | object, configuration?: Partial<SchemaUtils.ValidateErrorConfiguration>): void;
ValidateError: typeof SchemaUtils.ValidateError
}
(
schema: Schema,
options: Array<object> | object,
configuration?: Partial<SchemaUtils.ValidationErrorConfiguration>
): void;
ValidateError: typeof SchemaUtils.ValidationError;
ValidationError: typeof SchemaUtils.ValidationError;
};

export = validate;
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const validate = require('./validate');
const validateError = require('./ValidationError');
const ValidationError = require('./ValidationError');

module.exports = validate.default;
module.exports.ValidateError = validateError.default;
module.exports.ValidationError = ValidationError.default;

// Todo remove this in next major release
module.exports.ValidateError = ValidationError.default;
1 change: 1 addition & 0 deletions test/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('api', () => {
it('should export validate and ValidateError', () => {
expect(typeof schemaUtils).toBe('function');
expect(typeof schemaUtils.ValidateError).toBe('function');
expect(typeof schemaUtils.ValidationError).toBe('function');
});

it('should work', () => {
Expand Down

0 comments on commit d38f223

Please sign in to comment.