sand
is a library for handling platform detection and standardising native browser functions. It does not bundle any commands. It is only a collection of modules.
sand
is available as an npm
package. You can install it via the npm package @ssephox/sand
npm install @ssephox/sand
.
The project sand
has two purposes: platform detection and global wrappers.
In order to detect the current platform, execute PlatformDetection.detect()
. This will return an object with three parts: browser
, os
, and device
.
var platform = PlatformDetection.detect();
console.log("browser", platform.browser);
console.log("os", platform.os);
console.log("device", platform.device);
Note, PlatformQuery
has been introduced to provide convenience methods for common platform queries and manage the internal structure of detect's response itself.
The browser
field has the following information:
-
current
: the name of the browser as a string -
version
: a(major, minor)
tuple representing the version -
isEdge
: returns true iff. the browser is Microsoft Edge -
isChromium
: returns true iff. the browser is Chromium Based -
isIE
: returns true iff. the browser is Internet Explorer -
isOpera
: returns true iff. the browser is Opera -
isFirefox
: returns true iff. the browser is Firefox -
isSafari
: returns true iff. the browser is Safari
var platform = PlatformDetection.detect();
var isFF = platform.browser.isFirefox();
The os
field has the following information:
-
current
: the name of the OS as a string -
version
: a(major, minor)
tuple representing the version -
isWindows
: returns true iff. the OS is Windows -
isiOS
: returns true iff. the OS is iOS -
isAndroid
: returns true iff. the OS is Android -
isOSX
: returns true iff. the OS is OSX -
isLinux
: returns true iff. the OS is Linux -
isSolaris
: returns true iff. the OS is Solaris -
isFreeBSD
: returns true iff. the OS is FreeBSD
var platform = PlatformDetection.detect();
var isWin = platform.os.isWindows();
The device
field has the following information:
-
isiPad
: returns true iff. the device is an iPad -
isiPhone
: returns true iff. the device is an iPhone -
isTablet
: returns true iff. the device is an Tablet -
isPhone
: returns true iff. the device is an Phone -
isTouch
: returns true iff. the device is an Touch -
isAndroid
: returns true iff. the device is an Android -
isiOS
: returns true iff. the device is an iOS -
isWebView
: returns true iff. the device is an WebView
var platform = PlatformDetection.detect();
var isPh = platform.device.isPhone();
These wrappers allow dependencies on globals that only exist on newer browsers, where normal references to them would cause the script to fail to load. They don't provide any safety in accessing the globals; it is assumed the supporting code knows whether the current browser supports the global. They are simply a way to defer referencing it.
https://developer.mozilla.org/en-US/docs/Web/API/Blob
https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events
https://developer.mozilla.org/en-US/docs/Web/API/FileReader
https://developer.mozilla.org/en-US/docs/Web/API/FormData
https://developer.mozilla.org/en/docs/Web/API/HTMLElement
HTMLElement.isPrototypeOf(x)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON
JSON.parse(obj)
JSON.stringify(obj, replacer, space)
https://developer.mozilla.org/en-US/docs/Web/API/NodeFilter
https://developer.mozilla.org/en-US/docs/Web/API/URL.createObjectURL
URL.createObjectURL(blob)
URL.removeObjectURL(u)
https://developer.mozilla.org/en-US/docs/Web/API/Uint8Array
https://developer.mozilla.org/en/docs/Web/API/window.requestAnimationFrame
Window.requestAnimationFrame(callback)
Window.atob(base64)
https://developer.mozilla.org/en/docs/XMLHttpRequest
https://developer.mozilla.org/en/docs/XMLSerializer
XMLSerializer.serializeToString(node)
$ yarn test