@ephox/sand

中文文档
8.0.0发布于 2026/03/31GPL-2.0-or-laterTypeScriptESM + CJS近 30 天下载 2万

Platform detection library

原始使用文档
文档目录18 节
  1. Install from npm
  2. Platform Detection
  3. Browser
  4. Operating System (OS)
  5. Device
  6. Global Wrappers
  7. Blob
  8. Event
  9. FileReader
  10. FormData
  11. HTMLElement
  12. JSON
  13. NodeFilter
  14. URL
  15. Uint8Array
  16. Window
  17. XMLHttpRequest
  18. XMLSerializer

Description

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.

Installation

sand is available as an npm package. You can install it via the npm package @ephox/sand

Install from npm

npm install @ephox/sand.

Using the API

The project sand has two purposes: platform detection and global wrappers.

Platform Detection

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.

Browser

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();

Operating System (OS)

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();

Device

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();

Global Wrappers

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.

Blob

https://developer.mozilla.org/en-US/docs/Web/API/Blob

Event

https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events

FileReader

https://developer.mozilla.org/en-US/docs/Web/API/FileReader

FormData

https://developer.mozilla.org/en-US/docs/Web/API/FormData

HTMLElement

https://developer.mozilla.org/en/docs/Web/API/HTMLElement

  • HTMLElement.isPrototypeOf(x)

JSON

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON

  • JSON.parse(obj)
  • JSON.stringify(obj, replacer, space)

NodeFilter

https://developer.mozilla.org/en-US/docs/Web/API/NodeFilter

URL

https://developer.mozilla.org/en-US/docs/Web/API/URL.createObjectURL

  • URL.createObjectURL(blob)
  • URL.removeObjectURL(u)

Uint8Array

https://developer.mozilla.org/en-US/docs/Web/API/Uint8Array

Window

https://developer.mozilla.org/en/docs/Web/API/window.requestAnimationFrame

  • Window.requestAnimationFrame(callback)
  • Window.atob(base64)

XMLHttpRequest

https://developer.mozilla.org/en/docs/XMLHttpRequest

XMLSerializer

https://developer.mozilla.org/en/docs/XMLSerializer

  • XMLSerializer.serializeToString(node)

Running Tests

$ yarn test

版本与发布记录

@ephox/sand 共发布 64 个版本,首次发布于 2016/12/20;过去 12 个月发布了 1 个版本。

版本发布日期距今
8.0.0latest2026/03/317 个月前
6.0.102024/02/072 年前
6.0.92023/03/153 年前
6.0.72022/11/233 年前
6.0.52022/09/084 年前
6.0.32022/06/294 年前

其他发布通道:rc → 6.0.2-alpha.1。

关于 @ephox/sand 的常见问题

@ephox/sand 是什么?

Platform detection library

如何安装 @ephox/sand?

在项目目录运行 npm install @ephox/sand,或使用 pnpm add / yarn add / bun add。

@ephox/sand 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ephox/sand 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ephox/sand 可以商用吗?

@ephox/sand 使用 GPL-2.0-or-later 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以兼容的 GPL 许可开源。仅在内部使用、不对外分发时不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@ephox/sand 的下载量有多少?

根据 npm 官方下载统计,@ephox/sand 在 2026/10/14 – 2026/11/12 这 30 天内被下载 20,346 次,日均约 678 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ephox/sand 还在维护吗?

最新版本 8.0.0 发布于 2026/03/31(7 个月前);至今共发布 64 个版本,其中过去 12 个月发布了 1 个;首次发布于 2016/12/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。