@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
203 lines (202 loc) • 6.1 kB
TypeScript
/**
* ### EndsWithOneOf Rule
*
* Validates that the field under validation ends with one of the given values.
*
* #### Parameters
* - List of values that the field must end with
*
* @example
* ```typescript
* // Class validation
* class FileUpload {
* @EndsWithOneOf(['jpg', 'png', 'gif', 'webp'])
* imageFile: string;
*
* @EndsWithOneOf(['.com', '.org', '.net'])
* websiteUrl: string;
* }
* ```
*
* @param options - Validation options with rule parameters
* @param options.ruleParams - Array of valid ending values
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
export declare const EndsWithOneOf: (ruleParameters: string[]) => PropertyDecorator;
/**
* ### String Rule
*
* Validates that the field under validation is a string. If you would like to
* allow the field to also be null, you should assign the nullable rule to the field.
*
* @example
* ```typescript
* // Class validation
* class TextContent {
* @IsRequired
* @IsString
* title: String;
*
* @IsString
* description?: String | null;
* }
* ```
*
* @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 IsString: PropertyDecorator;
declare module "../types" {
interface IValidatorRules {
/**
* ### String Rule
*
* Validates that the field under validation is a string. If you would like to
* allow the field to also be null, you should assign the nullable rule to the field.
*
* @example
* ```typescript
* // Valid String values
* await Validator.validate({
* value: 'Hello World',
* rules: ['String']
* }); // ✓ Valid
*
* await Validator.validate({
* value: '',
* rules: ['String']
* }); // ✓ Valid (empty String)
*
* // Invalid examples
* await Validator.validate({
* value: 123,
* rules: ['String']
* }); // ✗ Invalid
*
* await Validator.validate({
* value: null,
* rules: ['String']
* }); // ✗ Invalid (use nullable for null support)
*
* // With nullable support
* await Validator.validate({
* value: null,
* rules: ['nullable', 'String']
* }); // ✓ Valid
*
* // Class validation
* class TextContent {
* @Required
* @String
* title: String;
*
* @String
* description?: String | null;
* }
* ```
*
* @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
*/
String: IValidatorRuleFunction;
/**
* ### StartsWithOneOf Rule
*
* Validates that the field under validation starts with one of the given values.
*
* #### Parameters
* - List of values that the field must start with
*
* @example
* ```typescript
* // Valid beginnings
* await Validator.validate({
* value: 'https://example.com',
* rules: ['StartsWithOneOf[http://,https://]']
* }); // ✓ Valid
*
* await Validator.validate({
* value: 'USER_12345',
* rules: ['StartsWithOneOf[USER_,ADMIN_]']
* }); // ✓ Valid
*
* // Invalid example
* await Validator.validate({
* value: 'ftp://example.com',
* rules: ['StartsWithOneOf[http://,https://]']
* }); // ✗ Invalid
*
* // Class validation
* class Configuration {
* @StartsWithOneOf(['http://', 'https://'])
* apiUrl: string;
*
* @StartsWithOneOf(['prod_', 'dev_', 'test_'])
* environment: string;
* }
* ```
*
* @param options - Validation options with rule parameters
* @param options.ruleParams - Array of valid starting values
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
StartsWithOneOf: IValidatorRuleFunction;
/**
* ### Ends With Rule
*
* Validates that the field under validation ends with one of the given values.
*
* #### Parameters
* - List of values that the field must end with
*
* @example
* ```typescript
* // Valid endings
* await Validator.validate({
* value: 'profile.jpg',
* rules: ['EndsWithOneOf[jpg,png,gif]']
* }); // ✓ Valid
*
* await Validator.validate({
* value: 'document.pdf',
* rules: ['EndsWithOneOf[pdf,doc,docx]']
* }); // ✓ Valid
*
* // Invalid example
* await Validator.validate({
* value: 'image.txt',
* rules: ['EndsWithOneOf[jpg,png,gif]']
* }); // ✗ Invalid
*
* // Class validation
* class FileUpload {
* @EndsWithOneOf(['jpg', 'png', 'gif', 'webp'])
* imageFile: string;
*
* @EndsWithOneOf(['.com', '.org', '.net'])
* websiteUrl: string;
* }
* ```
*
* @param options - Validation options with rule parameters
* @param options.ruleParams - Array of valid ending values
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
EndsWithOneOf: IValidatorRuleFunction;
}
}