I think the naming here is somewhat misleading: the user agent string contains the OS on which the browser is running, not the device. In the case of Apple’s iOS devices though the agent string seems to contain a hint of the device, all of which run iOS.
Thus I’d like to propose to rename whatever use of “device” to “os”, and perhaps expand the returned structure to
{browser: …, os: …, device: …}
where os takes the role of the current device. Furthermore, it should be MacOS instead of Macintosh, and iOS in case of any one of the iDevices. For os: "iOS" then the device entry can be set to iPad/iPhone/iPod or to undefined otherwise.
This would be a breaking change, yes 😉
One more thing: instead of exporting an anonymous function, why not export a function name like detect()?
I think the naming here is somewhat misleading: the user agent string contains the OS on which the browser is running, not the device. In the case of Apple’s iOS devices though the agent string seems to contain a hint of the device, all of which run iOS.
Thus I’d like to propose to rename whatever use of “device” to “os”, and perhaps expand the returned structure to
where
ostakes the role of the currentdevice. Furthermore, it should beMacOSinstead ofMacintosh, andiOSin case of any one of the iDevices. Foros: "iOS"then thedeviceentry can be set toiPad/iPhone/iPodor toundefinedotherwise.This would be a breaking change, yes 😉
One more thing: instead of exporting an anonymous function, why not export a function name like
detect()?