wasm-check
Version:
TypeScript / JavaScript library for detect WebAssembly features in node.js & browser
109 lines (85 loc) • 3.46 kB
Markdown
[](https://www.npmjs.com/package/wasm-check)[](LICENSE.md)
Detect WebAssembly Features
---
A tiny, zero-dependency library for detecting WebAssembly features (**~2 kB minified**).
## Support features
- [x] [Reference types](https://github.com/WebAssembly/reference-types) _(standardized)_
- [x] [BigInt between js and wasm](https://github.com/WebAssembly/JS-BigInt-integration) _(standardized)_
- [x] [Bulk memory operations](https://github.com/webassembly/bulk-memory-operations) _(standardized)_
- [x] [Exceptions](https://github.com/WebAssembly/exception-handling) _(--experimental-wasm-eh)_
- [x] [Memory 64-bit](https://github.com/WebAssembly/memory64) _(--experimental-wasm-memory64)_
- [x] [Custom page sizes](https://github.com/WebAssembly/custom-page-sizes)
- [x] [Mutable globals](https://github.com/WebAssembly/mutable-global) _(standardized)_
- [x] [Multi values](https://github.com/WebAssembly/multi-value) _(standardized)_
- [x] [Saturated (non-trapping) conversions from float to int](https://github.com/WebAssembly/nontrapping-float-to-int-conversions) _(standardized)_
- [x] [Sign extensions](https://github.com/WebAssembly/sign-extension-ops) _(standardized)_
- [x] [Tail calls](https://github.com/webassembly/tail-call) _(--experimental-wasm-return-call)_
- [x] [Threads](https://github.com/webassembly/threads) _(standardized)_
- [x] [SIMD](https://github.com/webassembly/simd) _(standardized)_
- [x] [Relaxed SIMD](https://github.com/WebAssembly/relaxed-simd)
- [x] [GC](https://github.com/WebAssembly/gc)
- [x] [Type reflection](https://github.com/WebAssembly/js-types) _(--experimental-wasm-type-reflection)_
- [x] [Typed function references](https://github.com/WebAssembly/function-references)
- [x] [JS String builtins](https://github.com/WebAssembly/js-string-builtins)
## Install
```
yarn add wasm-check
```
or
```
npm i wasm-check
```
## Usage
#### Check supported WebAssembly version
```ts
import * as check from 'wasm-check';
// or
// const check = require('wasm-check');
console.log(check.support()); // WebAssembly >= 1.0
console.log(check.support(1)); // ^^^
console.log(check.support(2)); // WebAssembly >= 2.0
console.log(check.support(3)); // WebAssembly >= 3.0
```
#### Check supporting streaming compilation
```ts
import * as check from 'wasm-check';
console.log(check.supportStreaming);
```
#### Get all post-MVP WebAssembly features
```ts
import * as check from 'wasm-check';
const features = { ...check.feature };
console.log(features);
```
Output:
```js
{
bigInt: true,
bulk: true,
exceptions: true,
memory64: true,
customPageSizes: false,
mutableGlobal: true,
multiValue: true,
saturateConversions: true,
signExtensions: true,
tailCall: true,
threads: true,
simd: true,
relaxedSimd: true,
gc: true,
references: true,
typeReflection: false,
funcReferences: true,
jsStringBuiltins: true
}
```
#### Or check concrete feature
```ts
import * as check from 'wasm-check';
console.log(check.feature.simd); // has SIMD support?
console.log(check.feature.relaxedSimd); // has Relaxed SIMD support?
console.log(check.feature.tailCall); // has tail call support?
console.log(check.feature.gc); // has Wasm GC support?
console.log(check.feature.jsStringBuiltins); // has JS String builtins support?
```