@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
82 lines (81 loc) • 2.36 kB
TypeScript
/**
* ### IsBoolean Rule
*
* Validates that the field under validation can be cast as a Boolean.
* This rule accepts true, false, 1, 0, "1", and "0" as valid Boolean values.
*
* #### Valid boolean Values
* - `true` and `false` (Boolean)
* - `1` and `0` (number)
* - `"1"` and `"0"` (string)
* - `"true"` and `"false"` (case-insensitive string)
*
* @example
* ```typescript
* // With class validation
* class UserPreferences {
* @IsBoolean
* emailNotifications: Boolean;
*
* @IsBoolean
* darkMode: string; // Can be "true"/"false"
* }
* ```
*
* @param options - Validation options containing value and context
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
export declare const IsBoolean: PropertyDecorator;
declare module "../types" {
interface IValidatorRulesMap<Context = unknown> {
/**
* ### Boolean Rule
*
* Validates that the field under validation can be cast as a Boolean.
* This rule accepts true, false, 1, 0, "1", and "0" as valid Boolean values.
*
* #### Valid boolean Values
* - `true` and `false` (Boolean)
* - `1` and `0` (number)
* - `"1"` and `"0"` (string)
* - `"true"` and `"false"` (case-insensitive string)
*
* @example
* ```typescript
* // Valid boolean values
* await Validator.validate({
* value: true,
* rules: ['Boolean']
* }); // ✓ Valid
*
* await Validator.validate({
* value: 0,
* rules: ['Boolean']
* }); // ✓ Valid
*
* await Validator.validate({
* value: 'false',
* rules: ['Boolean']
* }); // ✓ Valid
*
* // Invalid values
* await Validator.validate({
* value: 'maybe',
* rules: ['Boolean']
* }); // ✗ Invalid
*
* // With class validation
* ```
*
* @param options - Validation options containing value and context
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
Boolean: IValidatorRuleParams<[], Context>;
}
}