@@ -5,6 +5,7 @@ export namespace Versions {
55 major : number ;
66 minor : number ;
77 patch : number ;
8+ pre ?: string ;
89 }
910
1011 export function compare ( v1 : Version , v2 : Version ) : number {
@@ -17,19 +18,26 @@ export namespace Versions {
1718 if ( v1 . patch > v2 . patch ) return 1 ;
1819 if ( v1 . patch < v2 . patch ) return - 1 ;
1920
21+ if ( v1 . pre === undefined && v2 . pre !== undefined ) return 1 ;
22+ if ( v1 . pre !== undefined && v2 . pre === undefined ) return - 1 ;
23+
24+ if ( v1 . pre !== undefined && v2 . pre !== undefined ) return v1 . pre . localeCompare ( v2 . pre ) ;
25+
2026 return 0 ;
2127 }
2228
23- export function from ( major : string | number , minor : string | number , patch : string | number ) : Version {
29+ export function from ( major : string | number , minor : string | number , patch : string | number , pre ?: string ) : Version {
2430 return {
2531 major : typeof major === 'string' ? parseInt ( major , 10 ) : major ,
2632 minor : typeof minor === 'string' ? parseInt ( minor , 10 ) : minor ,
27- patch : typeof patch === 'string' ? parseInt ( patch , 10 ) : patch
33+ patch : typeof patch === 'string' ? parseInt ( patch , 10 ) : patch ,
34+ pre : pre
2835 } ;
2936 }
3037
3138 export function fromString ( version : string ) : Version {
32- const [ major , minor , patch ] = version . split ( '.' ) ;
33- return from ( major , minor , patch ) ;
39+ const [ ver , pre ] = version . split ( '-' ) ;
40+ const [ major , minor , patch ] = ver . split ( '.' ) ;
41+ return from ( major , minor , patch , pre ) ;
3442 }
3543}
0 commit comments