input-validator.ts 811 B

1234567891011121314151617181920212223242526272829303132
  1. export const AlertType = {
  2. WARNING: 'warning',
  3. ERROR: 'error',
  4. } as const;
  5. export type AlertType = typeof AlertType[keyof typeof AlertType];
  6. export const ValidationTarget = {
  7. FOLDER: 'folder_name',
  8. PAGE: 'page_name',
  9. DEFAULT: 'field',
  10. };
  11. export type ValidationTarget = typeof ValidationTarget[keyof typeof ValidationTarget];
  12. export type AlertInfo = {
  13. type?: AlertType
  14. message?: string,
  15. target?: string
  16. }
  17. export const inputValidator = async(title: string | null, target?: string): Promise<AlertInfo | null> => {
  18. const validationTarget = target || ValidationTarget.DEFAULT;
  19. if (title == null || title === '' || title.trim() === '') {
  20. return {
  21. type: AlertType.WARNING,
  22. message: 'form_validation.field_required',
  23. target: validationTarget,
  24. };
  25. }
  26. return null;
  27. };