@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
269 lines (268 loc) • 10.4 kB
TypeScript
export * from "./boolean";
export * from "./string";
export * from "./numeric";
/**
* @decorator IsNumberLessThanOrEquals
*
* Validator rule that checks if a number is less than or equal to a specified value.
*
* ### Example Usage:
* ```typescript
* class MyClass {
* @IsNumberLessThanOrEquals([5])
* myNumber: number;
* }
* ```
*/
export declare const IsNumberLessThanOrEquals: (ruleParameters: [param: number]) => PropertyDecorator;
/**
* @decorator IsNumberLessThan
*
* 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 {
* @IsNumberLessThan([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 IsNumberLessThan: (ruleParameters: [param: number]) => PropertyDecorator;
/**
* @decorator IsNumberGreaterThanOrEquals
*
* 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 {
* @IsNumberGreaterThanOrEquals([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 IsNumberGreaterThanOrEquals: (ruleParameters: [param: number]) => PropertyDecorator;
/**
* @decorator IsNumberGreaterThan
*
* 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 {
* @IsNumberGreaterThan([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 IsNumberGreaterThan: (ruleParameters: [param: number]) => PropertyDecorator;
/**
* @decorator IsNumberEquals
*
* 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 {
* @IsNumberEquals([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 IsNumberEquals: (ruleParameters: [param: number]) => PropertyDecorator;
/**
* @decorator IsNumberIsDifferentFrom
*
* 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.
*
* ### Example Usage:
* ```typescript
* class MyClass {
* @IsNumberIsDifferentFrom([10])
* myNumber: number;
* }
* ```
*/
export declare const IsNumberIsDifferentFrom: (ruleParameters: [param: number]) => PropertyDecorator;
/**
* @decorator HasLength
*
* 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 {
* @HasLength([3, 10]) //"This field must be between 3 and 10 characters long"
* myString: string;
* }
*
* class MyClass {
* @HasLength([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 HasLength: (ruleParameters: [minOrLength: number, maxLength?: number | undefined]) => PropertyDecorator;
/**
* @decorator HasMinLength
*
* 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 {
* @HasMinLength([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 HasMinLength: (ruleParameters: [minLength: string]) => PropertyDecorator;
/**
* @decorator HasMaxLength
*
* 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 { HasMaxLength } from '@resk/core';
class MyClass {
@HasMaxLength([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 HasMaxLength: (ruleParameters: [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 {
* @IsPhoneNumber
* phoneNumber: string;
* }
* ```
*/
export declare const IsPhoneNumber: 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 {
* @IsEmailOrPhoneNumber
* emailOrPhoneNumber : string;
* }
* ```
*/
export declare const IsEmailOrPhoneNumber: PropertyDecorator;