lib/init.js
function parseUseragent(ua) {

		if (!ua) {
			return null;
		}

		let platform,
		    webview = false,
		    version,
		    engine,
		    result,
		    major,
		    minor,
		    patch,
		    float,
		    index,
		    name,
		    temp,
		    os;

		ua = ua.toLowerCase();

		if (~ua.indexOf('mobile')) {
			platform = 'mobile';
		} else if (~ua.indexOf('tablet')) {
			platform = 'tablet';
		} else {
			platform = 'desktop';
		}

		if (~(index = ua.indexOf('msie'))) {
			name = 'internet explorer';
			platform = 'desktop';
		} else if (~(index = ua.indexOf('trident/'))) {
			name = 'internet explorer';
			platform = 'desktop';
			index += 13;
		} else if (~(index = ua.indexOf('edge/'))) {
			name = 'edge';
			engine = 'edgehtml';
		} else if (~(index = ua.indexOf('chrome/'))) {
			name = 'chrome';
		} else if (~(index = ua.indexOf('firefox/'))) {
			name = 'firefox';
			engine = 'gecko';
		} else if (~(index = ua.indexOf('safari/'))) {
			name = 'safari';
			index = ua.indexOf('version/');
			engine = 'webkit';
		}

		if (~index) {
			version = version_rx.exec(ua.slice(index));

			if (version) {
				float = parseFloat(version[0]);
				major = +version[1];
				minor = +version[2];
				patch = version[3] || '';
			}
		}

		if (!engine) {
			switch (name) {
				case 'internet explorer':
					engine = 'trident';
					break;

				case 'chrome':
					if (major < 28) {
						engine = 'webkit';
					} else {
						engine = 'blink';
					}
					break;
			}
		}

		if (platform != 'desktop') {
			if (~ua.indexOf('iphone') || ~ua.indexOf('ipad') || ~ua.indexOf('ipod')) {
				os = 'ios';

				if (ua.indexOf('safari') == -1) {
					webview = true;
				}
			} else if (~ua.indexOf('; wv')) {
				webview = true;
			}
		}

		result = {
			family    : name,
			version   : {
				major : major,
				minor : minor,
				patch : patch,
				float : float
			},
			platform  : platform,
			engine    : engine,
			webview   : webview,
			os        : os
		};

		return result;
	}
function parseUseragent(ua) {

		if (!ua) {
			return null;
		}

		let platform,
		    webview = false,
		    version,
		    engine,
		    result,
		    major,
		    minor,
		    patch,
		    float,
		    index,
		    name,
		    temp,
		    os;

		ua = ua.toLowerCase();

		if (~ua.indexOf('mobile')) {
			platform = 'mobile';
		} else if (~ua.indexOf('tablet')) {
			platform = 'tablet';
		} else {
			platform = 'desktop';
		}

		if (~(index = ua.indexOf('msie'))) {
			name = 'internet explorer';
			platform = 'desktop';
		} else if (~(index = ua.indexOf('trident/'))) {
			name = 'internet explorer';
			platform = 'desktop';
			index += 13;
		} else if (~(index = ua.indexOf('edge/'))) {
			name = 'edge';
			engine = 'edgehtml';
		} else if (~(index = ua.indexOf('chrome/'))) {
			name = 'chrome';
		} else if (~(index = ua.indexOf('firefox/'))) {
			name = 'firefox';
			engine = 'gecko';
		} else if (~(index = ua.indexOf('safari/'))) {
			name = 'safari';
			index = ua.indexOf('version/');
			engine = 'webkit';
		}

		if (~index) {
			version = version_rx.exec(ua.slice(index));

			if (version) {
				float = parseFloat(version[0]);
				major = +version[1];
				minor = +version[2];
				patch = version[3] || '';
			}
		}

		if (!engine) {
			switch (name) {
				case 'internet explorer':
					engine = 'trident';
					break;

				case 'chrome':
					if (major < 28) {
						engine = 'webkit';
					} else {
						engine = 'blink';
					}
					break;
			}
		}

		if (platform != 'desktop') {
			if (~ua.indexOf('iphone') || ~ua.indexOf('ipad') || ~ua.indexOf('ipod')) {
				os = 'ios';

				if (ua.indexOf('safari') == -1) {
					webview = true;
				}
			} else if (~ua.indexOf('; wv')) {
				webview = true;
			}
		}

		result = {
			family    : name,
			version   : {
				major : major,
				minor : minor,
				patch : patch,
				float : float
			},
			platform  : platform,
			engine    : engine,
			webview   : webview,
			os        : os
		};

		return result;
	}
function parseUseragent ( ua ) { if ( ! ua ) { return null ; } let platform , webview = false , version , engine , result , major , minor , patch , float , index , name , temp , os ; ua = ua . toLowerCase ( ) ; if ( ~ ua . indexOf ( 'mobile' ) ) { platform = 'mobile' ; } else if ( ~ ua . indexOf ( 'tablet' ) ) { platform = 'tablet' ; } else { platform = 'desktop' ; } if ( ~ ( index = ua . indexOf ( 'msie' ) ) ) { name = 'internet explorer' ; platform = 'desktop' ; } else if ( ~ ( index = ua . indexOf ( 'trident/' ) ) ) { name = 'internet explorer' ; platform = 'desktop' ; index += 13 ; } else if ( ~ ( index = ua . indexOf ( 'edge/' ) ) ) { name = 'edge' ; engine = 'edgehtml' ; } else if ( ~ ( index = ua . indexOf ( 'chrome/' ) ) ) { name = 'chrome' ; } else if ( ~ ( index = ua . indexOf ( 'firefox/' ) ) ) { name = 'firefox' ; engine = 'gecko' ; } else if ( ~ ( index = ua . indexOf ( 'safari/' ) ) ) { name = 'safari' ; index = ua . indexOf ( 'version/' ) ; engine = 'webkit' ; } if ( ~ index ) { version = version_rx . exec ( ua . slice ( index ) ) ; if ( version ) { float = parseFloat ( version [ 0 ] ) ; major = + version [ 1 ] ; minor = + version [ 2 ] ; patch = version [ 3 ] || '' ; } } if ( ! engine ) { switch ( name ) { case 'internet explorer' : engine = 'trident' ; break ; case 'chrome' : if ( major < 28 ) { engine = 'webkit' ; } else { engine = 'blink' ; } break ; } } if ( platform != 'desktop' ) { if ( ~ ua . indexOf ( 'iphone' ) || ~ ua . indexOf ( 'ipad' ) || ~ ua . indexOf ( 'ipod' ) ) { os = 'ios' ; if ( ua . indexOf ( 'safari' ) == - 1 ) { webview = true ; } } else if ( ~ ua . indexOf ( '; wv' ) ) { webview = true ; } } result = { family : name , version : { major : major , minor : minor , patch : patch , float : float } , platform : platform , engine : engine , webview : webview , os : os } ; return result ; }
Parse a useragent string

@author   Jelle De Loecker   <jelle@develry.be>
@since    0.6.6
@version  0.6.6

@param    {String}     useragent

@return   {Object}
Parse a useragent string