From 18730452f2b40099710613ecbe188d98f4bfad19 Mon Sep 17 00:00:00 2001 From: Faisal Salman Date: Sat, 25 Feb 2023 11:41:19 +0700 Subject: [PATCH] Add new device: Apple Watch, new os: watchOS --- readme.md | 15 ++++++++------- src/ua-parser.js | 4 ++++ test/device-test.json | 9 +++++++++ test/os-test.json | 27 +++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index 4bae24f..fdeccfd 100644 --- a/readme.md +++ b/readme.md @@ -159,7 +159,7 @@ Linpus, Linspire,Linux, Mac OS, Maemo, Mageia, Mandriva, Manjaro, MeeGo, Minix, Mint, Morph OS, NetBSD, NetRange, NetTV, Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD, PCLinuxOS, Plan9, PlayStation, QNX, Raspbian, RedHat, RIM Tablet OS, RISC OS, Sabayon, Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen, -Ubuntu, Unix, VectorLinux, Viera, WebOS, Windows [Phone/Mobile], Zenwalk, ... +Ubuntu, Unix, VectorLinux, Viera, watchOS, WebOS, Windows [Phone/Mobile], Zenwalk, ... # 'os.version' determined dynamically ``` @@ -182,7 +182,7 @@ Ubuntu, Unix, VectorLinux, Viera, WebOS, Windows [Phone/Mobile], Zenwalk, ... #### * is() utility `since@1.1` ```js -// Is just a shorthand to check whether one of the specified properties has equal value +// Is just a shorthand to check whether specified item has a property with equals value (case-insensitive) // so that instead of write it using `==` operator like this: let ua = UAParser(); @@ -198,7 +198,7 @@ if (device.is("mobile") && !os.is("iOS")) {} if (device.is("smarttv") || device.is("Samsung")) {} /* - Properties will be checked in this particular order: + Each properties will be checked in this particular order: * browser : name * cpu : architecture * device : type, model, vendor @@ -220,10 +220,11 @@ uap.getOS().is("Windows Phone"); // true uap.getDevice(); // { vendor: "Nokia", model: "Lumia 635", type: "mobile" } uap.getResult().device; // { vendor: "Nokia", model: "Lumia 635", type: "mobile" } -uap.getDevice().is("mobile"); // true -uap.getDevice().is("Lumia 635"); // true -uap.getDevice().is("Nokia"); // true -uap.getDevice().is("iPhone"); // false +let device = uap.getDevice(); +device.is("mobile"); // true +device.is("Lumia 635"); // true +device.is("Nokia"); // true +device.is("iPhone"); // false uap.getResult().device.is("Nokia"); // true uap.getResult().device.model; // "Lumia 635" diff --git a/src/ua-parser.js b/src/ua-parser.js index a3a3ad4..f03bfc5 100755 --- a/src/ua-parser.js +++ b/src/ua-parser.js @@ -656,6 +656,8 @@ /((pebble))app/i // Pebble ], [VENDOR, MODEL, [TYPE, WEARABLE]], [ + /(watch)(?: ?os[,\/]|\d,\d\/)[\d\.]+/i // Apple Watch + ], [MODEL, [VENDOR, APPLE], [TYPE, WEARABLE]], [ /droid.+; (glass) \d/i // Google Glass ], [MODEL, [VENDOR, GOOGLE], [TYPE, WEARABLE]], [ /droid.+; (wt63?0{2,3})\)/i @@ -742,6 +744,8 @@ /web0s;.+rt(tv)/i, /\b(?:hp)?wos(?:browser)?\/([\w\.]+)/i // WebOS ], [VERSION, [NAME, 'webOS']], [ + /watch(?: ?os[,\/]|\d,\d\/)([\d\.]+)/i // watchOS + ], [VERSION, [NAME, 'watchOS']], [ // Google Chromecast /crkey\/([\d\.]+)/i // Google Chromecast diff --git a/test/device-test.json b/test/device-test.json index f042a17..c40361f 100644 --- a/test/device-test.json +++ b/test/device-test.json @@ -763,6 +763,15 @@ "type": "undefined" } }, + { + "desc": "Apple Watch", + "ua": "atc/1.0 watchOS/7.3.3 model/Watch4,2 hwp/t8006 build/18S830 (6; dt:191)", + "expect": { + "vendor": "Apple", + "model": "watch", + "type": "wearable" + } + }, { "desc": "iPad using UCBrowser", "ua": "Mozilla/5.0 (iPad; U; CPU OS 11_2 like Mac OS X; zh-CN; iPad5,3) AppleWebKit/534.46 (KHTML, like Gecko) UCBrowser/3.0.1.776 U3/ Mobile/10A403 Safari/7543.48.3", diff --git a/test/os-test.json b/test/os-test.json index 2067015..d97c7ff 100644 --- a/test/os-test.json +++ b/test/os-test.json @@ -764,6 +764,33 @@ "version" : "undefined" } }, + { + "desc" : "watchOS", + "ua" : "server-bag [Watch OS,8.4,19S546,Watch3,4]", + "expect" : + { + "name" : "watchOS", + "version" : "8.4" + } + }, + { + "desc" : "watchOS", + "ua" : "atc/1.0 watchOS/7.4.1 model/Watch3,3 hwp/t8004 build/18T201 (6; dt:155)", + "expect" : + { + "name" : "watchOS", + "version" : "7.4.1" + } + }, + { + "desc" : "watchOS", + "ua" : "Watch4,3/5.3.8 (16U680)", + "expect" : + { + "name" : "watchOS", + "version" : "5.3.8" + } + }, { "desc" : "Mac OS on PowerPC", "ua" : "Mozilla/4.0 (compatible; MSIE 5.0b1; Mac_PowerPC)",