@umituz/react-native-design-system 4.25.8 → 4.25.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/atoms/AtomicAvatar.tsx +0 -5
- package/src/atoms/AtomicInput.tsx +0 -2
- package/src/atoms/AtomicProgress.tsx +0 -5
- package/src/atoms/AtomicTextArea.tsx +0 -4
- package/src/atoms/card/AtomicCard.tsx +111 -54
- package/src/atoms/input/types.ts +0 -2
- package/src/atoms/skeleton/AtomicSkeleton.tsx +2 -2
- package/src/image/presentation/components/ImageGallery.tsx +16 -15
- package/src/image/presentation/components/editor/StickerPickerSheet.tsx +4 -7
- package/src/layouts/ScreenHeader/ScreenHeader.tsx +0 -2
- package/src/loading/presentation/providers/LoadingProvider.tsx +13 -4
- package/src/molecules/SearchBar/SearchBar.tsx +0 -2
- package/src/molecules/SearchBar/SearchSuggestions.tsx +1 -1
- package/src/molecules/SearchBar/types.ts +0 -1
- package/src/molecules/StepHeader/StepHeader.tsx +1 -1
- package/src/molecules/avatar/Avatar.tsx +76 -71
- package/src/molecules/avatar/AvatarGroup.tsx +1 -1
- package/src/molecules/calendar/presentation/components/CalendarDayCell.tsx +2 -3
- package/src/molecules/calendar/presentation/components/CalendarWeekdayHeader.tsx +1 -1
- package/src/molecules/countdown/components/Countdown.tsx +14 -11
- package/src/molecules/info-grid/InfoGrid.tsx +2 -2
- package/src/onboarding/presentation/components/BackgroundImageCollage.tsx +2 -2
- package/src/onboarding/presentation/components/OnboardingBackground.tsx +63 -49
- package/src/onboarding/presentation/components/OnboardingSlide.tsx +2 -2
- package/src/theme/infrastructure/providers/DesignSystemProvider.tsx +3 -1
- package/src/gallery/gallery-download.service.ts +0 -69
- package/src/gallery/gallery-save.service.ts +0 -80
- package/src/gallery/index.ts +0 -3
- package/src/gallery/types.ts +0 -11
- package/src/image/domain/entities/EditorTypes.ts +0 -23
- package/src/image/domain/entities/editor/EditorConfigTypes.ts +0 -35
- package/src/image/domain/entities/editor/EditorElementTypes.ts +0 -60
- package/src/image/domain/entities/editor/EditorFilterTypes.ts +0 -9
- package/src/image/domain/entities/editor/EditorLayerTypes.ts +0 -34
- package/src/image/domain/entities/editor/EditorStateTypes.ts +0 -35
- package/src/image/domain/entities/editor/EditorToolTypes.ts +0 -33
- package/src/image/infrastructure/services/ImageEditorService.ts +0 -134
- package/src/image/infrastructure/utils/ImageAnalysisUtils.ts +0 -120
- package/src/image/infrastructure/utils/ImageEditorHistoryUtils.ts +0 -63
- package/src/image/infrastructure/utils/LayerManager.ts +0 -65
- package/src/media/infrastructure/hooks/useGenericMediaGeneration.ts +0 -170
- package/src/molecules/ConfirmationModal.tsx +0 -42
- package/src/molecules/calendar/infrastructure/storage/CalendarStore.types.ts +0 -64
- package/src/molecules/calendar/infrastructure/storage/CalendarStore.utils.ts +0 -56
- package/src/molecules/calendar/infrastructure/storage/EventActions.ts +0 -140
- package/src/molecules/calendar/infrastructure/storage/NavigationActions.ts +0 -118
- package/src/molecules/calendar/presentation/hooks/useCalendar.ts +0 -185
- package/src/molecules/confirmation-modal/index.ts +0 -7
- package/src/molecules/listitem/index.ts +0 -6
- package/src/molecules/navigation/components/index.ts +0 -4
- package/src/molecules/navigation/utils/NavigationTheme.ts +0 -21
- package/src/presentation/utils/variants/compound.ts +0 -34
- package/src/services/api/ApiClient.ts +0 -180
- package/src/services/api/index.ts +0 -9
- package/src/services/api/types/ApiTypes.ts +0 -50
- package/src/services/api/utils/requestBuilder.ts +0 -92
- package/src/services/api/utils/responseHandler.ts +0 -130
- package/src/storage/cache/index.ts +0 -28
- package/src/theme/core/tokens/BorderRadius.ts +0 -16
- package/src/utilities/clipboard/ClipboardUtils.ts +0 -67
- package/src/utilities/clipboard/index.ts +0 -5
- package/src/utilities/index.ts +0 -6
- package/src/utilities/sharing/domain/entities/Share.ts +0 -104
- package/src/utilities/sharing/domain/entities/SharingUtils.ts +0 -111
- package/src/utilities/sharing/index.ts +0 -33
- package/src/utilities/sharing/infrastructure/services/SharingService.ts +0 -165
- package/src/utilities/sharing/presentation/hooks/useSharing.ts +0 -116
- package/src/utils/colorMapper.ts +0 -193
- package/src/utils/errors/adapters/CacheErrorAdapter.ts +0 -68
- package/src/utils/errors/adapters/ImageErrorAdapter.ts +0 -91
- package/src/utils/errors/adapters/StorageErrorAdapter.ts +0 -107
- package/src/utils/formatHelper.ts +0 -16
- package/src/utils/formatters/dateFormatter.ts +0 -64
- package/src/utils/formatters/numberFormatter.ts +0 -130
- package/src/utils/index.ts +0 -16
- package/src/utils/styleComposer.ts +0 -94
- package/src/utils/validationHelper.ts +0 -16
- package/src/utils/validators/dataValidators.ts +0 -111
- package/src/utils/validators/numericValidators.ts +0 -106
- package/src/utils/validators/stringValidators.ts +0 -85
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Number Formatter Utility
|
|
3
|
-
* Number, currency, and percentage formatting functions
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Number formatting options
|
|
8
|
-
*/
|
|
9
|
-
export interface NumberFormatOptions {
|
|
10
|
-
decimals?: number;
|
|
11
|
-
locale?: string;
|
|
12
|
-
compact?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Formats a number according to the specified options
|
|
17
|
-
*
|
|
18
|
-
* @param num - Number to format
|
|
19
|
-
* @param options - Formatting options
|
|
20
|
-
* @returns Formatted number string
|
|
21
|
-
*/
|
|
22
|
-
export function formatNumber(num: number, options: NumberFormatOptions = {}): string {
|
|
23
|
-
const {
|
|
24
|
-
decimals = 0,
|
|
25
|
-
locale = 'en-US',
|
|
26
|
-
compact = false,
|
|
27
|
-
} = options;
|
|
28
|
-
|
|
29
|
-
if (isNaN(num)) {
|
|
30
|
-
return '0';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const formatOptions: Intl.NumberFormatOptions = {
|
|
34
|
-
minimumFractionDigits: decimals,
|
|
35
|
-
maximumFractionDigits: decimals,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
if (compact) {
|
|
39
|
-
formatOptions.notation = 'compact';
|
|
40
|
-
formatOptions.compactDisplay = 'short';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return new Intl.NumberFormat(locale, formatOptions).format(num);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Currency formatting options
|
|
48
|
-
*/
|
|
49
|
-
export interface CurrencyFormatOptions {
|
|
50
|
-
currency?: string;
|
|
51
|
-
locale?: string;
|
|
52
|
-
decimals?: number;
|
|
53
|
-
symbol?: string;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Formats a currency amount
|
|
58
|
-
*
|
|
59
|
-
* @param amount - Amount to format
|
|
60
|
-
* @param options - Formatting options
|
|
61
|
-
* @returns Formatted currency string
|
|
62
|
-
*/
|
|
63
|
-
export function formatCurrency(amount: number, options: CurrencyFormatOptions = {}): string {
|
|
64
|
-
const {
|
|
65
|
-
currency = 'USD',
|
|
66
|
-
locale = 'en-US',
|
|
67
|
-
decimals = 2,
|
|
68
|
-
symbol,
|
|
69
|
-
} = options;
|
|
70
|
-
|
|
71
|
-
if (isNaN(amount)) {
|
|
72
|
-
return `${symbol || currency} 0.00`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (symbol) {
|
|
76
|
-
return `${symbol}${formatNumber(amount, { decimals, locale })}`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return new Intl.NumberFormat(locale, {
|
|
80
|
-
style: 'currency',
|
|
81
|
-
currency,
|
|
82
|
-
minimumFractionDigits: decimals,
|
|
83
|
-
maximumFractionDigits: decimals,
|
|
84
|
-
}).format(amount);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Percentage formatting options
|
|
89
|
-
*/
|
|
90
|
-
export interface PercentFormatOptions {
|
|
91
|
-
decimals?: number;
|
|
92
|
-
locale?: string;
|
|
93
|
-
includeSymbol?: boolean;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Formats a number as a percentage
|
|
98
|
-
*
|
|
99
|
-
* @param value - Value to format (0-1 or 0-100)
|
|
100
|
-
* @param options - Formatting options
|
|
101
|
-
* @param isDecimal - Whether the value is already in decimal form (0-1)
|
|
102
|
-
* @returns Formatted percentage string
|
|
103
|
-
*/
|
|
104
|
-
export function formatPercent(
|
|
105
|
-
value: number,
|
|
106
|
-
options: PercentFormatOptions = {},
|
|
107
|
-
isDecimal: boolean = true
|
|
108
|
-
): string {
|
|
109
|
-
const {
|
|
110
|
-
decimals = 1,
|
|
111
|
-
locale = 'en-US',
|
|
112
|
-
includeSymbol = true,
|
|
113
|
-
} = options;
|
|
114
|
-
|
|
115
|
-
if (isNaN(value)) {
|
|
116
|
-
return '0%';
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const displayValue = isDecimal ? value * 100 : value;
|
|
120
|
-
|
|
121
|
-
if (includeSymbol) {
|
|
122
|
-
return new Intl.NumberFormat(locale, {
|
|
123
|
-
style: 'percent',
|
|
124
|
-
minimumFractionDigits: decimals,
|
|
125
|
-
maximumFractionDigits: decimals,
|
|
126
|
-
}).format(isDecimal ? value : value / 100);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return `${formatNumber(displayValue, { decimals, locale })}%`;
|
|
130
|
-
}
|
package/src/utils/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utils Index
|
|
3
|
-
* Centralized export of all utility functions
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export * from './styleComposer';
|
|
7
|
-
export * from './colorMapper';
|
|
8
|
-
export * from './validationHelper';
|
|
9
|
-
export * from './formatHelper';
|
|
10
|
-
export * from './formatters/dateFormatter';
|
|
11
|
-
export * from './formatters/numberFormatter';
|
|
12
|
-
export * from './formatters/stringFormatter';
|
|
13
|
-
export * from './validators/dataValidators';
|
|
14
|
-
export * from './validators/stringValidators';
|
|
15
|
-
export * from './validators/numericValidators';
|
|
16
|
-
export * from './logger';
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Style Composer Utility
|
|
3
|
-
* Centralized style composition logic to avoid duplication across components
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { StyleProp, ViewStyle, TextStyle, ImageStyle } from 'react-native';
|
|
7
|
-
|
|
8
|
-
type StyleType = ViewStyle | TextStyle | ImageStyle;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Composes multiple styles into a single style array
|
|
12
|
-
* Handles conditional styles and prevents undefined values
|
|
13
|
-
*
|
|
14
|
-
* @param baseStyle - The base style object
|
|
15
|
-
* @param additionalStyles - Additional styles to compose (can be conditional)
|
|
16
|
-
* @returns Composed style array
|
|
17
|
-
*/
|
|
18
|
-
export function composeStyles<T extends StyleType>(
|
|
19
|
-
baseStyle?: StyleProp<T>,
|
|
20
|
-
...additionalStyles: (StyleProp<T> | boolean | undefined | null)[]
|
|
21
|
-
): StyleProp<T> {
|
|
22
|
-
const composed: any[] = [];
|
|
23
|
-
|
|
24
|
-
// Add base style if provided
|
|
25
|
-
if (baseStyle) {
|
|
26
|
-
composed.push(baseStyle);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Add additional styles, filtering out falsy values
|
|
30
|
-
additionalStyles.forEach((style) => {
|
|
31
|
-
if (style && style !== true) {
|
|
32
|
-
composed.push(style);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
return composed as StyleProp<T>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Composes styles with condition handling
|
|
41
|
-
* Useful for variant-based style composition
|
|
42
|
-
*
|
|
43
|
-
* @param baseStyles - Base style object
|
|
44
|
-
* @param variantStyles - Variant-specific styles
|
|
45
|
-
* @param condition - Whether to apply variant styles
|
|
46
|
-
* @returns Composed style array
|
|
47
|
-
*/
|
|
48
|
-
export function composeVariantStyles<T extends StyleType>(
|
|
49
|
-
baseStyles: StyleProp<T>,
|
|
50
|
-
variantStyles: StyleProp<T>,
|
|
51
|
-
condition: boolean
|
|
52
|
-
): StyleProp<T> {
|
|
53
|
-
return composeStyles(baseStyles, condition && variantStyles);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Merges multiple style objects into one
|
|
58
|
-
* Deep merges style properties
|
|
59
|
-
*
|
|
60
|
-
* @param styles - Styles to merge
|
|
61
|
-
* @returns Merged style object
|
|
62
|
-
*/
|
|
63
|
-
export function mergeStyles<T extends StyleType>(
|
|
64
|
-
...styles: (StyleProp<T> | undefined | null)[]
|
|
65
|
-
): StyleProp<T> {
|
|
66
|
-
const merged: T = {} as T;
|
|
67
|
-
|
|
68
|
-
styles.forEach((style) => {
|
|
69
|
-
if (style && typeof style === 'object') {
|
|
70
|
-
Object.assign(merged, style);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return merged;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Creates a style resolver for responsive designs
|
|
79
|
-
* Returns appropriate style based on screen size
|
|
80
|
-
*
|
|
81
|
-
* @param small - Style for small screens
|
|
82
|
-
* @param medium - Style for medium screens
|
|
83
|
-
* @param large - Style for large screens
|
|
84
|
-
* @param screenSize - Current screen size category
|
|
85
|
-
* @returns Appropriate style for the screen size
|
|
86
|
-
*/
|
|
87
|
-
export function resolveResponsiveStyle<T extends StyleType>(
|
|
88
|
-
small: T,
|
|
89
|
-
medium: T,
|
|
90
|
-
large: T,
|
|
91
|
-
screenSize: 'small' | 'medium' | 'large'
|
|
92
|
-
): T {
|
|
93
|
-
return screenSize === 'large' ? large : screenSize === 'medium' ? medium : small;
|
|
94
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validation Helper Utility
|
|
3
|
-
* Common validation functions for forms and inputs
|
|
4
|
-
*
|
|
5
|
-
* This file re-exports all validation utilities for convenience
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// Core validation types and functions
|
|
9
|
-
export * from './validators/dataValidators';
|
|
10
|
-
|
|
11
|
-
// String validation functions
|
|
12
|
-
export * from './validators/stringValidators';
|
|
13
|
-
|
|
14
|
-
// Numeric validation functions
|
|
15
|
-
export * from './validators/numericValidators';
|
|
16
|
-
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Data Validators
|
|
3
|
-
* Common validation functions for data types
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Email validation result
|
|
8
|
-
*/
|
|
9
|
-
export interface ValidationResult {
|
|
10
|
-
isValid: boolean;
|
|
11
|
-
error?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Email validation regex pattern
|
|
16
|
-
*/
|
|
17
|
-
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Validates an email address
|
|
21
|
-
*
|
|
22
|
-
* @param email - Email string to validate
|
|
23
|
-
* @returns Validation result with error message if invalid
|
|
24
|
-
*/
|
|
25
|
-
export function validateEmail(email: string): ValidationResult {
|
|
26
|
-
if (!email || email.trim() === '') {
|
|
27
|
-
return { isValid: false, error: 'Email is required' };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!EMAIL_REGEX.test(email)) {
|
|
31
|
-
return { isValid: false, error: 'Please enter a valid email address' };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return { isValid: true };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* URL validation regex pattern
|
|
39
|
-
*/
|
|
40
|
-
const URL_REGEX = /^https?:\/\/.+/;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Validates a URL
|
|
44
|
-
*
|
|
45
|
-
* @param url - URL string to validate
|
|
46
|
-
* @returns Validation result with error message if invalid
|
|
47
|
-
*/
|
|
48
|
-
export function validateUrl(url: string): ValidationResult {
|
|
49
|
-
if (!url || url.trim() === '') {
|
|
50
|
-
return { isValid: false, error: 'URL is required' };
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!URL_REGEX.test(url)) {
|
|
54
|
-
return { isValid: false, error: 'Please enter a valid URL (must start with http:// or https://)' };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return { isValid: true };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Validates a required field
|
|
62
|
-
*
|
|
63
|
-
* @param value - Value to validate
|
|
64
|
-
* @param fieldName - Name of the field for error message
|
|
65
|
-
* @returns Validation result with error message if invalid
|
|
66
|
-
*/
|
|
67
|
-
export function validateRequired(value: any, fieldName: string = 'Field'): ValidationResult {
|
|
68
|
-
if (value === null || value === undefined || value === '') {
|
|
69
|
-
return { isValid: false, error: `${fieldName} is required` };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (typeof value === 'string' && value.trim() === '') {
|
|
73
|
-
return { isValid: false, error: `${fieldName} is required` };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (Array.isArray(value) && value.length === 0) {
|
|
77
|
-
return { isValid: false, error: `${fieldName} is required` };
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return { isValid: true };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Validates multiple fields and returns all errors
|
|
85
|
-
*
|
|
86
|
-
* @param validations - Object containing field names and their validation results
|
|
87
|
-
* @returns Object with field names as keys and error messages as values
|
|
88
|
-
*/
|
|
89
|
-
export function validateMultiple(
|
|
90
|
-
validations: Record<string, ValidationResult>
|
|
91
|
-
): Record<string, string> {
|
|
92
|
-
const errors: Record<string, string> = {};
|
|
93
|
-
|
|
94
|
-
Object.entries(validations).forEach(([field, result]) => {
|
|
95
|
-
if (!result.isValid && result.error) {
|
|
96
|
-
errors[field] = result.error;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
return errors;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Checks if there are any validation errors
|
|
105
|
-
*
|
|
106
|
-
* @param errors - Validation errors object
|
|
107
|
-
* @returns True if there are errors
|
|
108
|
-
*/
|
|
109
|
-
export function hasValidationErrors(errors: Record<string, string>): boolean {
|
|
110
|
-
return Object.keys(errors).length > 0;
|
|
111
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Numeric Validators
|
|
3
|
-
* Validation functions for numeric inputs
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { ValidationResult } from './dataValidators';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Password validation options
|
|
10
|
-
*/
|
|
11
|
-
export interface PasswordValidationOptions {
|
|
12
|
-
minLength?: number;
|
|
13
|
-
requireUppercase?: boolean;
|
|
14
|
-
requireLowercase?: boolean;
|
|
15
|
-
requireNumbers?: boolean;
|
|
16
|
-
requireSpecialChars?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Validates a password
|
|
21
|
-
*
|
|
22
|
-
* @param password - Password string to validate
|
|
23
|
-
* @param options - Validation options
|
|
24
|
-
* @returns Validation result with error message if invalid
|
|
25
|
-
*/
|
|
26
|
-
export function validatePassword(
|
|
27
|
-
password: string,
|
|
28
|
-
options: PasswordValidationOptions = {}
|
|
29
|
-
): ValidationResult {
|
|
30
|
-
const {
|
|
31
|
-
minLength = 8,
|
|
32
|
-
requireUppercase = true,
|
|
33
|
-
requireLowercase = true,
|
|
34
|
-
requireNumbers = true,
|
|
35
|
-
requireSpecialChars = false,
|
|
36
|
-
} = options;
|
|
37
|
-
|
|
38
|
-
if (!password || password.trim() === '') {
|
|
39
|
-
return { isValid: false, error: 'Password is required' };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (password.length < minLength) {
|
|
43
|
-
return { isValid: false, error: `Password must be at least ${minLength} characters` };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (requireUppercase && !/[A-Z]/.test(password)) {
|
|
47
|
-
return { isValid: false, error: 'Password must contain at least one uppercase letter' };
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (requireLowercase && !/[a-z]/.test(password)) {
|
|
51
|
-
return { isValid: false, error: 'Password must contain at least one lowercase letter' };
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (requireNumbers && !/\d/.test(password)) {
|
|
55
|
-
return { isValid: false, error: 'Password must contain at least one number' };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (requireSpecialChars && !/[!@#$%^&*(),.?":{}|<>]/.test(password)) {
|
|
59
|
-
return { isValid: false, error: 'Password must contain at least one special character' };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return { isValid: true };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Number range validation options
|
|
67
|
-
*/
|
|
68
|
-
export interface NumberRangeValidationOptions {
|
|
69
|
-
min?: number;
|
|
70
|
-
max?: number;
|
|
71
|
-
allowDecimals?: boolean;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Validates a number is within a range
|
|
76
|
-
*
|
|
77
|
-
* @param value - Number value to validate
|
|
78
|
-
* @param options - Validation options
|
|
79
|
-
* @returns Validation result with error message if invalid
|
|
80
|
-
*/
|
|
81
|
-
export function validateNumberRange(
|
|
82
|
-
value: number | string,
|
|
83
|
-
options: NumberRangeValidationOptions = {}
|
|
84
|
-
): ValidationResult {
|
|
85
|
-
const numValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
86
|
-
|
|
87
|
-
if (isNaN(numValue)) {
|
|
88
|
-
return { isValid: false, error: 'Please enter a valid number' };
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const { min, max, allowDecimals = true } = options;
|
|
92
|
-
|
|
93
|
-
if (!allowDecimals && !Number.isInteger(numValue)) {
|
|
94
|
-
return { isValid: false, error: 'Please enter a whole number' };
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (min !== undefined && numValue < min) {
|
|
98
|
-
return { isValid: false, error: `Value must be at least ${min}` };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (max !== undefined && numValue > max) {
|
|
102
|
-
return { isValid: false, error: `Value must be at most ${max}` };
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return { isValid: true };
|
|
106
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* String Validators
|
|
3
|
-
* Validation functions for string-based inputs
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { ValidationResult } from './dataValidators';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* String length validation options
|
|
10
|
-
*/
|
|
11
|
-
export interface StringLengthValidationOptions {
|
|
12
|
-
min?: number;
|
|
13
|
-
max?: number;
|
|
14
|
-
trimWhitespace?: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Validates a string length
|
|
19
|
-
*
|
|
20
|
-
* @param value - String value to validate
|
|
21
|
-
* @param options - Validation options
|
|
22
|
-
* @returns Validation result with error message if invalid
|
|
23
|
-
*/
|
|
24
|
-
export function validateStringLength(
|
|
25
|
-
value: string,
|
|
26
|
-
options: StringLengthValidationOptions = {}
|
|
27
|
-
): ValidationResult {
|
|
28
|
-
const { trimWhitespace = true } = options;
|
|
29
|
-
const strValue = trimWhitespace ? value.trim() : value;
|
|
30
|
-
|
|
31
|
-
if (!strValue) {
|
|
32
|
-
return { isValid: false, error: 'Value is required' };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const { min, max } = options;
|
|
36
|
-
|
|
37
|
-
if (min !== undefined && strValue.length < min) {
|
|
38
|
-
return { isValid: false, error: `Value must be at least ${min} characters` };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (max !== undefined && strValue.length > max) {
|
|
42
|
-
return { isValid: false, error: `Value must be at most ${max} characters` };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return { isValid: true };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Phone number validation options
|
|
50
|
-
*/
|
|
51
|
-
export interface PhoneValidationOptions {
|
|
52
|
-
countryCode?: string;
|
|
53
|
-
allowLandline?: boolean;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Validates a phone number
|
|
58
|
-
*
|
|
59
|
-
* @param phone - Phone number string to validate
|
|
60
|
-
* @param options - Validation options
|
|
61
|
-
* @returns Validation result with error message if invalid
|
|
62
|
-
*/
|
|
63
|
-
export function validatePhone(
|
|
64
|
-
phone: string,
|
|
65
|
-
_options: PhoneValidationOptions = {}
|
|
66
|
-
): ValidationResult {
|
|
67
|
-
if (!phone || phone.trim() === '') {
|
|
68
|
-
return { isValid: false, error: 'Phone number is required' };
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Remove all non-numeric characters
|
|
72
|
-
const cleanedPhone = phone.replace(/\D/g, '');
|
|
73
|
-
|
|
74
|
-
// Check minimum length (at least 10 digits for most countries)
|
|
75
|
-
if (cleanedPhone.length < 10) {
|
|
76
|
-
return { isValid: false, error: 'Please enter a valid phone number' };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Check maximum length (maximum 15 digits for international numbers)
|
|
80
|
-
if (cleanedPhone.length > 15) {
|
|
81
|
-
return { isValid: false, error: 'Please enter a valid phone number' };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return { isValid: true };
|
|
85
|
-
}
|