import compareVersions from "compare-versions" ; export class VersionUtils { public static isValidVersion = ( version ) : boolean => { return compareVersions . validate ( version ) ; } ; public static isLatestVersionKeyword = ( version ) : boolean => { return version === "latest" ; } ; public static isVersionsEqual = ( firstVersion , secondVersion ) : boolean => { return compareVersions . compare ( firstVersion , secondVersion , "=" ) ; } ; public static sortVersions = ( versions ) : string [ ] => { return [ ... versions ] . sort ( compareVersions ) . reverse ( ) ; } ; public static normalizeVersion = ( version ) : string => { const versionParts = VersionUtils . splitVersionToParts ( version ) ; while ( versionParts . length < 4 ) { versionParts . push ( "x" ) ; } return VersionUtils . buildVersionFromParts ( versionParts ) ; } ; public static countVersionLength = ( version ) : number => { return VersionUtils . splitVersionToParts ( version ) . length ; } ; public static cutVersionLength = ( version , newLength ) : string => { const versionParts = VersionUtils . splitVersionToParts ( version ) ; const newParts = versionParts . slice ( 0 , newLength ) ; return VersionUtils . buildVersionFromParts ( newParts ) ; } ; private static splitVersionToParts = ( version ) : string [ ] => { return version . split ( "." ) ; } ; private static buildVersionFromParts = ( versionParts ) : string => { return versionParts . join ( "." ) ; } ; }