since import * as t from 'io-ts' ; import isEmail from 'validator/lib/isEmail' ; import isMobilePhone from 'validator/lib/isMobilePhone' ; import isURL from 'validator/lib/isURL' ; interface NonEmptyStringBrand { readonly NonEmptyString : unique symbol ; } since export const NonEmptyString = t . brand ( t . string , ( s ) : s is t . Branded < string , NonEmptyStringBrand > => s . length > 0 , 'NonEmptyString' ) ; interface TrimmedStringBrand { readonly TrimmedString : unique symbol ; } since export const TrimmedString = t . brand ( t . string , ( s ) : s is t . Branded < string , TrimmedStringBrand > => s . trim ( ) . length === s . length , 'TrimmedString' ) ; since export const NonEmptyTrimmedString = t . intersection ( [ NonEmptyString , TrimmedString , ] ) ; interface Max64StringBrand { readonly Max64String : unique symbol ; } since export const Max64String = t . brand ( t . string , ( s ) : s is t . Branded < string , Max64StringBrand > => s . length <= 64 , 'Max64String' ) ; interface Max512StringBrand { readonly Max512String : unique symbol ; } since export const Max512String = t . brand ( t . string , ( s ) : s is t . Branded < string , Max512StringBrand > => s . length <= 512 , 'Max512String' ) ; interface Min6StringBrand { readonly Min6String : unique symbol ; } since export const Min6String = t . brand ( t . string , ( s ) : s is t . Branded < string , Min6StringBrand > => s . length >= 6 , 'Min6String' ) ; interface EmailStringBrand { readonly EmailString : unique symbol ; } since export const EmailString = t . brand ( t . string , ( s ) : s is t . Branded < string , EmailStringBrand > => isEmail ( s ) , 'EmailString' ) ; interface PhoneStringBrand { readonly PhoneString : unique symbol ; } since export const PhoneString = t . brand ( t . string , ( s ) : s is t . Branded < string , PhoneStringBrand > => isMobilePhone ( s ) , 'PhoneString' ) ; interface UrlStringBrand { readonly UrlString : unique symbol ; } since export const UrlString = t . brand ( t . string , ( s ) : s is t . Branded < string , UrlStringBrand > => isURL ( s ) , 'UrlString' ) ; since export const String64 = t . intersection ( [ NonEmptyTrimmedString , Max64String ] ) ; since export type String64 = t . TypeOf < typeof String64 > ; since export const String512 = t . intersection ( [ NonEmptyTrimmedString , Max512String ] ) ; since export type String512 = t . TypeOf < typeof String512 > ; since export const Email = t . intersection ( [ String64 , EmailString ] ) ; since export type Email = t . TypeOf < typeof Email > ; interface UniqueEmailBrand { readonly UniqueEmail : unique symbol ; } example ts-ignore since export const UniqueEmail = t . brand ( Email , ( _s ) : _s is t . Branded < Email , UniqueEmailBrand > => true , 'UniqueEmail' ) ; since export type UniqueEmail = t . TypeOf < typeof UniqueEmail > ; since export const Password = t . intersection ( [ String512 , Min6String ] ) ; since export type Password = t . TypeOf < typeof Password > ; interface VerifiedPasswordBrand { readonly VerifiedPassword : unique symbol ; } since export const VerifiedPassword = t . brand ( Password , ( _s ) : _s is t . Branded < Password , VerifiedPasswordBrand > => true , 'VerifiedPassword' ) ; since export type VerifiedPassword = t . TypeOf < typeof VerifiedPassword > ; since export const Phone = t . intersection ( [ NonEmptyTrimmedString , PhoneString ] ) ; since export type Phone = t . TypeOf < typeof Phone > ; since export const Url = t . intersection ( [ NonEmptyTrimmedString , UrlString ] ) ; since export type Url = t . TypeOf < typeof Url > ;