services/luarocks/luarocks-version-helpers.js
function parseVersion(versionString) {
  versionString = versionString.toLowerCase().replace('-', '.')
  const versionList = []
  versionString.split('.').forEach(versionPart => {
    const parsedPart = /(\d*)([a-z]*)(\d*)/.exec(versionPart)
    if (parsedPart[1]) {
      versionList.push(parseInt(parsedPart[1]))
    }
    if (parsedPart[2]) {
      let weight
      // calculate weight as a negative number
      // 'rc' > 'pre' > 'beta' > 'alpha' > any other value
      switch (parsedPart[2]) {
        case 'alpha':
        case 'beta':
        case 'pre':
        case 'rc':
          weight = (parsedPart[2].charCodeAt(0) - 128) * 100
          break
        default:
          weight = -10000
      }
      // add positive number, i.e. 'beta5' > 'beta2'
      weight += parseInt(parsedPart[3]) || 0
      versionList.push(weight)
    }
  })
  return versionList
}
function parseVersion(versionString) {
  versionString = versionString.toLowerCase().replace('-', '.')
  const versionList = []
  versionString.split('.').forEach(versionPart => {
    const parsedPart = /(\d*)([a-z]*)(\d*)/.exec(versionPart)
    if (parsedPart[1]) {
      versionList.push(parseInt(parsedPart[1]))
    }
    if (parsedPart[2]) {
      let weight
      // calculate weight as a negative number
      // 'rc' > 'pre' > 'beta' > 'alpha' > any other value
      switch (parsedPart[2]) {
        case 'alpha':
        case 'beta':
        case 'pre':
        case 'rc':
          weight = (parsedPart[2].charCodeAt(0) - 128) * 100
          break
        default:
          weight = -10000
      }
      // add positive number, i.e. 'beta5' > 'beta2'
      weight += parseInt(parsedPart[3]) || 0
      versionList.push(weight)
    }
  })
  return versionList
}
function parseVersion ( versionString ) { versionString = versionString . toLowerCase ( ) . replace ( '-' , '.' ) const versionList = [ ] versionString . split ( '.' ) . forEach ( versionPart => { const parsedPart = / (\d*)([a-z]*)(\d*) / . exec ( versionPart ) if ( parsedPart [ 1 ] ) { versionList . push ( parseInt ( parsedPart [ 1 ] ) ) } if ( parsedPart [ 2 ] ) { let weight // calculate weight as a negative number // 'rc' > 'pre' > 'beta' > 'alpha' > any other value switch ( parsedPart [ 2 ] ) { case 'alpha' : case 'beta' : case 'pre' : case 'rc' : weight = ( parsedPart [ 2 ] . charCodeAt ( 0 ) - 128 ) * 100 break default : weight = - 10000 } // add positive number, i.e. 'beta5' > 'beta2' weight += parseInt ( parsedPart [ 3 ] ) || 0 versionList . push ( weight ) } } ) return versionList }
Parse a dotted version string to an array of numbers 'rc', 'pre', 'beta', 'alpha' are converted to negative numbers
Parse a dotted version string to an array of numbers rc pre beta alpha are converted to negative numbers