1

I'm using UAParser to get the OS version the user has, for example:

function osCheck() {
  var parser = new UAParser();

  return {
    name: parser.getOS().name,
    version: parser.getOS().version
  }
}

This gives me back 10.11.3 for example: var osVersion = osCheck().version;

I then want to add a conditional to check whether is more than 10.11 taking into account the variable could have double decimals like 10.11.3 what's the best way to do this?

user1937021
  • 10,151
  • 22
  • 81
  • 143
  • Slice after 5 characters? If there's a part behind 10.11, you know there's another version number, so it's automatically higher than 10.11 (eg 10.11.1) And then you can just split on the dots, parse the integer of the last part and compare integers. – Shilly Feb 14 '17 at 15:57
  • possible duplicate of http://stackoverflow.com/questions/6832596/how-to-compare-software-version-number-using-js-only-number – callback Feb 14 '17 at 16:20

1 Answers1

1

If you don't mind using a third party, try semver

Then you can just:

const semver = require('semver')

semver.gt(version, '10.11.0')
Daniel
  • 6,194
  • 7
  • 33
  • 59