I made something similar, but with a JavaScript-first approach:
https://github.com/faisalman/ua-parser-js