From eab75a191169546c01a766b88ee90f1848012107 Mon Sep 17 00:00:00 2001 From: qm3ster Date: Fri, 24 Aug 2018 02:19:27 +0300 Subject: [PATCH] Add TypeScript typedef --- index.d.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..e0432ab --- /dev/null +++ b/index.d.ts @@ -0,0 +1,43 @@ +import { Ajv, ValidateFunction } from 'ajv' + +interface AjvPack { + /** + * validate data against the schema + * @this Ajv + * @param {Object} schema JSON-schema + * @param {Any} data data to validate + * @return {Boolean} validation result + */ + validate(schema: object, data: any): boolean + + /** + * compile the schema and require the module + * @this Ajv + * @param {Object} schema JSON-schema + * @return {Function} validation function + */ + compile(schema: object): ValidateFunction + + /** + * add schema to the instance + * @this Ajv + * @return {Any} result from ajv instance + */ + addSchema: Ajv['addSchema'] + + /** + * add custom keyword to the instance + * @this Ajv + * @return {Any} result from ajv instance + */ + addKeyword: Ajv['addKeyword'] +} + +interface PackValidate { + (ajv: Ajv, validate: ValidateFunction): string + instance(ajv: Ajv): AjvPack +} + +declare const pack: PackValidate + +export = pack diff --git a/package.json b/package.json index ed37e54..4133970 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "test-debug": "mocha spec/*.spec.js --debug-brk -R spec", "test-spec": "mocha spec/*.spec.js -R spec", "test-cov": "istanbul cover -x '**/spec/**' node_modules/mocha/bin/_mocha -- spec/*.spec.js -R spec", - "prepublish": "npm run build" + "prepare": "npm run build" }, "repository": { "type": "git",