@typescript-package/length
Version:
A lightweight TypeScript library for the length.
92 lines (91 loc) • 3.73 kB
TypeScript
import { LengthOptions, LengthSettings } from '@typedly/length';
/**
* @description Represents a length value with optional minimum and maximum constraints.
* @export
* @class Length
* @template {number | undefined} [Value=number | undefined] The type of the length value, which can be a number or undefined.
* @template {number | undefined} [Min=number | undefined] The type of the minimum length value, which can be a number or undefined.
* @template {number | undefined} [Max=number | undefined] The type of the maximum length value, which can be a number or undefined.
*/
export declare class Length<Value extends number | undefined = number | undefined, Min extends number | undefined = number | undefined, Max extends number | undefined = number | undefined> {
#private;
/**
* @description The length value of generic type variable `Value`.
* @public
* @readonly
* @type {Value }
*/
get length(): Value;
/**
* @description The maximum length value of generic type variable `Max`.
* @public
* @readonly
* @type {Max}
*/
get max(): Max;
/**
* @description The minimum length value of generic type variable `Min`.
* @public
* @readonly
* @type {Min}
*/
get min(): Min;
/**
* @description The configuration object containing the length, minimum, and maximum values.
* @public
* @readonly
* @type {LengthSettings<Value, Min, Max>}
*/
get config(): LengthSettings<Value, Min, Max>;
/**
* Creates an instance of `Length`.
* @constructor
* @param {?(Value | LengthOptions<Value, Min, Max>)} [length] The initial length value, which can be a number or an object containing min, max, and value properties.
*/
constructor(length?: Value | LengthOptions<Value, Min, Max>);
/**
* @description Checks whether the length is valid based on the defined minimum and maximum constraints.
* @public
* @returns {boolean} Returns the true if the length is valid, otherwise false.
*/
isValid(): boolean;
/**
* @description Sets the length, minimum, and maximum values.
* @public
* @param {LengthOptions<Value, Min, Max>} [param0={}]
* @param {LengthOptions<Value, Min, Max>} param0.max Optional maximum length value.
* @param {LengthOptions<Value, Min, Max>} param0.min Optional minimum length value.
* @param {LengthOptions<Value, Min, Max>} param0.value Optional length value.
* @returns {this} The current instance of Length.
*/
set({ max, min, value }?: LengthOptions<Value, Min, Max>): this;
/**
* @description Sets the length value.
* @public
* @param {(Value | undefined)} value The length value to set.
* @returns {this} The current instance of Length.
*/
setLength(value: Value | undefined): this;
/**
* @description Sets the maximum length value.
* @public
* @param {(Max | undefined)} max The maximum length value to set.
* @returns {this} The current instance of Length.
*/
setMax(max: Max | undefined): this;
/**
* @description Sets the minimum length value.
* @public
* @param {(Min | undefined)} min The minimum length value to set.
* @returns {this} The current instance of Length.
*/
setMin(min: Min | undefined): this;
/**
* @description Sets both the minimum and maximum length values.
* @public
* @param {Min | undefined} min The minimum length value to set.
* @param {Max | undefined} max The maximum length value to set.
* @returns {this} The current instance of Length.
*/
setMinMax(min: Min | undefined, max: Max | undefined): this;
}