mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
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:
parent
25fe77861d
commit
82eebd3e0c
18
types/ajv-pack/ajv-pack-tests.ts
Normal file
18
types/ajv-pack/ajv-pack-tests.ts
Normal 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
45
types/ajv-pack/index.d.ts
vendored
Normal 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;
|
||||
6
types/ajv-pack/package.json
Normal file
6
types/ajv-pack/package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"ajv": "^5.0.0"
|
||||
}
|
||||
}
|
||||
23
types/ajv-pack/tsconfig.json
Normal file
23
types/ajv-pack/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/ajv-pack/tslint.json
Normal file
1
types/ajv-pack/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user