Changeset View
Changeset View
Standalone View
Standalone View
lib/utils/validation-utils.js
// @flow | // @flow | ||||
import t from 'tcomb'; | import t from 'tcomb'; | ||||
import type { | import type { | ||||
TStructProps, | TStructProps, | ||||
TIrreducible, | TIrreducible, | ||||
TRefinement, | TRefinement, | ||||
TEnums, | TEnums, | ||||
TInterface, | TInterface, | ||||
TUnion, | |||||
} from 'tcomb'; | } from 'tcomb'; | ||||
import { | import { | ||||
validEmailRegex, | validEmailRegex, | ||||
oldValidUsernameRegex, | oldValidUsernameRegex, | ||||
validHexColorRegex, | validHexColorRegex, | ||||
} from '../shared/account-utils'; | } from '../shared/account-utils'; | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | const tPassword: TRefinement<string> = t.refinement( | ||||
t.String, | t.String, | ||||
(password: string) => !!password, | (password: string) => !!password, | ||||
); | ); | ||||
const tCookie: TRegex = tRegex(/^(user|anonymous)=[0-9]+:[0-9a-f]+$/); | const tCookie: TRegex = tRegex(/^(user|anonymous)=[0-9]+:[0-9a-f]+$/); | ||||
const tEmail: TRegex = tRegex(validEmailRegex); | const tEmail: TRegex = tRegex(validEmailRegex); | ||||
const tOldValidUsername: TRegex = tRegex(oldValidUsernameRegex); | const tOldValidUsername: TRegex = tRegex(oldValidUsernameRegex); | ||||
const tID: TRefinement<string> = t.refinement(t.String, (id: string) => !!id); | const tID: TRefinement<string> = t.refinement(t.String, (id: string) => !!id); | ||||
const tMediaMessagePhoto: TInterface = tShape({ | |||||
type: tString('photo'), | |||||
uploadID: t.String, | |||||
}); | |||||
const tMediaMessageVideo: TInterface = tShape({ | |||||
type: tString('video'), | |||||
uploadID: t.String, | |||||
thumbnailUploadID: t.String, | |||||
}); | |||||
const tMediaMessageMedia: TUnion<TInterface> = t.union([ | |||||
tMediaMessagePhoto, | |||||
tMediaMessageVideo, | |||||
]); | |||||
export { | export { | ||||
tBool, | tBool, | ||||
tString, | tString, | ||||
tNumber, | tNumber, | ||||
tShape, | tShape, | ||||
tRegex, | tRegex, | ||||
tNumEnum, | tNumEnum, | ||||
tDate, | tDate, | ||||
tColor, | tColor, | ||||
tPlatform, | tPlatform, | ||||
tDeviceType, | tDeviceType, | ||||
tPlatformDetails, | tPlatformDetails, | ||||
tPassword, | tPassword, | ||||
tCookie, | tCookie, | ||||
tEmail, | tEmail, | ||||
tOldValidUsername, | tOldValidUsername, | ||||
tID, | tID, | ||||
tMediaMessagePhoto, | |||||
tMediaMessageVideo, | |||||
tMediaMessageMedia, | |||||
}; | }; |