@barchart/common-js
Version:
Library of common JavaScript utilities
72 lines (71 loc) • 3.23 kB
TypeScript
/**
* Utilities checking arguments.
*
* @public
* @module lang/assert
*/
/**
* Throws an error if an argument doesn't conform to the desired specification (as
* determined by a type check).
*
* @static
* @param {*} variable - The value to check.
* @param {string=} variableName - The name of the value (used for formatting an error message).
* @param {*=} type - The expected type of the argument.
* @param {string=} typeDescription - The description of the expected type (used for formatting an error message).
*/
export function argumentIsRequired(variable: any, variableName?: string | undefined, type?: any | undefined, typeDescription?: string | undefined): void;
/**
* A relaxed version of the "argumentIsRequired" function that will not throw if
* the value is undefined or null.
*
* @static
* @param {*} variable - The value to check.
* @param {string=} variableName - The name of the value (used for formatting an error message).
* @param {*=} type - The expected type of the argument.
* @param {string=} typeDescription - The description of the expected type (used for formatting an error message).
* @param {Function=} predicate - A function used to validate the item (beyond type checking).
* @param {string=} predicateDescription - A description of the assertion made by the predicate (e.g. "is an integer") that is used for formatting an error message.
*/
export function argumentIsOptional(variable: any, variableName?: string | undefined, type?: any | undefined, typeDescription?: string | undefined, predicate?: Function | undefined, predicateDescription?: string | undefined): void;
/**
* Throws an error when a value is not an array or its items do not satisfy the supplied constraint.
*
* @public
* @param {*} variable
* @param {*} variableName
* @param {*} itemConstraint
* @param {*} itemConstraintDescription
*/
export function argumentIsArray(variable: any, variableName: any, itemConstraint: any, itemConstraintDescription: any): void;
/**
* Throws an error if an argument doesn't conform to the desired specification
* (as determined by a predicate).
*
* @static
* @param {*} variable - The value to check.
* @param {string=} variableName - The name of the value (used for formatting an error message).
* @param {Function=} predicate - A function used to validate the item (beyond type checking).
* @param {string=} predicateDescription - A description of the assertion made by the predicate (e.g. "is an integer") that is used for formatting an error message.
*/
export function argumentIsValid(variable: any, variableName?: string | undefined, predicate?: Function | undefined, predicateDescription?: string | undefined): void;
/**
* Throws an error when two values are not strictly equal.
*
* @public
* @param {*} a
* @param {*} b
* @param {*=} descriptionA
* @param {*=} descriptionB
*/
export function areEqual(a: any, b: any, descriptionA?: any | undefined, descriptionB?: any | undefined): void;
/**
* Throws an error when two values are strictly equal.
*
* @public
* @param {*} a
* @param {*} b
* @param {*} descriptionA
* @param {*} descriptionB
*/
export function areNotEqual(a: any, b: any, descriptionA: any, descriptionB: any): void;