diff --git a/types/ajv-pack/ajv-pack-tests.ts b/types/ajv-pack/ajv-pack-tests.ts new file mode 100644 index 0000000000..75ee87f547 --- /dev/null +++ b/types/ajv-pack/ajv-pack-tests.ts @@ -0,0 +1,18 @@ +import * as Ajv from 'ajv'; +import * as pack from 'ajv-pack'; + +const ajv = new Ajv({ sourceCode: true }); + +const schema = { + type: 'object', + properties: { + foo: { + type: 'string', + pattern: '^[a-z]+$', + }, + }, +}; + +const validate = ajv.compile(schema); +pack(ajv, validate); // $ExpectType string +pack.instance(ajv); // $ExpectType AjvPack diff --git a/types/ajv-pack/index.d.ts b/types/ajv-pack/index.d.ts new file mode 100644 index 0000000000..26cc4f4b95 --- /dev/null +++ b/types/ajv-pack/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for ajv-pack 0.3 +// Project: https://github.com/epoberezkin/ajv-pack +// Definitions by: Mihail Malo +// Christian Murphy +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import { Ajv, ValidateFunction } from 'ajv'; + +declare namespace AjvPack { + interface AjvPack { + /** + * validate data against the schema + * @param schema JSON-schema + * @param data data to validate + * @return validation result + */ + validate(this: Ajv, schema: object, data: any): boolean; + + /** + * compile the schema and require the module + * @param schema JSON-schema + * @return validation function + */ + compile(this: Ajv, schema: object): ValidateFunction; + + /** + * add schema to the instance + * @return result from ajv instance + */ + addSchema: Ajv['addSchema']; + + /** + * add custom keyword to the instance + * @return result from ajv instance + */ + addKeyword: Ajv['addKeyword']; + } + + function instance(ajv: Ajv): AjvPack; +} + +declare function AjvPack(ajv: Ajv, validate: ValidateFunction): string; + +export = AjvPack; diff --git a/types/ajv-pack/package.json b/types/ajv-pack/package.json new file mode 100644 index 0000000000..a11a450ab5 --- /dev/null +++ b/types/ajv-pack/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "ajv": "^5.0.0" + } +} diff --git a/types/ajv-pack/tsconfig.json b/types/ajv-pack/tsconfig.json new file mode 100644 index 0000000000..aead664e55 --- /dev/null +++ b/types/ajv-pack/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ajv-pack-tests.ts" + ] +} diff --git a/types/ajv-pack/tslint.json b/types/ajv-pack/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/ajv-pack/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }