ua-spy
A parser for user agent to simple js object
Features
How to use
Install
npm i ua-spy -S
Example
const { detectAll } = require('ua-spy')
const parse = detectAll()
const all = parse('Mozilla/5.0 (Linux; Android 5.1.1; vivo X6S A Build/LMY47V; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044207 Mobile Safari/537.36 MicroMessenger/6.7.3.1340(0x26070332) NetType/4G Language/zh_CN Process/tools')
console.log('result is', all)
const patchParser = detectAll({
osPatches: [
['MYOS', /\bMYOS ([\d.]+)/],
],
appPatches: [
['TAOBAO', /\bTB\/([\d.]+)/]
],
browserPatches: [
['UC', /\bMYUC ([\d._]+)/]
],
devicePatches: [
['YEJIDEVICE', /\bYEJIDEVICE ?([\d.]+)/]
],
sdkPatches: [
['YOURKIT', /\bYOURKIT ?([\d.]+)/]
],
})
const MY_UA = 'MYOS 3.3.3 Mozilla/5.0 YEJIDEVICE 1.1.1 (iPhone; CPU iPhone OS 11_4 like Mac OS X) TB/1.1.1 MYUC 2.0 AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15F79 YOURKIT 2.2.2'
console.log('result is', patchParser(MY_UA))
License
MIT