From bea39a03609089057a45310e42e6daf862e10a23 Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Wed, 1 May 2019 19:37:09 +0200 Subject: [PATCH] Add types for djv (#35136) --- types/djv/djv-tests.ts | 12 +++++++++ types/djv/index.d.ts | 56 +++++++++++++++++++++++++++++++++++++++++ types/djv/tsconfig.json | 23 +++++++++++++++++ types/djv/tslint.json | 1 + 4 files changed, 92 insertions(+) create mode 100644 types/djv/djv-tests.ts create mode 100644 types/djv/index.d.ts create mode 100644 types/djv/tsconfig.json create mode 100644 types/djv/tslint.json diff --git a/types/djv/djv-tests.ts b/types/djv/djv-tests.ts new file mode 100644 index 0000000000..3b8a65b873 --- /dev/null +++ b/types/djv/djv-tests.ts @@ -0,0 +1,12 @@ +import djv = require('djv'); + +const env = djv({ + version: 'draft-06', + formats: {}, + errorHandler: () => {}, +}); + +new djv({ version: 'draft-04' }); + +env.addSchema('test'); +env.addFormat('uri-reference', () => true); diff --git a/types/djv/index.d.ts b/types/djv/index.d.ts new file mode 100644 index 0000000000..76185b7a52 --- /dev/null +++ b/types/djv/index.d.ts @@ -0,0 +1,56 @@ +// Type definitions for djv 2.1 +// Project: https://github.com/korzio/djv#readme +// Definitions by: Florian Keller +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +interface DjvStatic { + (options?: DjvStatic.DjvConfig): DjvStatic.djv; + new (options?: DjvStatic.DjvConfig): DjvStatic.djv; + expression(strings: string[], ...keys: string[]): (...values: string[]) => string; +} + +declare namespace DjvStatic { + interface DjvConfig { + /** a handler to use for generating custom error messages */ + errorHandler?: () => void; + /** an object containing list of formatters to add for environment */ + formats?: Record string>; + /** + * generating object should be considered as inner + * + * Default value is `false`/`undefined`. If `true`, then it avoid creating variables in a + * generated function body, however without proper wrapper function approach will not work. + */ + inner?: boolean; + /** defines which version of json-schema draft to use, draft-04 by default */ + version?: string; + /** handler to apply for environment version */ + versionConfigure?: (object: object) => void; + } + + interface Resolved { + schema: object; + fn: (...args: any[]) => any; + } + + interface djv { + resolved: Resolved; + + addFormat(name: string, formatter: string | ((schema: object, tpl: any) => void)): void; + + addSchema(nameOrSchema: string | object, schema?: object): Resolved; + + export(name?: string): string; + import(config: object): void; + removeSchema(name: string): void; + resolve(name: string | object): Resolved; + setErrorHandler(errorHandler: (errorType: string, property: any) => string): void; + useVersion(version: string, configure?: any): void; + validate(name: string, object: object): string | undefined; + } +} + +declare const DjvStatic: DjvStatic; + +export = DjvStatic; diff --git a/types/djv/tsconfig.json b/types/djv/tsconfig.json new file mode 100644 index 0000000000..f451cf09db --- /dev/null +++ b/types/djv/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", + "djv-tests.ts" + ] +} diff --git a/types/djv/tslint.json b/types/djv/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/djv/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }