add ajv-pack typings (#38425)

* add ajv-pack typings

* ajv-pack restructure typings to leverage namespace

* ajv-pack: add newline to tsconfig

* ajv-pack: simplify namespace
This commit is contained in:
Christian Murphy 2019-09-25 09:38:35 -07:00 committed by Ben Lichtman
parent 25fe77861d
commit 82eebd3e0c
5 changed files with 93 additions and 0 deletions

View File

@ -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

45
types/ajv-pack/index.d.ts vendored Normal file
View File

@ -0,0 +1,45 @@
// Type definitions for ajv-pack 0.3
// Project: https://github.com/epoberezkin/ajv-pack
// Definitions by: Mihail Malo <https://github.com/qm3ster>
// Christian Murphy <https://github.com/ChristianMurphy>
// 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;

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"ajv": "^5.0.0"
}
}

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }