platform.js 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. /*!
  2. * Platform.js
  3. * Copyright 2014-2018 Benjamin Tan
  4. * Copyright 2011-2013 John-David Dalton
  5. * Available under MIT license
  6. */
  7. ;(function() {
  8. 'use strict';
  9. /** Used to determine if values are of the language type `Object`. */
  10. var objectTypes = {
  11. 'function': true,
  12. 'object': true
  13. };
  14. /** Used as a reference to the global object. */
  15. var root = (objectTypes[typeof window] && window) || this;
  16. /** Backup possible global object. */
  17. var oldRoot = root;
  18. /** Detect free variable `exports`. */
  19. var freeExports = objectTypes[typeof exports] && exports;
  20. /** Detect free variable `module`. */
  21. var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
  22. /** Detect free variable `global` from Node.js or Browserified code and use it as `root`. */
  23. var freeGlobal = freeExports && freeModule && typeof global == 'object' && global;
  24. if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
  25. root = freeGlobal;
  26. }
  27. /**
  28. * Used as the maximum length of an array-like object.
  29. * See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength)
  30. * for more details.
  31. */
  32. var maxSafeInteger = Math.pow(2, 53) - 1;
  33. /** Regular expression to detect Opera. */
  34. var reOpera = /\bOpera/;
  35. /** Possible global object. */
  36. var thisBinding = this;
  37. /** Used for native method references. */
  38. var objectProto = Object.prototype;
  39. /** Used to check for own properties of an object. */
  40. var hasOwnProperty = objectProto.hasOwnProperty;
  41. /** Used to resolve the internal `[[Class]]` of values. */
  42. var toString = objectProto.toString;
  43. /*--------------------------------------------------------------------------*/
  44. /**
  45. * Capitalizes a string value.
  46. *
  47. * @private
  48. * @param {string} string The string to capitalize.
  49. * @returns {string} The capitalized string.
  50. */
  51. function capitalize(string) {
  52. string = String(string);
  53. return string.charAt(0).toUpperCase() + string.slice(1);
  54. }
  55. /**
  56. * A utility function to clean up the OS name.
  57. *
  58. * @private
  59. * @param {string} os The OS name to clean up.
  60. * @param {string} [pattern] A `RegExp` pattern matching the OS name.
  61. * @param {string} [label] A label for the OS.
  62. */
  63. function cleanupOS(os, pattern, label) {
  64. // Platform tokens are defined at:
  65. // http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx
  66. // http://web.archive.org/web/20081122053950/http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx
  67. var data = {
  68. '10.0': '10',
  69. '6.4': '10 Technical Preview',
  70. '6.3': '8.1',
  71. '6.2': '8',
  72. '6.1': 'Server 2008 R2 / 7',
  73. '6.0': 'Server 2008 / Vista',
  74. '5.2': 'Server 2003 / XP 64-bit',
  75. '5.1': 'XP',
  76. '5.01': '2000 SP1',
  77. '5.0': '2000',
  78. '4.0': 'NT',
  79. '4.90': 'ME'
  80. };
  81. // Detect Windows version from platform tokens.
  82. if (pattern && label && /^Win/i.test(os) && !/^Windows Phone /i.test(os) &&
  83. (data = data[/[\d.]+$/.exec(os)])) {
  84. os = 'Windows ' + data;
  85. }
  86. // Correct character case and cleanup string.
  87. os = String(os);
  88. if (pattern && label) {
  89. os = os.replace(RegExp(pattern, 'i'), label);
  90. }
  91. os = format(
  92. os.replace(/ ce$/i, ' CE')
  93. .replace(/\bhpw/i, 'web')
  94. .replace(/\bMacintosh\b/, 'Mac OS')
  95. .replace(/_PowerPC\b/i, ' OS')
  96. .replace(/\b(OS X) [^ \d]+/i, '$1')
  97. .replace(/\bMac (OS X)\b/, '$1')
  98. .replace(/\/(\d)/, ' $1')
  99. .replace(/_/g, '.')
  100. .replace(/(?: BePC|[ .]*fc[ \d.]+)$/i, '')
  101. .replace(/\bx86\.64\b/gi, 'x86_64')
  102. .replace(/\b(Windows Phone) OS\b/, '$1')
  103. .replace(/\b(Chrome OS \w+) [\d.]+\b/, '$1')
  104. .split(' on ')[0]
  105. );
  106. return os;
  107. }
  108. /**
  109. * An iteration utility for arrays and objects.
  110. *
  111. * @private
  112. * @param {Array|Object} object The object to iterate over.
  113. * @param {Function} callback The function called per iteration.
  114. */
  115. function each(object, callback) {
  116. var index = -1,
  117. length = object ? object.length : 0;
  118. if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) {
  119. while (++index < length) {
  120. callback(object[index], index, object);
  121. }
  122. } else {
  123. forOwn(object, callback);
  124. }
  125. }
  126. /**
  127. * Trim and conditionally capitalize string values.
  128. *
  129. * @private
  130. * @param {string} string The string to format.
  131. * @returns {string} The formatted string.
  132. */
  133. function format(string) {
  134. string = trim(string);
  135. return /^(?:webOS|i(?:OS|P))/.test(string)
  136. ? string
  137. : capitalize(string);
  138. }
  139. /**
  140. * Iterates over an object's own properties, executing the `callback` for each.
  141. *
  142. * @private
  143. * @param {Object} object The object to iterate over.
  144. * @param {Function} callback The function executed per own property.
  145. */
  146. function forOwn(object, callback) {
  147. for (var key in object) {
  148. if (hasOwnProperty.call(object, key)) {
  149. callback(object[key], key, object);
  150. }
  151. }
  152. }
  153. /**
  154. * Gets the internal `[[Class]]` of a value.
  155. *
  156. * @private
  157. * @param {*} value The value.
  158. * @returns {string} The `[[Class]]`.
  159. */
  160. function getClassOf(value) {
  161. return value == null
  162. ? capitalize(value)
  163. : toString.call(value).slice(8, -1);
  164. }
  165. /**
  166. * Host objects can return type values that are different from their actual
  167. * data type. The objects we are concerned with usually return non-primitive
  168. * types of "object", "function", or "unknown".
  169. *
  170. * @private
  171. * @param {*} object The owner of the property.
  172. * @param {string} property The property to check.
  173. * @returns {boolean} Returns `true` if the property value is a non-primitive, else `false`.
  174. */
  175. function isHostType(object, property) {
  176. var type = object != null ? typeof object[property] : 'number';
  177. return !/^(?:boolean|number|string|undefined)$/.test(type) &&
  178. (type == 'object' ? !!object[property] : true);
  179. }
  180. /**
  181. * Prepares a string for use in a `RegExp` by making hyphens and spaces optional.
  182. *
  183. * @private
  184. * @param {string} string The string to qualify.
  185. * @returns {string} The qualified string.
  186. */
  187. function qualify(string) {
  188. return String(string).replace(/([ -])(?!$)/g, '$1?');
  189. }
  190. /**
  191. * A bare-bones `Array#reduce` like utility function.
  192. *
  193. * @private
  194. * @param {Array} array The array to iterate over.
  195. * @param {Function} callback The function called per iteration.
  196. * @returns {*} The accumulated result.
  197. */
  198. function reduce(array, callback) {
  199. var accumulator = null;
  200. each(array, function(value, index) {
  201. accumulator = callback(accumulator, value, index, array);
  202. });
  203. return accumulator;
  204. }
  205. /**
  206. * Removes leading and trailing whitespace from a string.
  207. *
  208. * @private
  209. * @param {string} string The string to trim.
  210. * @returns {string} The trimmed string.
  211. */
  212. function trim(string) {
  213. return String(string).replace(/^ +| +$/g, '');
  214. }
  215. /*--------------------------------------------------------------------------*/
  216. /**
  217. * Creates a new platform object.
  218. *
  219. * @memberOf platform
  220. * @param {Object|string} [ua=navigator.userAgent] The user agent string or
  221. * context object.
  222. * @returns {Object} A platform object.
  223. */
  224. function parse(ua) {
  225. /** The environment context object. */
  226. var context = root;
  227. /** Used to flag when a custom context is provided. */
  228. var isCustomContext = ua && typeof ua == 'object' && getClassOf(ua) != 'String';
  229. // Juggle arguments.
  230. if (isCustomContext) {
  231. context = ua;
  232. ua = null;
  233. }
  234. /** Browser navigator object. */
  235. var nav = context.navigator || {};
  236. /** Browser user agent string. */
  237. var userAgent = nav.userAgent || '';
  238. ua || (ua = userAgent);
  239. /** Used to flag when `thisBinding` is the [ModuleScope]. */
  240. var isModuleScope = isCustomContext || thisBinding == oldRoot;
  241. /** Used to detect if browser is like Chrome. */
  242. var likeChrome = isCustomContext
  243. ? !!nav.likeChrome
  244. : /\bChrome\b/.test(ua) && !/internal|\n/i.test(toString.toString());
  245. /** Internal `[[Class]]` value shortcuts. */
  246. var objectClass = 'Object',
  247. airRuntimeClass = isCustomContext ? objectClass : 'ScriptBridgingProxyObject',
  248. enviroClass = isCustomContext ? objectClass : 'Environment',
  249. javaClass = (isCustomContext && context.java) ? 'JavaPackage' : getClassOf(context.java),
  250. phantomClass = isCustomContext ? objectClass : 'RuntimeObject';
  251. /** Detect Java environments. */
  252. var java = /\bJava/.test(javaClass) && context.java;
  253. /** Detect Rhino. */
  254. var rhino = java && getClassOf(context.environment) == enviroClass;
  255. /** A character to represent alpha. */
  256. var alpha = java ? 'a' : '\u03b1';
  257. /** A character to represent beta. */
  258. var beta = java ? 'b' : '\u03b2';
  259. /** Browser document object. */
  260. var doc = context.document || {};
  261. /**
  262. * Detect Opera browser (Presto-based).
  263. * http://www.howtocreate.co.uk/operaStuff/operaObject.html
  264. * http://dev.opera.com/articles/view/opera-mini-web-content-authoring-guidelines/#operamini
  265. */
  266. var opera = context.operamini || context.opera;
  267. /** Opera `[[Class]]`. */
  268. var operaClass = reOpera.test(operaClass = (isCustomContext && opera) ? opera['[[Class]]'] : getClassOf(opera))
  269. ? operaClass
  270. : (opera = null);
  271. /*------------------------------------------------------------------------*/
  272. /** Temporary variable used over the script's lifetime. */
  273. var data;
  274. /** The CPU architecture. */
  275. var arch = ua;
  276. /** Platform description array. */
  277. var description = [];
  278. /** Platform alpha/beta indicator. */
  279. var prerelease = null;
  280. /** A flag to indicate that environment features should be used to resolve the platform. */
  281. var useFeatures = ua == userAgent;
  282. /** The browser/environment version. */
  283. var version = useFeatures && opera && typeof opera.version == 'function' && opera.version();
  284. /** A flag to indicate if the OS ends with "/ Version" */
  285. var isSpecialCasedOS;
  286. /* Detectable layout engines (order is important). */
  287. var layout = getLayout([
  288. { 'label': 'EdgeHTML', 'pattern': '(?:Edge|EdgA|EdgiOS)' },
  289. 'Trident',
  290. { 'label': 'WebKit', 'pattern': 'AppleWebKit' },
  291. 'iCab',
  292. 'Presto',
  293. 'NetFront',
  294. 'Tasman',
  295. 'KHTML',
  296. 'Gecko'
  297. ]);
  298. /* Detectable browser names (order is important). */
  299. var name = getName([
  300. 'Adobe AIR',
  301. 'Arora',
  302. 'Avant Browser',
  303. 'Breach',
  304. 'Camino',
  305. 'Electron',
  306. 'Epiphany',
  307. 'Fennec',
  308. 'Flock',
  309. 'Galeon',
  310. 'GreenBrowser',
  311. 'iCab',
  312. 'Iceweasel',
  313. 'K-Meleon',
  314. 'Konqueror',
  315. 'Lunascape',
  316. 'Maxthon',
  317. { 'label': 'Microsoft Edge', 'pattern': '(?:Edge|EdgA|EdgiOS)' },
  318. 'Midori',
  319. 'Nook Browser',
  320. 'PaleMoon',
  321. 'PhantomJS',
  322. 'Raven',
  323. 'Rekonq',
  324. 'RockMelt',
  325. { 'label': 'Samsung Internet', 'pattern': 'SamsungBrowser' },
  326. 'SeaMonkey',
  327. { 'label': 'Silk', 'pattern': '(?:Cloud9|Silk-Accelerated)' },
  328. 'Sleipnir',
  329. 'SlimBrowser',
  330. { 'label': 'SRWare Iron', 'pattern': 'Iron' },
  331. 'Sunrise',
  332. 'Swiftfox',
  333. 'Waterfox',
  334. 'WebPositive',
  335. 'Opera Mini',
  336. { 'label': 'Opera Mini', 'pattern': 'OPiOS' },
  337. 'Opera',
  338. { 'label': 'Opera', 'pattern': 'OPR' },
  339. 'Chrome',
  340. { 'label': 'Chrome Mobile', 'pattern': '(?:CriOS|CrMo)' },
  341. { 'label': 'Firefox', 'pattern': '(?:Firefox|Minefield)' },
  342. { 'label': 'Firefox for iOS', 'pattern': 'FxiOS' },
  343. { 'label': 'IE', 'pattern': 'IEMobile' },
  344. { 'label': 'IE', 'pattern': 'MSIE' },
  345. 'Safari'
  346. ]);
  347. /* Detectable products (order is important). */
  348. var product = getProduct([
  349. { 'label': 'BlackBerry', 'pattern': 'BB10' },
  350. 'BlackBerry',
  351. { 'label': 'Galaxy S', 'pattern': 'GT-I9000' },
  352. { 'label': 'Galaxy S2', 'pattern': 'GT-I9100' },
  353. { 'label': 'Galaxy S3', 'pattern': 'GT-I9300' },
  354. { 'label': 'Galaxy S4', 'pattern': 'GT-I9500' },
  355. { 'label': 'Galaxy S5', 'pattern': 'SM-G900' },
  356. { 'label': 'Galaxy S6', 'pattern': 'SM-G920' },
  357. { 'label': 'Galaxy S6 Edge', 'pattern': 'SM-G925' },
  358. { 'label': 'Galaxy S7', 'pattern': 'SM-G930' },
  359. { 'label': 'Galaxy S7 Edge', 'pattern': 'SM-G935' },
  360. 'Google TV',
  361. 'Lumia',
  362. 'iPad',
  363. 'iPod',
  364. 'iPhone',
  365. 'Kindle',
  366. { 'label': 'Kindle Fire', 'pattern': '(?:Cloud9|Silk-Accelerated)' },
  367. 'Nexus',
  368. 'Nook',
  369. 'PlayBook',
  370. 'PlayStation Vita',
  371. 'PlayStation',
  372. 'TouchPad',
  373. 'Transformer',
  374. { 'label': 'Wii U', 'pattern': 'WiiU' },
  375. 'Wii',
  376. 'Xbox One',
  377. { 'label': 'Xbox 360', 'pattern': 'Xbox' },
  378. 'Xoom'
  379. ]);
  380. /* Detectable manufacturers. */
  381. var manufacturer = getManufacturer({
  382. 'Apple': { 'iPad': 1, 'iPhone': 1, 'iPod': 1 },
  383. 'Archos': {},
  384. 'Amazon': { 'Kindle': 1, 'Kindle Fire': 1 },
  385. 'Asus': { 'Transformer': 1 },
  386. 'Barnes & Noble': { 'Nook': 1 },
  387. 'BlackBerry': { 'PlayBook': 1 },
  388. 'Google': { 'Google TV': 1, 'Nexus': 1 },
  389. 'HP': { 'TouchPad': 1 },
  390. 'HTC': {},
  391. 'LG': {},
  392. 'Microsoft': { 'Xbox': 1, 'Xbox One': 1 },
  393. 'Motorola': { 'Xoom': 1 },
  394. 'Nintendo': { 'Wii U': 1, 'Wii': 1 },
  395. 'Nokia': { 'Lumia': 1 },
  396. 'Samsung': { 'Galaxy S': 1, 'Galaxy S2': 1, 'Galaxy S3': 1, 'Galaxy S4': 1 },
  397. 'Sony': { 'PlayStation': 1, 'PlayStation Vita': 1 }
  398. });
  399. /* Detectable operating systems (order is important). */
  400. var os = getOS([
  401. 'Windows Phone',
  402. 'Android',
  403. 'CentOS',
  404. { 'label': 'Chrome OS', 'pattern': 'CrOS' },
  405. 'Debian',
  406. 'Fedora',
  407. 'FreeBSD',
  408. 'Gentoo',
  409. 'Haiku',
  410. 'Kubuntu',
  411. 'Linux Mint',
  412. 'OpenBSD',
  413. 'Red Hat',
  414. 'SuSE',
  415. 'Ubuntu',
  416. 'Xubuntu',
  417. 'Cygwin',
  418. 'Symbian OS',
  419. 'hpwOS',
  420. 'webOS ',
  421. 'webOS',
  422. 'Tablet OS',
  423. 'Tizen',
  424. 'Linux',
  425. 'Mac OS X',
  426. 'Macintosh',
  427. 'Mac',
  428. 'Windows 98;',
  429. 'Windows '
  430. ]);
  431. /*------------------------------------------------------------------------*/
  432. /**
  433. * Picks the layout engine from an array of guesses.
  434. *
  435. * @private
  436. * @param {Array} guesses An array of guesses.
  437. * @returns {null|string} The detected layout engine.
  438. */
  439. function getLayout(guesses) {
  440. return reduce(guesses, function(result, guess) {
  441. return result || RegExp('\\b' + (
  442. guess.pattern || qualify(guess)
  443. ) + '\\b', 'i').exec(ua) && (guess.label || guess);
  444. });
  445. }
  446. /**
  447. * Picks the manufacturer from an array of guesses.
  448. *
  449. * @private
  450. * @param {Array} guesses An object of guesses.
  451. * @returns {null|string} The detected manufacturer.
  452. */
  453. function getManufacturer(guesses) {
  454. return reduce(guesses, function(result, value, key) {
  455. // Lookup the manufacturer by product or scan the UA for the manufacturer.
  456. return result || (
  457. value[product] ||
  458. value[/^[a-z]+(?: +[a-z]+\b)*/i.exec(product)] ||
  459. RegExp('\\b' + qualify(key) + '(?:\\b|\\w*\\d)', 'i').exec(ua)
  460. ) && key;
  461. });
  462. }
  463. /**
  464. * Picks the browser name from an array of guesses.
  465. *
  466. * @private
  467. * @param {Array} guesses An array of guesses.
  468. * @returns {null|string} The detected browser name.
  469. */
  470. function getName(guesses) {
  471. return reduce(guesses, function(result, guess) {
  472. return result || RegExp('\\b' + (
  473. guess.pattern || qualify(guess)
  474. ) + '\\b', 'i').exec(ua) && (guess.label || guess);
  475. });
  476. }
  477. /**
  478. * Picks the OS name from an array of guesses.
  479. *
  480. * @private
  481. * @param {Array} guesses An array of guesses.
  482. * @returns {null|string} The detected OS name.
  483. */
  484. function getOS(guesses) {
  485. return reduce(guesses, function(result, guess) {
  486. var pattern = guess.pattern || qualify(guess);
  487. if (!result && (result =
  488. RegExp('\\b' + pattern + '(?:/[\\d.]+|[ \\w.]*)', 'i').exec(ua)
  489. )) {
  490. result = cleanupOS(result, pattern, guess.label || guess);
  491. }
  492. return result;
  493. });
  494. }
  495. /**
  496. * Picks the product name from an array of guesses.
  497. *
  498. * @private
  499. * @param {Array} guesses An array of guesses.
  500. * @returns {null|string} The detected product name.
  501. */
  502. function getProduct(guesses) {
  503. return reduce(guesses, function(result, guess) {
  504. var pattern = guess.pattern || qualify(guess);
  505. if (!result && (result =
  506. RegExp('\\b' + pattern + ' *\\d+[.\\w_]*', 'i').exec(ua) ||
  507. RegExp('\\b' + pattern + ' *\\w+-[\\w]*', 'i').exec(ua) ||
  508. RegExp('\\b' + pattern + '(?:; *(?:[a-z]+[_-])?[a-z]+\\d+|[^ ();-]*)', 'i').exec(ua)
  509. )) {
  510. // Split by forward slash and append product version if needed.
  511. if ((result = String((guess.label && !RegExp(pattern, 'i').test(guess.label)) ? guess.label : result).split('/'))[1] && !/[\d.]+/.test(result[0])) {
  512. result[0] += ' ' + result[1];
  513. }
  514. // Correct character case and cleanup string.
  515. guess = guess.label || guess;
  516. result = format(result[0]
  517. .replace(RegExp(pattern, 'i'), guess)
  518. .replace(RegExp('; *(?:' + guess + '[_-])?', 'i'), ' ')
  519. .replace(RegExp('(' + guess + ')[-_.]?(\\w)', 'i'), '$1 $2'));
  520. }
  521. return result;
  522. });
  523. }
  524. /**
  525. * Resolves the version using an array of UA patterns.
  526. *
  527. * @private
  528. * @param {Array} patterns An array of UA patterns.
  529. * @returns {null|string} The detected version.
  530. */
  531. function getVersion(patterns) {
  532. return reduce(patterns, function(result, pattern) {
  533. return result || (RegExp(pattern +
  534. '(?:-[\\d.]+/|(?: for [\\w-]+)?[ /-])([\\d.]+[^ ();/_-]*)', 'i').exec(ua) || 0)[1] || null;
  535. });
  536. }
  537. /**
  538. * Returns `platform.description` when the platform object is coerced to a string.
  539. *
  540. * @name toString
  541. * @memberOf platform
  542. * @returns {string} Returns `platform.description` if available, else an empty string.
  543. */
  544. function toStringPlatform() {
  545. return this.description || '';
  546. }
  547. /*------------------------------------------------------------------------*/
  548. // Convert layout to an array so we can add extra details.
  549. layout && (layout = [layout]);
  550. // Detect product names that contain their manufacturer's name.
  551. if (manufacturer && !product) {
  552. product = getProduct([manufacturer]);
  553. }
  554. // Clean up Google TV.
  555. if ((data = /\bGoogle TV\b/.exec(product))) {
  556. product = data[0];
  557. }
  558. // Detect simulators.
  559. if (/\bSimulator\b/i.test(ua)) {
  560. product = (product ? product + ' ' : '') + 'Simulator';
  561. }
  562. // Detect Opera Mini 8+ running in Turbo/Uncompressed mode on iOS.
  563. if (name == 'Opera Mini' && /\bOPiOS\b/.test(ua)) {
  564. description.push('running in Turbo/Uncompressed mode');
  565. }
  566. // Detect IE Mobile 11.
  567. if (name == 'IE' && /\blike iPhone OS\b/.test(ua)) {
  568. data = parse(ua.replace(/like iPhone OS/, ''));
  569. manufacturer = data.manufacturer;
  570. product = data.product;
  571. }
  572. // Detect iOS.
  573. else if (/^iP/.test(product)) {
  574. name || (name = 'Safari');
  575. os = 'iOS' + ((data = / OS ([\d_]+)/i.exec(ua))
  576. ? ' ' + data[1].replace(/_/g, '.')
  577. : '');
  578. }
  579. // Detect Kubuntu.
  580. else if (name == 'Konqueror' && !/buntu/i.test(os)) {
  581. os = 'Kubuntu';
  582. }
  583. // Detect Android browsers.
  584. else if ((manufacturer && manufacturer != 'Google' &&
  585. ((/Chrome/.test(name) && !/\bMobile Safari\b/i.test(ua)) || /\bVita\b/.test(product))) ||
  586. (/\bAndroid\b/.test(os) && /^Chrome/.test(name) && /\bVersion\//i.test(ua))) {
  587. name = 'Android Browser';
  588. os = /\bAndroid\b/.test(os) ? os : 'Android';
  589. }
  590. // Detect Silk desktop/accelerated modes.
  591. else if (name == 'Silk') {
  592. if (!/\bMobi/i.test(ua)) {
  593. os = 'Android';
  594. description.unshift('desktop mode');
  595. }
  596. if (/Accelerated *= *true/i.test(ua)) {
  597. description.unshift('accelerated');
  598. }
  599. }
  600. // Detect PaleMoon identifying as Firefox.
  601. else if (name == 'PaleMoon' && (data = /\bFirefox\/([\d.]+)\b/.exec(ua))) {
  602. description.push('identifying as Firefox ' + data[1]);
  603. }
  604. // Detect Firefox OS and products running Firefox.
  605. else if (name == 'Firefox' && (data = /\b(Mobile|Tablet|TV)\b/i.exec(ua))) {
  606. os || (os = 'Firefox OS');
  607. product || (product = data[1]);
  608. }
  609. // Detect false positives for Firefox/Safari.
  610. else if (!name || (data = !/\bMinefield\b/i.test(ua) && /\b(?:Firefox|Safari)\b/.exec(name))) {
  611. // Escape the `/` for Firefox 1.
  612. if (name && !product && /[\/,]|^[^(]+?\)/.test(ua.slice(ua.indexOf(data + '/') + 8))) {
  613. // Clear name of false positives.
  614. name = null;
  615. }
  616. // Reassign a generic name.
  617. if ((data = product || manufacturer || os) &&
  618. (product || manufacturer || /\b(?:Android|Symbian OS|Tablet OS|webOS)\b/.test(os))) {
  619. name = /[a-z]+(?: Hat)?/i.exec(/\bAndroid\b/.test(os) ? os : data) + ' Browser';
  620. }
  621. }
  622. // Add Chrome version to description for Electron.
  623. else if (name == 'Electron' && (data = (/\bChrome\/([\d.]+)\b/.exec(ua) || 0)[1])) {
  624. description.push('Chromium ' + data);
  625. }
  626. // Detect non-Opera (Presto-based) versions (order is important).
  627. if (!version) {
  628. version = getVersion([
  629. '(?:Cloud9|CriOS|CrMo|Edge|EdgA|EdgiOS|FxiOS|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$))',
  630. 'Version',
  631. qualify(name),
  632. '(?:Firefox|Minefield|NetFront)'
  633. ]);
  634. }
  635. // Detect stubborn layout engines.
  636. if ((data =
  637. layout == 'iCab' && parseFloat(version) > 3 && 'WebKit' ||
  638. /\bOpera\b/.test(name) && (/\bOPR\b/.test(ua) ? 'Blink' : 'Presto') ||
  639. /\b(?:Midori|Nook|Safari)\b/i.test(ua) && !/^(?:Trident|EdgeHTML)$/.test(layout) && 'WebKit' ||
  640. !layout && /\bMSIE\b/i.test(ua) && (os == 'Mac OS' ? 'Tasman' : 'Trident') ||
  641. layout == 'WebKit' && /\bPlayStation\b(?! Vita\b)/i.test(name) && 'NetFront'
  642. )) {
  643. layout = [data];
  644. }
  645. // Detect Windows Phone 7 desktop mode.
  646. if (name == 'IE' && (data = (/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(ua) || 0)[1])) {
  647. name += ' Mobile';
  648. os = 'Windows Phone ' + (/\+$/.test(data) ? data : data + '.x');
  649. description.unshift('desktop mode');
  650. }
  651. // Detect Windows Phone 8.x desktop mode.
  652. else if (/\bWPDesktop\b/i.test(ua)) {
  653. name = 'IE Mobile';
  654. os = 'Windows Phone 8.x';
  655. description.unshift('desktop mode');
  656. version || (version = (/\brv:([\d.]+)/.exec(ua) || 0)[1]);
  657. }
  658. // Detect IE 11 identifying as other browsers.
  659. else if (name != 'IE' && layout == 'Trident' && (data = /\brv:([\d.]+)/.exec(ua))) {
  660. if (name) {
  661. description.push('identifying as ' + name + (version ? ' ' + version : ''));
  662. }
  663. name = 'IE';
  664. version = data[1];
  665. }
  666. // Leverage environment features.
  667. if (useFeatures) {
  668. // Detect server-side environments.
  669. // Rhino has a global function while others have a global object.
  670. if (isHostType(context, 'global')) {
  671. if (java) {
  672. data = java.lang.System;
  673. arch = data.getProperty('os.arch');
  674. os = os || data.getProperty('os.name') + ' ' + data.getProperty('os.version');
  675. }
  676. if (rhino) {
  677. try {
  678. version = context.require('ringo/engine').version.join('.');
  679. name = 'RingoJS';
  680. } catch(e) {
  681. if ((data = context.system) && data.global.system == context.system) {
  682. name = 'Narwhal';
  683. os || (os = data[0].os || null);
  684. }
  685. }
  686. if (!name) {
  687. name = 'Rhino';
  688. }
  689. }
  690. else if (
  691. typeof context.process == 'object' && !context.process.browser &&
  692. (data = context.process)
  693. ) {
  694. if (typeof data.versions == 'object') {
  695. if (typeof data.versions.electron == 'string') {
  696. description.push('Node ' + data.versions.node);
  697. name = 'Electron';
  698. version = data.versions.electron;
  699. } else if (typeof data.versions.nw == 'string') {
  700. description.push('Chromium ' + version, 'Node ' + data.versions.node);
  701. name = 'NW.js';
  702. version = data.versions.nw;
  703. }
  704. }
  705. if (!name) {
  706. name = 'Node.js';
  707. arch = data.arch;
  708. os = data.platform;
  709. version = /[\d.]+/.exec(data.version);
  710. version = version ? version[0] : null;
  711. }
  712. }
  713. }
  714. // Detect Adobe AIR.
  715. else if (getClassOf((data = context.runtime)) == airRuntimeClass) {
  716. name = 'Adobe AIR';
  717. os = data.flash.system.Capabilities.os;
  718. }
  719. // Detect PhantomJS.
  720. else if (getClassOf((data = context.phantom)) == phantomClass) {
  721. name = 'PhantomJS';
  722. version = (data = data.version || null) && (data.major + '.' + data.minor + '.' + data.patch);
  723. }
  724. // Detect IE compatibility modes.
  725. else if (typeof doc.documentMode == 'number' && (data = /\bTrident\/(\d+)/i.exec(ua))) {
  726. // We're in compatibility mode when the Trident version + 4 doesn't
  727. // equal the document mode.
  728. version = [version, doc.documentMode];
  729. if ((data = +data[1] + 4) != version[1]) {
  730. description.push('IE ' + version[1] + ' mode');
  731. layout && (layout[1] = '');
  732. version[1] = data;
  733. }
  734. version = name == 'IE' ? String(version[1].toFixed(1)) : version[0];
  735. }
  736. // Detect IE 11 masking as other browsers.
  737. else if (typeof doc.documentMode == 'number' && /^(?:Chrome|Firefox)\b/.test(name)) {
  738. description.push('masking as ' + name + ' ' + version);
  739. name = 'IE';
  740. version = '11.0';
  741. layout = ['Trident'];
  742. os = 'Windows';
  743. }
  744. os = os && format(os);
  745. }
  746. // Detect prerelease phases.
  747. if (version && (data =
  748. /(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(version) ||
  749. /(?:alpha|beta)(?: ?\d)?/i.exec(ua + ';' + (useFeatures && nav.appMinorVersion)) ||
  750. /\bMinefield\b/i.test(ua) && 'a'
  751. )) {
  752. prerelease = /b/i.test(data) ? 'beta' : 'alpha';
  753. version = version.replace(RegExp(data + '\\+?$'), '') +
  754. (prerelease == 'beta' ? beta : alpha) + (/\d+\+?/.exec(data) || '');
  755. }
  756. // Detect Firefox Mobile.
  757. if (name == 'Fennec' || name == 'Firefox' && /\b(?:Android|Firefox OS)\b/.test(os)) {
  758. name = 'Firefox Mobile';
  759. }
  760. // Obscure Maxthon's unreliable version.
  761. else if (name == 'Maxthon' && version) {
  762. version = version.replace(/\.[\d.]+/, '.x');
  763. }
  764. // Detect Xbox 360 and Xbox One.
  765. else if (/\bXbox\b/i.test(product)) {
  766. if (product == 'Xbox 360') {
  767. os = null;
  768. }
  769. if (product == 'Xbox 360' && /\bIEMobile\b/.test(ua)) {
  770. description.unshift('mobile mode');
  771. }
  772. }
  773. // Add mobile postfix.
  774. else if ((/^(?:Chrome|IE|Opera)$/.test(name) || name && !product && !/Browser|Mobi/.test(name)) &&
  775. (os == 'Windows CE' || /Mobi/i.test(ua))) {
  776. name += ' Mobile';
  777. }
  778. // Detect IE platform preview.
  779. else if (name == 'IE' && useFeatures) {
  780. try {
  781. if (context.external === null) {
  782. description.unshift('platform preview');
  783. }
  784. } catch(e) {
  785. description.unshift('embedded');
  786. }
  787. }
  788. // Detect BlackBerry OS version.
  789. // http://docs.blackberry.com/en/developers/deliverables/18169/HTTP_headers_sent_by_BB_Browser_1234911_11.jsp
  790. else if ((/\bBlackBerry\b/.test(product) || /\bBB10\b/.test(ua)) && (data =
  791. (RegExp(product.replace(/ +/g, ' *') + '/([.\\d]+)', 'i').exec(ua) || 0)[1] ||
  792. version
  793. )) {
  794. data = [data, /BB10/.test(ua)];
  795. os = (data[1] ? (product = null, manufacturer = 'BlackBerry') : 'Device Software') + ' ' + data[0];
  796. version = null;
  797. }
  798. // Detect Opera identifying/masking itself as another browser.
  799. // http://www.opera.com/support/kb/view/843/
  800. else if (this != forOwn && product != 'Wii' && (
  801. (useFeatures && opera) ||
  802. (/Opera/.test(name) && /\b(?:MSIE|Firefox)\b/i.test(ua)) ||
  803. (name == 'Firefox' && /\bOS X (?:\d+\.){2,}/.test(os)) ||
  804. (name == 'IE' && (
  805. (os && !/^Win/.test(os) && version > 5.5) ||
  806. /\bWindows XP\b/.test(os) && version > 8 ||
  807. version == 8 && !/\bTrident\b/.test(ua)
  808. ))
  809. ) && !reOpera.test((data = parse.call(forOwn, ua.replace(reOpera, '') + ';'))) && data.name) {
  810. // When "identifying", the UA contains both Opera and the other browser's name.
  811. data = 'ing as ' + data.name + ((data = data.version) ? ' ' + data : '');
  812. if (reOpera.test(name)) {
  813. if (/\bIE\b/.test(data) && os == 'Mac OS') {
  814. os = null;
  815. }
  816. data = 'identify' + data;
  817. }
  818. // When "masking", the UA contains only the other browser's name.
  819. else {
  820. data = 'mask' + data;
  821. if (operaClass) {
  822. name = format(operaClass.replace(/([a-z])([A-Z])/g, '$1 $2'));
  823. } else {
  824. name = 'Opera';
  825. }
  826. if (/\bIE\b/.test(data)) {
  827. os = null;
  828. }
  829. if (!useFeatures) {
  830. version = null;
  831. }
  832. }
  833. layout = ['Presto'];
  834. description.push(data);
  835. }
  836. // Detect WebKit Nightly and approximate Chrome/Safari versions.
  837. if ((data = (/\bAppleWebKit\/([\d.]+\+?)/i.exec(ua) || 0)[1])) {
  838. // Correct build number for numeric comparison.
  839. // (e.g. "532.5" becomes "532.05")
  840. data = [parseFloat(data.replace(/\.(\d)$/, '.0$1')), data];
  841. // Nightly builds are postfixed with a "+".
  842. if (name == 'Safari' && data[1].slice(-1) == '+') {
  843. name = 'WebKit Nightly';
  844. prerelease = 'alpha';
  845. version = data[1].slice(0, -1);
  846. }
  847. // Clear incorrect browser versions.
  848. else if (version == data[1] ||
  849. version == (data[2] = (/\bSafari\/([\d.]+\+?)/i.exec(ua) || 0)[1])) {
  850. version = null;
  851. }
  852. // Use the full Chrome version when available.
  853. data[1] = (/\bChrome\/([\d.]+)/i.exec(ua) || 0)[1];
  854. // Detect Blink layout engine.
  855. if (data[0] == 537.36 && data[2] == 537.36 && parseFloat(data[1]) >= 28 && layout == 'WebKit') {
  856. layout = ['Blink'];
  857. }
  858. // Detect JavaScriptCore.
  859. // http://stackoverflow.com/questions/6768474/how-can-i-detect-which-javascript-engine-v8-or-jsc-is-used-at-runtime-in-androi
  860. if (!useFeatures || (!likeChrome && !data[1])) {
  861. layout && (layout[1] = 'like Safari');
  862. data = (data = data[0], data < 400 ? 1 : data < 500 ? 2 : data < 526 ? 3 : data < 533 ? 4 : data < 534 ? '4+' : data < 535 ? 5 : data < 537 ? 6 : data < 538 ? 7 : data < 601 ? 8 : '8');
  863. } else {
  864. layout && (layout[1] = 'like Chrome');
  865. data = data[1] || (data = data[0], data < 530 ? 1 : data < 532 ? 2 : data < 532.05 ? 3 : data < 533 ? 4 : data < 534.03 ? 5 : data < 534.07 ? 6 : data < 534.10 ? 7 : data < 534.13 ? 8 : data < 534.16 ? 9 : data < 534.24 ? 10 : data < 534.30 ? 11 : data < 535.01 ? 12 : data < 535.02 ? '13+' : data < 535.07 ? 15 : data < 535.11 ? 16 : data < 535.19 ? 17 : data < 536.05 ? 18 : data < 536.10 ? 19 : data < 537.01 ? 20 : data < 537.11 ? '21+' : data < 537.13 ? 23 : data < 537.18 ? 24 : data < 537.24 ? 25 : data < 537.36 ? 26 : layout != 'Blink' ? '27' : '28');
  866. }
  867. // Add the postfix of ".x" or "+" for approximate versions.
  868. layout && (layout[1] += ' ' + (data += typeof data == 'number' ? '.x' : /[.+]/.test(data) ? '' : '+'));
  869. // Obscure version for some Safari 1-2 releases.
  870. if (name == 'Safari' && (!version || parseInt(version) > 45)) {
  871. version = data;
  872. }
  873. }
  874. // Detect Opera desktop modes.
  875. if (name == 'Opera' && (data = /\bzbov|zvav$/.exec(os))) {
  876. name += ' ';
  877. description.unshift('desktop mode');
  878. if (data == 'zvav') {
  879. name += 'Mini';
  880. version = null;
  881. } else {
  882. name += 'Mobile';
  883. }
  884. os = os.replace(RegExp(' *' + data + '$'), '');
  885. }
  886. // Detect Chrome desktop mode.
  887. else if (name == 'Safari' && /\bChrome\b/.exec(layout && layout[1])) {
  888. description.unshift('desktop mode');
  889. name = 'Chrome Mobile';
  890. version = null;
  891. if (/\bOS X\b/.test(os)) {
  892. manufacturer = 'Apple';
  893. os = 'iOS 4.3+';
  894. } else {
  895. os = null;
  896. }
  897. }
  898. // Strip incorrect OS versions.
  899. if (version && version.indexOf((data = /[\d.]+$/.exec(os))) == 0 &&
  900. ua.indexOf('/' + data + '-') > -1) {
  901. os = trim(os.replace(data, ''));
  902. }
  903. // Add layout engine.
  904. if (layout && !/\b(?:Avant|Nook)\b/.test(name) && (
  905. /Browser|Lunascape|Maxthon/.test(name) ||
  906. name != 'Safari' && /^iOS/.test(os) && /\bSafari\b/.test(layout[1]) ||
  907. /^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|Web)/.test(name) && layout[1])) {
  908. // Don't add layout details to description if they are falsey.
  909. (data = layout[layout.length - 1]) && description.push(data);
  910. }
  911. // Combine contextual information.
  912. if (description.length) {
  913. description = ['(' + description.join('; ') + ')'];
  914. }
  915. // Append manufacturer to description.
  916. if (manufacturer && product && product.indexOf(manufacturer) < 0) {
  917. description.push('on ' + manufacturer);
  918. }
  919. // Append product to description.
  920. if (product) {
  921. description.push((/^on /.test(description[description.length - 1]) ? '' : 'on ') + product);
  922. }
  923. // Parse the OS into an object.
  924. if (os) {
  925. data = / ([\d.+]+)$/.exec(os);
  926. isSpecialCasedOS = data && os.charAt(os.length - data[0].length - 1) == '/';
  927. os = {
  928. 'architecture': 32,
  929. 'family': (data && !isSpecialCasedOS) ? os.replace(data[0], '') : os,
  930. 'version': data ? data[1] : null,
  931. 'toString': function() {
  932. var version = this.version;
  933. return this.family + ((version && !isSpecialCasedOS) ? ' ' + version : '') + (this.architecture == 64 ? ' 64-bit' : '');
  934. }
  935. };
  936. }
  937. // Add browser/OS architecture.
  938. if ((data = /\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i.exec(arch)) && !/\bi686\b/i.test(arch)) {
  939. if (os) {
  940. os.architecture = 64;
  941. os.family = os.family.replace(RegExp(' *' + data), '');
  942. }
  943. if (
  944. name && (/\bWOW64\b/i.test(ua) ||
  945. (useFeatures && /\w(?:86|32)$/.test(nav.cpuClass || nav.platform) && !/\bWin64; x64\b/i.test(ua)))
  946. ) {
  947. description.unshift('32-bit');
  948. }
  949. }
  950. // Chrome 39 and above on OS X is always 64-bit.
  951. else if (
  952. os && /^OS X/.test(os.family) &&
  953. name == 'Chrome' && parseFloat(version) >= 39
  954. ) {
  955. os.architecture = 64;
  956. }
  957. ua || (ua = null);
  958. /*------------------------------------------------------------------------*/
  959. /**
  960. * The platform object.
  961. *
  962. * @name platform
  963. * @type Object
  964. */
  965. var platform = {};
  966. /**
  967. * The platform description.
  968. *
  969. * @memberOf platform
  970. * @type string|null
  971. */
  972. platform.description = ua;
  973. /**
  974. * The name of the browser's layout engine.
  975. *
  976. * The list of common layout engines include:
  977. * "Blink", "EdgeHTML", "Gecko", "Trident" and "WebKit"
  978. *
  979. * @memberOf platform
  980. * @type string|null
  981. */
  982. platform.layout = layout && layout[0];
  983. /**
  984. * The name of the product's manufacturer.
  985. *
  986. * The list of manufacturers include:
  987. * "Apple", "Archos", "Amazon", "Asus", "Barnes & Noble", "BlackBerry",
  988. * "Google", "HP", "HTC", "LG", "Microsoft", "Motorola", "Nintendo",
  989. * "Nokia", "Samsung" and "Sony"
  990. *
  991. * @memberOf platform
  992. * @type string|null
  993. */
  994. platform.manufacturer = manufacturer;
  995. /**
  996. * The name of the browser/environment.
  997. *
  998. * The list of common browser names include:
  999. * "Chrome", "Electron", "Firefox", "Firefox for iOS", "IE",
  1000. * "Microsoft Edge", "PhantomJS", "Safari", "SeaMonkey", "Silk",
  1001. * "Opera Mini" and "Opera"
  1002. *
  1003. * Mobile versions of some browsers have "Mobile" appended to their name:
  1004. * eg. "Chrome Mobile", "Firefox Mobile", "IE Mobile" and "Opera Mobile"
  1005. *
  1006. * @memberOf platform
  1007. * @type string|null
  1008. */
  1009. platform.name = name;
  1010. /**
  1011. * The alpha/beta release indicator.
  1012. *
  1013. * @memberOf platform
  1014. * @type string|null
  1015. */
  1016. platform.prerelease = prerelease;
  1017. /**
  1018. * The name of the product hosting the browser.
  1019. *
  1020. * The list of common products include:
  1021. *
  1022. * "BlackBerry", "Galaxy S4", "Lumia", "iPad", "iPod", "iPhone", "Kindle",
  1023. * "Kindle Fire", "Nexus", "Nook", "PlayBook", "TouchPad" and "Transformer"
  1024. *
  1025. * @memberOf platform
  1026. * @type string|null
  1027. */
  1028. platform.product = product;
  1029. /**
  1030. * The browser's user agent string.
  1031. *
  1032. * @memberOf platform
  1033. * @type string|null
  1034. */
  1035. platform.ua = ua;
  1036. /**
  1037. * The browser/environment version.
  1038. *
  1039. * @memberOf platform
  1040. * @type string|null
  1041. */
  1042. platform.version = name && version;
  1043. /**
  1044. * The name of the operating system.
  1045. *
  1046. * @memberOf platform
  1047. * @type Object
  1048. */
  1049. platform.os = os || {
  1050. /**
  1051. * The CPU architecture the OS is built for.
  1052. *
  1053. * @memberOf platform.os
  1054. * @type number|null
  1055. */
  1056. 'architecture': null,
  1057. /**
  1058. * The family of the OS.
  1059. *
  1060. * Common values include:
  1061. * "Windows", "Windows Server 2008 R2 / 7", "Windows Server 2008 / Vista",
  1062. * "Windows XP", "OS X", "Ubuntu", "Debian", "Fedora", "Red Hat", "SuSE",
  1063. * "Android", "iOS" and "Windows Phone"
  1064. *
  1065. * @memberOf platform.os
  1066. * @type string|null
  1067. */
  1068. 'family': null,
  1069. /**
  1070. * The version of the OS.
  1071. *
  1072. * @memberOf platform.os
  1073. * @type string|null
  1074. */
  1075. 'version': null,
  1076. /**
  1077. * Returns the OS string.
  1078. *
  1079. * @memberOf platform.os
  1080. * @returns {string} The OS string.
  1081. */
  1082. 'toString': function() { return 'null'; }
  1083. };
  1084. platform.parse = parse;
  1085. platform.toString = toStringPlatform;
  1086. if (platform.version) {
  1087. description.unshift(version);
  1088. }
  1089. if (platform.name) {
  1090. description.unshift(name);
  1091. }
  1092. if (os && name && !(os == String(os).split(' ')[0] && (os == name.split(' ')[0] || product))) {
  1093. description.push(product ? '(' + os + ')' : 'on ' + os);
  1094. }
  1095. if (description.length) {
  1096. platform.description = description.join(' ');
  1097. }
  1098. return platform;
  1099. }
  1100. /*--------------------------------------------------------------------------*/
  1101. // Export platform.
  1102. var platform = parse();
  1103. // Some AMD build optimizers, like r.js, check for condition patterns like the following:
  1104. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  1105. // Expose platform on the global object to prevent errors when platform is
  1106. // loaded by a script tag in the presence of an AMD loader.
  1107. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  1108. root.platform = platform;
  1109. // Define as an anonymous module so platform can be aliased through path mapping.
  1110. define(function() {
  1111. return platform;
  1112. });
  1113. }
  1114. // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
  1115. else if (freeExports && freeModule) {
  1116. // Export for CommonJS support.
  1117. forOwn(platform, function(value, key) {
  1118. freeExports[key] = value;
  1119. });
  1120. }
  1121. else {
  1122. // Export to the global object.
  1123. root.platform = platform;
  1124. }
  1125. }.call(this));