Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Add TypeScript typedef #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down