1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-26 05:16:41 +07:00

working upload saga?

This commit is contained in:
muerwre 2019-08-07 15:37:57 +07:00
parent 3872ff5903
commit d73437d8c6
8 changed files with 153 additions and 42 deletions

View file

@ -1,28 +1,23 @@
import { IMAGE_MIME_TYPES } from '~/utils/uploader';
import isValid from 'date-fns/isValid';
import { IAddress } from '~/redux/types';
import { IMAGE_MIME_TYPES } from '~/utils/uploader';
const isValidEmail = (email: string): boolean =>
!!email &&
String(email) &&
!!String(email).match(
/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/,
const isValidEmail = (email: string): boolean => !!email
&& String(email)
&& !!String(email).match(
/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/
);
const isLikeEmail = (email: string): boolean =>
!!email && String(email) && !!String(email).match(/^([^\@]+)@([^\@]+)\.([^\@]+)$$/);
const isLikeEmail = (email: string): boolean => !!email && String(email) && !!String(email).match(/^([^\@]+)@([^\@]+)\.([^\@]+)$$/);
const isNonEmpty = (value: string): boolean => !!value && value.trim().length > 0;
const isLikePhone = isNonEmpty;
const isAtLeast = (length: number, value: string): boolean =>
!!value && value.trim().length >= length;
const isAtLeast = (length: number, value: string): boolean => !!value && value.trim().length >= length;
const isMimeOfImage = (mime): boolean => !!mime && IMAGE_MIME_TYPES.indexOf(mime) >= 0;
const isDate = (val: string): boolean => !!val && isValid(new Date(val));
const isStringDate = (val: string): boolean => !!val && !!val.match(/^[\d]{2,4}\-[\d]{2}-[\d]{2}/);
const isAddrWithRaw = ({ raw }: Partial<IAddress>): boolean => !!raw && isNonEmpty(raw);
export const VALIDATORS = {
EMAIL: isValidEmail,
@ -33,7 +28,5 @@ export const VALIDATORS = {
IS_IMAGE_MIME: isMimeOfImage,
IS_DATE: isDate,
IS_STRINGY_DATE: isStringDate,
IS_ADDRESS_WITH_RAW: isAddrWithRaw,
EVOLVE: (validator: (val: any) => boolean, error: string) => (val: any) =>
!val || !validator(val) ? error : null,
EVOLVE: (validator: (val: any) => boolean, error: string) => (val: any) => (!val || !validator(val) ? error : null)
};