File size: 762 Bytes
2857363
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
export const MIN_TEXT_LENGTH = 1;
export const MAX_TEXT_LENGTH = 512;

export interface ValidationResult {
  isValid: boolean;
  error: string | null;
}

export const validateText = (text: string): ValidationResult => {
  const trimmedText = text.trim();

  if (trimmedText.length === 0) {
    return {
      isValid: false,
      error: 'Please enter some text to analyze',
    };
  }

  if (trimmedText.length < MIN_TEXT_LENGTH) {
    return {
      isValid: false,
      error: `Text must be at least ${MIN_TEXT_LENGTH} character`,
    };
  }

  if (trimmedText.length > MAX_TEXT_LENGTH) {
    return {
      isValid: false,
      error: `Text must be ${MAX_TEXT_LENGTH} characters or less`,
    };
  }

  return {
    isValid: true,
    error: null,
  };
};