docschema
Version:
Schema declaration and validation library using JsDoc comments
52 lines (51 loc) • 1.29 kB
TypeScript
/**
* @param {number} levels
* @returns {void}
*/
export function shiftStack(levels: number): void;
/**
* @template SCHEMA
*/
export class DocSchema<SCHEMA> {
/**
* @param {SCHEMA} [typeCarrier]
*/
constructor(typeCarrier?: SCHEMA);
/**
* @returns {CheckResult}
*/
get lastError(): CheckResult;
/**
* @returns {Ast | null}
*/
get ast(): Ast | null;
/**
* Check and return either true or false
*
* @param {any} value
* @returns {boolean}
* @throws {Error} If the schema has not been created yet
*/
approves(value: any): boolean;
/**
* Check and return an object with information about the check
*
* @param {any} value
* @returns {CheckResult}
* @throws {Error} If the schema has not been created yet
*/
check(value: any): CheckResult;
/**
* Check and throw an error if the input value is invalid,
* otherwise return it
*
* @template T
* @param {T} value
* @returns {T extends SCHEMA ? SCHEMA : SCHEMA}
* @throws {ValidationError | Error}
* If the schema has not been created yet, or if the
* validation is not successful
*/
validate<T>(value: T): T extends SCHEMA ? SCHEMA : SCHEMA;
#private;
}