1.8.0 • Published 2 months ago

wasm-feature-detect v1.8.0

Weekly downloads
291
License
Apache-2.0
Repository
github
Last release
2 months ago

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 ~970B gzipped

Installation

npm install -g wasm-feature-detect

Usage

<script type="module">
	import { simd } from "wasm-feature-detect";

	if (await simd()) {
		/* SIMD support */
	} else {
		/* No SIMD support */
	}
</script>

Hotlinking from Unpkg

<script type="module">
	import { simd } from "https://unpkg.com/wasm-feature-detect?module";
	// ...
</script>

If required, there’s also a UMD version

<script src="https://unpkg.com/wasm-feature-detect/dist/umd/index.js"></script>
<script>
	if (await wasmFeatureDetect.simd()) {
	  // ...
	}
</script>

Detectors

All detectors return a Promise<bool>.

FunctionProposal
bigInt()BigInt integration
bulkMemory()Bulk memory operations
exceptions()Legacy Exception Handling
exceptionsFinal()Exception Handling with exnref
extendedConst()Extented Const Expressesions
gc()Garbage Collection
jsStringBuiltins()JS String Builtins Proposal for WebAssembly
jspi()JavaScript Promise Integration
memory64()Memory64
multiMemory()Multiple Memories
multiValue()Multi-value
mutableGlobals()Importable/Exportable mutable globals
referenceTypes()Reference Types
relaxedSimd()Relaxed SIMD
saturatedFloatToInt()Non-trapping float-to-int conversions
signExtensions()Sign-extension operators
simd()Fixed-Width SIMD
streamingCompilation()Streaming Compilation
tailCall()Tail call
threads()Threads
typeReflection()Type Reflection
typedFunctionReferences()Typed 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 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.

;; Name: <Name of the feature for the README>
;; Proposal: <Link to the proposal’s explainer/repo>
;; Features: <Space-separated list of WasmFeatures from wabt.js>

(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.


License Apache-2.0

@juunini/squoosh-lib@dashql/duckdbpsyseg-js-sdk@personifyinc/psyseg-jsretina-engine@everything-registry/sub-chunk-3114@tenpi/jxlshoggoth-diffusersscandit-web-datacapture-coreremigeronds-graph-chartronds-graph-chart-phmtest13456nuxt-tesseract.jsmeishewasmloaderlingo3ditk-wasmjsquash-avifgifski-wasmnebuia-react-componentmaplibre-rspivx-shieldplivo-browser-sdksquooshlibtest01squoosh-browser-sensetesseract.js@antv/layout-wasm@aislamov/diffusers.js@banuba/webar@biowasm/aioli@carsonburke/diffusers.jswebp-codecverified-runzeropool-client-jszkbob-client-jszkbob-client-js-dev@frostoven/libsquoosh@liesegang/oxipng@manishiitg/virtual-background-lib@microblink/blinkid-in-browser-sdk@microblink/blinkcard-in-browser-sdk@movable/squoosh-lib@jsquash/avif@jsquash/jxl@jsquash/oxipng@jsquash/webp@privateid/bravo-web-sdk@privateid/cryptonets-web-sdk-alpha@privateid/cryptonets-web-sdk-test@privateid/oidc-web-sdk-alpha@privateid/ping-oidc-web-sdk-alpha@privateid/privid-fhe-modules@privateid/cryptonets-web-sdk@privateid/small-age-sdk@privateid/small-age-sdk-alpha@privateid/ultra-web-sdk-alpha@radulle/cra-squoosh-avif@radulle/cra-squoosh-oxipng@radulle/cra-squoosh-png@radulle/cra-squoosh-webp@scribe.js/tesseract.js@schickling-tmp/squoosh-lib@php-wasm/cli@php-wasm/fs-journal@php-wasm/node@php-wasm/web@openziti/ziti-browzer-runtime@superbiche/squoosh-lib@snap/camera-kit@stream-io/video-filters-web@stream-io/audio-filters-web@squoosh/lib@sse-stream/audio-filters-web@sse-stream/video-filters-web@datachecker/faceverify@wasmer/wasm-transformer@vonage/ml-transformers@waganawa/diffusers.js@wonderlandengine/api@wp-playground/blueprints@wp-playground/cli@wp-playground/client@wp-playground/wordpress@wp-playground/storage@xyo-network/wasm@xverse/core@yireen/squoosh-browserargon2-browser-bwbnlkdsdsf
1.8.0

2 months ago

1.7.0

2 months ago

1.6.2

5 months ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.11

3 years ago

1.2.10

4 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago