@@ -24,37 +24,45 @@ export const isHtml = (value: any) => !value || HtmlRegexp.test(value);
2424export const valuesAreHtml = ( values : any [ ] ) => values . every ( isHtml ) ;
2525
2626const UrlRegexp = / h t t p ( s * ) : \/ \/ .* / i;
27- export const isUrl = ( value : any ) => ! value || UrlRegexp . test ( value ) ;
27+ export const isUrl = ( value : any ) : value is string =>
28+ ! value || UrlRegexp . test ( value ) ;
2829export const valuesAreUrl = ( values : any [ ] ) => values . every ( isUrl ) ;
2930
3031const ImageUrlRegexp =
31- / h t t p ( s * ) : \/ \/ .* \. ( j p e g | j p g | j f i f | p j p e g | p j p | p n g | s v g | g i f | w e b p | a p n g | b m p | i c o | c u r | t i f | t i f f ) / i;
32- export const isImageUrl = ( value : any ) => ! value || ImageUrlRegexp . test ( value ) ;
32+ / ^ h t t p ( s * ) : \/ \/ .* \. ( j p e g | j p g | j f i f | p j p e g | p j p | p n g | s v g | g i f | w e b p | a p n g | b m p | i c o | c u r | t i f | t i f f ) / i;
33+ export const isImageUrl = ( value : any ) : value is string =>
34+ ! value || ImageUrlRegexp . test ( value ) ;
3335export const valuesAreImageUrl = ( values : any [ ] ) => values . every ( isImageUrl ) ;
3436
3537// This is a very simple regex to find emails
3638// It is NOT meant to validate emails as the spec is way more complicated but is
3739// enough for our inference needs
3840const EmailRegexp = / @ { 1 } / ;
39- export const isEmail = ( value : any ) => ! value || EmailRegexp . test ( value ) ;
41+ export const isEmail = ( value : any ) : value is string =>
42+ ! value || EmailRegexp . test ( value ) ;
4043export const valuesAreEmail = ( values : any [ ] ) => values . every ( isEmail ) ;
4144
42- export const isArray = ( value : any ) => Array . isArray ( value ) ;
43- export const valuesAreArray = ( values : any [ ] ) => values . every ( isArray ) ;
45+ export const isArray = ( value : any ) : value is Array < any > =>
46+ Array . isArray ( value ) ;
47+ export const valuesAreArray = ( values : any [ ] ) : values is Array < any > [ ] =>
48+ values . every ( isArray ) ;
4449
45- export const isDate = ( value : any ) => ! value || value instanceof Date ;
46- export const valuesAreDate = ( values : any [ ] ) => values . every ( isDate ) ;
50+ export const isDate = ( value : any ) : value is Date =>
51+ ! value || value instanceof Date ;
52+ export const valuesAreDate = ( values : any [ ] ) : values is Date [ ] =>
53+ values . every ( isDate ) ;
4754
48- export const isDateString = ( value : any ) =>
55+ export const isDateString = ( value : any ) : value is string =>
4956 ! value ||
5057 ( typeof value === 'string' &&
5158 ( isMatch ( value , 'MM/dd/yyyy' ) ||
5259 isMatch ( value , 'MM/dd/yy' ) ||
5360 isValid ( parseISO ( value ) ) ) ) ;
5461
55- export const valuesAreDateString = ( values : any [ ] ) =>
62+ export const valuesAreDateString = ( values : any [ ] ) : values is string [ ] =>
5663 values . every ( isDateString ) ;
5764
58- export const isObject = ( value : any ) =>
65+ export const isObject = ( value : any ) : value is object =>
5966 Object . prototype . toString . call ( value ) === '[object Object]' ;
60- export const valuesAreObject = ( values : any [ ] ) => values . every ( isObject ) ;
67+ export const valuesAreObject = ( values : any [ ] ) : values is Array < object > =>
68+ values . every ( isObject ) ;
0 commit comments