Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/GoogleChromeLabs/wasm-feature-detect
A small library to detect which features of WebAssembly are supported.
https://github.com/GoogleChromeLabs/wasm-feature-detect
Last synced: 13 days ago
JSON representation
A small library to detect which features of WebAssembly are supported.
- Host: GitHub
- URL: https://github.com/GoogleChromeLabs/wasm-feature-detect
- Owner: GoogleChromeLabs
- License: apache-2.0
- Created: 2019-09-11T14:14:09.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-09-17T08:42:08.000Z (about 2 months ago)
- Last Synced: 2024-09-17T11:11:55.345Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://webassembly.org/roadmap
- Size: 231 KB
- Stars: 545
- Watchers: 15
- Forks: 52
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# WebAssembly Feature Detection
A small library to detect which features of WebAssembly are supported.
- ✅ Runs in browsers, Node and Deno
- ✅ Tree-shakable (only bundle the detectors you use)
- ✅ Provided as an ES6, CommonJS and UMD module.
- ✅ CSP compatible
- ✅ All detectors add up to only ~980B gzipped## Installation
```
npm install -g wasm-feature-detect
```## Usage
```html
import { simd } from "wasm-feature-detect";
if (await simd()) {
/* SIMD support */
} else {
/* No SIMD support */
}```
### Hotlinking from Unpkg
```html
import { simd } from "https://unpkg.com/wasm-feature-detect?module";
// ...```
If required, there’s also a UMD version
```html
if (await wasmFeatureDetect.simd()) {
// ...
}```
## Detectors
All detectors return a `Promise`.
| Function | Proposal |
| --------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `bigInt()` | [BigInt integration](https://github.com/WebAssembly/JS-BigInt-integration) |
| `bulkMemory()` | [Bulk memory operations](https://github.com/webassembly/bulk-memory-operations) |
| `exceptions()` | [Legacy Exception Handling](https://github.com/WebAssembly/exception-handling) |
| `exceptionsFinal()` | [Exception Handling with exnref](https://github.com/WebAssembly/exception-handling) |
| `extendedConst()` | [Extented Const Expressesions](https://github.com/WebAssembly/extended-const) |
| `gc()` | [Garbage Collection](https://github.com/WebAssembly/gc) |
| `jsStringBuiltins()` | [JS String Builtins Proposal for WebAssembly](https://github.com/WebAssembly/js-string-builtins) |
| `jspi()` | [JavaScript Promise Integration](https://github.com/WebAssembly/js-promise-integration) |
| `memory64()` | [Memory64](https://github.com/WebAssembly/memory64) |
| `multiMemory()` | [Multiple Memories](https://github.com/WebAssembly/multi-memory) |
| `multiValue()` | [Multi-value](https://github.com/WebAssembly/multi-value) |
| `mutableGlobals()` | [Importable/Exportable mutable globals]() |
| `referenceTypes()` | [Reference Types](https://github.com/WebAssembly/reference-types) |
| `relaxedSimd()` | [Relaxed SIMD](https://github.com/webassembly/relaxed-simd) |
| `saturatedFloatToInt()` | [Non-trapping float-to-int conversions](https://github.com/WebAssembly/nontrapping-float-to-int-conversions) |
| `signExtensions()` | [Sign-extension operators](https://github.com/WebAssembly/sign-extension-ops) |
| `simd()` | [Fixed-Width SIMD](https://github.com/webassembly/simd) |
| `streamingCompilation()` | [Streaming Compilation](https://webassembly.github.io/spec/web-api/index.html#streaming-modules) |
| `tailCall()` | [Tail call](https://github.com/webassembly/tail-call) |
| `threads()` | [Threads](https://github.com/webassembly/threads) |
| `typeReflection()` | [Type Reflection](https://github.com/WebAssembly/js-types) |
| `typedFunctionReferences()` | [Typed function references](https://github.com/WebAssembly/function-references) |## Why are all the tests async?
The _technical_ reason is that some tests might have to be augmented to be asynchronous in the future. For example, Firefox is planning to [make a change][ff coop] that would require a `postMessage` call to detect SABs, which are required for threads.
The _other_ reason is that you _should_ be using `WebAssembly.compile`, `WebAssembly.instantiate`, or their streaming versions `WebAssembly.compileStreaming` and `WebAssembly.instantiateStreaming`, which are all asynchronous. You should already be prepared for asynchronous code when using WebAssembly!
## Contributing
If you want to contribute a new feature test, all you need to do is create a new folder in `src/detectors` and it will be automatically picked up. The folder may contain a `module.wat` file, which will be compiled using [`wabt.js`](https://github.com/AssemblyScript/wabt.js).
```wat
;; Name:
;; Proposal:
;; Features:(module
;; More WAT code here
)
```The folder can also contain an optional `index.js` file, whose default export must be an async function. This function can do additional testing in JavaScript and must return a boolean. See the “threads” detector as an example.
It must contain at least one of `module.wat` or `index.js`.[ff coop]: https://groups.google.com/forum/#!msg/mozilla.dev.platform/IHkBZlHETpA/dwsMNchWEQAJ
[wat2wasm]: https://github.com/webassembly/wabt---
License Apache-2.0