@resk/core
Version:
An innovative TypeScript framework that empowers developers to build applications with a fully decorator-based architecture for efficient resource management. By combining the power of decorators with a resource-oriented design, DecorRes enhances code cla
285 lines (284 loc) • 11.5 kB
TypeScript
/**
* @decorator ValidatorIsNumberLestThanOrEquals
*
* Validator rule that checks if a number is less than or equal to a specified value.
*
* ### Parameters:
* - **options**: `IValidatorValidateOptions` - Contains the value to validate and the rule parameters.
*
* ### Return Value:
* - `IValidatorResult`: Resolves to `true` if the value is less than or equal to the specified value, otherwise rejects with an error message.
*
* ### Example Usage:
* ```typescript
* class MyClass {
* @ValidatorIsNumberLestThanOrEquals([5])
* myNumber: number;
* }
* ```
*/
export declare const ValidatorIsNumberLestThanOrEquals: (params: [param: number]) => PropertyDecorator;
/**
* @decorator ValidatorIsNumberLessThan
*
* Validator rule that checks if a given number is less than a specified value.
* This rule utilizes the `compareNumer` function to perform the comparison and return the result.
*
* ### Parameters:
* - **options**: `IValidatorValidateOptions` - An object containing:
* - `value`: The number to validate.
* - `ruleParams`: An array where the first element is the value to compare against.
*
* ### Return Value:
* - `IValidatorResult`: Resolves to `true` if the value is less than the specified comparison value,
* otherwise rejects with an error message indicating the validation failure.
*
* ### Example Usage:
* ```typescript
* class MyClass {
* @ValidatorIsNumberLessThan([10])
* myNumber: number;
* }
* ```
*
* ### Notes:
* - This rule is useful for scenarios where you need to ensure that a numeric input is strictly less than a specified limit.
* - The error message can be customized by modifying the second parameter of the `compareNumer` function.
*/
export declare const ValidatorIsNumberLessThan: (params: [param: number]) => PropertyDecorator;
/**
* @decorator ValidatorIsNumberGreaterThanOrEquals
*
* Validator rule that checks if a given number is greater than or equal to a specified value.
* This rule utilizes the `compareNumer` function to perform the comparison and return the result.
*
* ### Parameters:
* - **options**: `IValidatorValidateOptions` - An object containing:
* - `value`: The number to validate.
* - `ruleParams`: An array where the first element is the value to compare against.
*
* ### Return Value:
* - `IValidatorResult`: Resolves to `true` if the value is greater than or equal to the specified comparison value,
* otherwise rejects with an error message indicating the validation failure.
*
* ### Example Usage:
* ```typescript
* class MyClass {
* @ValidatorIsNumberGreaterThanOrEquals([5])
* myNumber: number;
* }
* ```
*
* ### Notes:
* - This rule is useful for scenarios where you need to ensure that a numeric input meets or exceeds a specified limit.
* - The error message can be customized by modifying the second parameter of the `compareNumer` function.
*/
export declare const ValidatorIsNumberGreaterThanOrEquals: (params: [param: number]) => PropertyDecorator;
/**
* @decorator ValidatorIsNumberGreaterThan
*
* Validator rule that checks if a given number is greater than a specified value.
* This rule utilizes the `compareNumer` function to perform the comparison and return the result.
*
* ### Parameters:
* - **options**: `IValidatorValidateOptions` - An object containing:
* - `value`: The number to validate.
* - `ruleParams`: An array where the first element is the value to compare against.
*
* ### Return Value:
* - `IValidatorResult`: Resolves to `true` if the value is greater than the specified comparison value,
* otherwise rejects with an error message indicating the validation failure.
*
* ### Example Usage:
* ```typescript
* class MyClass {
* @ValidatorIsNumberGreaterThan([10])
* myNumber: number;
* }
* ```
*
* ### Notes:
* - This rule is useful for scenarios where you need to ensure that a numeric input exceeds a specified limit.
* - The error message can be customized by modifying the second parameter of the `compareNumer` function.
*/
export declare const ValidatorIsNumberGreaterThan: (params: [param: number]) => PropertyDecorator;
/**
* @decorator ValidatorIsNumberEquals
*
* Validator rule that checks if a given number is equal to a specified value.
* This rule utilizes the `compareNumer` function to perform the comparison and return the result.
*
* ### Parameters:
* - **options**: `IValidatorValidateOptions` - An object containing:
* - `value`: The number to validate.
* - `ruleParams`: An array where the first element is the value to compare against.
*
* ### Return Value:
* - `IValidatorResult`: Resolves to `true` if the value is equal to the specified comparison value,
* otherwise rejects with an error message indicating the validation failure.
*
* ### Example Usage:
* ```typescript
* class MyClass {
* @ValidatorIsNumberEquals([10])
* myNumber: number;
* }
* ```
*
* ### Notes:
* - This rule is useful for scenarios where you need to ensure that a numeric input matches a specified value exactly.
* - The error message can be customized by modifying the second parameter of the `compareNumer` function.
*/
export declare const ValidatorIsNumberEquals: (params: [param: number]) => PropertyDecorator;
/**
* @decorator ValidatorNumberIsDifferentFrom
*
* Validator rule that checks if a given number is not equal to a specified value.
* This rule utilizes the `compareNumer` function to perform the comparison and return the result.
*
* ### Parameters:
* - **options**: `IValidatorValidateOptions` - An object containing:
* - `value`: The number to validate.
* - `ruleParams`: An array where the first element is the value to compare against.
*
* ### Return Value:
* - `IValidatorResult`: Resolves to `true` if the value is not equal to the specified comparison value,
* otherwise rejects with an error message indicating the validation failure.
*
* ### Example Usage:
* ```typescript
* class MyClass {
* @ValidatorNumberIsDifferentFrom([10])
* myNumber: number;
* }
* ```
*
* ### Notes:
* - This rule is useful for scenarios where you need to ensure that a numeric input does not match a specified value.
* - The error message can be customized by modifying the second parameter of the `compareNumer` function.
*/
export declare const ValidatorNumberIsDifferentFrom: (params: [param: number]) => PropertyDecorator;
/**
* @decorator ValidatorHasLength
*
* Validator rule that validates the length of a string. This rule checks if the length of the input string
* falls within a specified range or matches a specific length.
*
* ### Parameters:
* - **options**: `IValidatorValidateOptions` - An object containing:
* - `value`: The string value to validate.
* - `ruleParams`: An array where:
* - The first element specifies the minimum length (optional).
* - The second element specifies the maximum length (optional).
*
* ### Return Value:
* - `boolean | string`: Returns `true` if the string length is valid according to the specified rules;
* otherwise, returns an error message indicating the validation failure.
*
* ### Example Usage:
* ```typescript
*
* class MyClass {
* @ValidatorHasLength([3, 10]) //"This field must be between 3 and 10 characters long"
* myString: string;
* }
*
* class MyClass {
* @ValidatorHasLength([4]) //"This field must be exactly 4 characters long"
* myString: string;
* }
* ```
*
* ### Notes:
* - This rule is useful for validating user input in forms, ensuring that the input meets specific length requirements.
* - The error messages can be customized based on the parameters provided, allowing for clear feedback to users.
* - The `defaultStr` utility function is used to ensure that the value is treated as a string, even if it is `null` or `undefined`.
*/
export declare const ValidatorHasLength: (params: [minOrLength: number, maxLength?: number | undefined]) => PropertyDecorator;
/**
* @decorator ValidatorHasMinLength
*
* Validator rule that checks if a given string meets a minimum length requirement.
* This rule ensures that the input string has at least the specified number of characters.
*
* ### Parameters:
* - **options**: `IValidatorValidateOptions` - An object containing:
* - `value`: The string value to validate.
* - `ruleParams`: An array where the first element specifies the minimum length required.
*
* ### Return Value:
* - `boolean | string`: Returns `true` if the value is empty or meets the minimum length requirement;
* otherwise, returns an error message indicating that the minimum length is not met.
*
* ### Example Usage:
* ```typescript
* class MyClass {
* @ValidatorHasMinLength([3]) //"This field must have a minimum of 3 characters"
* myString: string;
* }
* ```
*
* ### Notes:
* - This rule is useful for validating user input in forms, ensuring that the input meets a minimum length requirement.
* - The error message can be customized based on the parameters provided, allowing for clear feedback to users.
* - The `isEmpty` utility function is used to check for empty values, which may include `null`, `undefined`, or empty strings.
*/
export declare const ValidatorHasMinLength: (params: [minLength: string]) => PropertyDecorator;
/**
* @decorator ValidatorHasMaxLength
*
* Validator rule that checks if a given string does not exceed a maximum length.
* This rule ensures that the input string has at most the specified number of characters.
*
* ### Parameters:
* - **options**: `IValidatorValidateOptions` - An object containing:
* - `value`: The string value to validate.
* - `ruleParams`: An array where the first element specifies the maximum length allowed.
*
* ### Return Value:
* - `boolean | string`: Returns `true` if the value is empty or meets the maximum length requirement;
* otherwise, returns an error message indicating that the maximum length is exceeded.
*
* ### Example Usage:
* ```typescript
import { ValidatorHasMaxLength } from '@resk/core';
class MyClass {
@ValidatorHasMaxLength([10])
myProperty: string;
}
* ```
*
* ### Notes:
* - This rule is useful for validating user input in forms, ensuring that the input does not exceed a specified length.
* - The error message can be customized based on the parameters provided, allowing for clear feedback to users.
* - The `isEmpty` utility function is used to check for empty values, which may include `null`, `undefined`, or empty strings.
*/
export declare const ValidatorHasMaxLength: (params: [maxLength: number]) => PropertyDecorator;
/**
* A validator decorator to check if a phone number is valid.
*
* @param phoneNumber The phone number to validate.
* @returns A validator decorator that checks if the phone number is valid.
* @example
* ```typescript
* class User {
* @ValidatorIsPhoneNumber
* phoneNumber: string;
* }
* ```
*/
export declare const ValidatorIsPhoneNumber: PropertyDecorator;
/**
* A validator decorator to check if value is a valid email or phone number.
*
* @param value The email or phone number to validate.
* @returns A validator decorator that checks if the email or phone number is valid.
* @example
* ```typescript
* class User {
* @ValidatorIsEmailOrPhoneNumber
* emailOrPhoneNumber : string;
* }
* ```
*/
export declare const ValidatorIsEmailOrPhoneNumber: PropertyDecorator;