Skip to content

Commit

Permalink
Merge pull request #105 from wbinnssmith/wbinnssmith/os-detection
Browse files Browse the repository at this point in the history
Expose the UA's os as a property on the results
  • Loading branch information
ded committed Nov 2, 2015
2 parents 5f93339 + 32e2bc4 commit 611795a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 9 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ if (bowser.msie && bowser.version <= 6) {

For all detected browsers the browser version is set in the `version` field.

## Flags set for detected mobile Operating Systems
## Flags set for detected Operating Systems

* `mac`
* Windows other than Windows Phone as `windows`
* Windows Phone as `windowsphone`
* `linux` for Linux other than `android`, `chromeos`, `webos`, `tizen`, and `sailfish`
* `chromeos`
* `android`
* Windows Phone as `windowsphone`
* `ios` (`iphone`/`ipad`/`ipod`)
* `blackberry`
* `firefoxos`
Expand Down
29 changes: 22 additions & 7 deletions src/bowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@
var iosdevice = getFirstMatch(/(ipod|iphone|ipad)/i).toLowerCase()
, likeAndroid = /like android/i.test(ua)
, android = !likeAndroid && /android/i.test(ua)
, chromeBook = /CrOS/.test(ua)
, chromeos = /CrOS/.test(ua)
, silk = /silk/i.test(ua)
, sailfish = /sailfish/i.test(ua)
, tizen = /tizen/i.test(ua)
, webos = /(web|hpw)os/i.test(ua)
, windowsphone = /windows phone/i.test(ua)
, windows = !windowsphone && /windows/i.test(ua)
, mac = !iosdevice && !silk && /macintosh/i.test(ua)
, linux = !android && !sailfish && !tizen && !webos && /linux/i.test(ua)
, edgeVersion = getFirstMatch(/edge\/(\d+(\.\d+)?)/i)
, versionIdentifier = getFirstMatch(/version\/(\d+(\.\d+)?)/i)
, tablet = /tablet/i.test(ua)
Expand All @@ -45,7 +53,7 @@
, version: versionIdentifier || getFirstMatch(/(?:yabrowser)[\s\/](\d+(\.\d+)?)/i)
}
}
else if (/windows phone/i.test(ua)) {
else if (windowsphone) {
result = {
name: 'Windows Phone'
, windowsphone: t
Expand All @@ -65,9 +73,10 @@
, msie: t
, version: getFirstMatch(/(?:msie |rv:)(\d+(\.\d+)?)/i)
}
} else if (chromeBook) {
} else if (chromeos) {
result = {
name: 'Chrome'
, chromeos: t
, chromeBook: t
, chrome: t
, version: getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)
Expand Down Expand Up @@ -95,7 +104,7 @@
result.version = versionIdentifier
}
}
else if (/sailfish/i.test(ua)) {
else if (sailfish) {
result = {
name: 'Sailfish'
, sailfish: t
Expand All @@ -119,7 +128,7 @@
result.firefoxos = t
}
}
else if (/silk/i.test(ua)) {
else if (silk) {
result = {
name: 'Amazon Silk'
, silk: t
Expand All @@ -146,7 +155,7 @@
, version: versionIdentifier || getFirstMatch(/blackberry[\d]+\/(\d+(\.\d+)?)/i)
}
}
else if (/(web|hpw)os/i.test(ua)) {
else if (webos) {
result = {
name: 'WebOS'
, webos: t
Expand All @@ -161,7 +170,7 @@
, version: getFirstMatch(/dolfin\/(\d+(\.\d+)?)/i)
};
}
else if (/tizen/i.test(ua)) {
else if (tizen) {
result = {
name: 'Tizen'
, tizen: t
Expand Down Expand Up @@ -201,6 +210,12 @@
} else if (iosdevice) {
result[iosdevice] = t
result.ios = t
} else if (windows) {
result.windows = t
} else if (mac) {
result.mac = t
} else if (linux) {
result.linux = t
}

// OS version extraction
Expand Down
Loading

0 comments on commit 611795a

Please sign in to comment.