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 @ephox/sand
npm install @ephox/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 stringversion
: a (major, minor)
tuple representing the versionisEdge
: returns true iff. the browser is Microsoft EdgeisChrome
: returns true iff. the browser is ChromeisIE
: returns true iff. the browser is Internet ExplorerisOpera
: returns true iff. the browser is OperaisFirefox
: returns true iff. the browser is FirefoxisSafari
: 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 stringversion
: a (major, minor)
tuple representing the versionisWindows
: returns true iff. the OS is WindowsisiOS
: returns true iff. the OS is iOSisAndroid
: returns true iff. the OS is AndroidisOSX
: returns true iff. the OS is OSXisLinux
: returns true iff. the OS is LinuxisSolaris
: returns true iff. the OS is SolarisisFreeBSD
: 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 iPadisiPhone
: returns true iff. the device is an iPhoneisTablet
: returns true iff. the device is an TabletisPhone
: returns true iff. the device is an PhoneisTouch
: returns true iff. the device is an TouchisAndroid
: returns true iff. the device is an AndroidisiOS
: returns true iff. the device is an iOSisWebView
: 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