brotli-wasm
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -6,3 +6,8 @@ // This makes importing wasm-brotli asynchronous (because of dynamic import). | ||
// We don't want to do this for _all_ usage, because dynamic import isn't | ||
// supported in older node versions. | ||
// In addition, we provide a default export with the same value, for compatibility | ||
// with the pure ESM web bundle: | ||
module.exports.default = module.exports; | ||
// Without this, ts-loader gets annoyed by imports for the pure type. Clear ts-loader bug, | ||
// but this is a quick & easy fix on our end: | ||
module.exports.BrotliWasmType = undefined; |
{ | ||
"name": "brotli-wasm", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A reliable compressor and decompressor for Brotli, supporting node & browsers via wasm", | ||
"main": "./pkg.node/brotli_wasm.js", | ||
"types": "./pkg.node/brotli_wasm.d.ts", | ||
"types": "./index.d.ts", | ||
"main": "./index.node.js", | ||
"browser": "./index.browser.js", | ||
"exports": { | ||
".": { | ||
"import": "./index.web.js", | ||
"browser": "./index.browser.js", | ||
"require": "./index.node.js", | ||
"default": "./index.web.js" | ||
} | ||
}, | ||
"sideEffects": false, | ||
@@ -12,3 +20,7 @@ "files": [ | ||
"pkg.bundler", | ||
"index.browser.js" | ||
"pkg.web", | ||
"index.node.js", | ||
"index.browser.js", | ||
"index.web.js", | ||
"index.d.ts" | ||
], | ||
@@ -18,6 +30,8 @@ "scripts": { | ||
"pretest": "npm run build", | ||
"test": "npm run test:node && npm run test:browser", | ||
"test:node": "TS_NODE_FILES=true mocha -r ts-node/register 'test/**/*.spec.ts'", | ||
"test:browser": "karma start", | ||
"test:browser:debug": "npm run test:browser -- --single-run=false --browsers Chrome" | ||
"test": "npm run test:node && npm run test:esm && npm run test:webpack", | ||
"test:node": "ts-mocha -p test/tsconfig.json 'test/**/*.spec.ts'", | ||
"test:webpack": "karma start ./karma-webpack.conf.js", | ||
"test:esm": "karma start ./karma-esm.conf.js", | ||
"test:webpack:debug": "npm run test:webpack -- --single-run=false --browsers Chrome", | ||
"test:esm:debug": "npm run test:esm -- --single-run=false --browsers Chrome" | ||
}, | ||
@@ -41,5 +55,11 @@ "repository": { | ||
"devDependencies": { | ||
"@peculiar/webcrypto": "^1.4.0", | ||
"@types/atob": "^2.1.2", | ||
"@types/btoa": "^1.2.3", | ||
"@types/chai": "^4.2.18", | ||
"@types/mocha": "^8.2.2", | ||
"@types/node": "^15.6.0", | ||
"@types/text-encoding": "0.0.36", | ||
"atob": "^2.1.2", | ||
"btoa": "^1.2.1", | ||
"buffer": "^6.0.3", | ||
@@ -54,11 +74,14 @@ "chai": "^4.3.4", | ||
"karma-typescript": "^5.5.1", | ||
"karma-vite": "^1.0.1", | ||
"karma-webpack": "^5.0.0", | ||
"mocha": "^8.4.0", | ||
"shelljs": "^0.8.4", | ||
"text-encoding": "^0.7.0", | ||
"ts-loader": "^9.2.1", | ||
"ts-mocha": "^10.0.0", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.2.4", | ||
"wasm-pack": "^0.9.1", | ||
"wasm-pack": "^0.10.3", | ||
"webpack": "^5.37.1" | ||
} | ||
} |
@@ -19,7 +19,7 @@ # brotli-wasm [![Build Status](https://github.com/httptoolkit/brotli-wasm/workflows/CI/badge.svg)](https://github.com/httptoolkit/brotli-wasm/actions) [![Available on NPM](https://img.shields.io/npm/v/brotli-wasm.svg)](https://npmjs.com/package/brotli-wasm) | ||
You should be able to import this directly into Node, as normal, or into a browser using any bundler that supports ES modules & webassembly (e.g. Webpack v4 or v5). | ||
You should be able to import this directly into Node, as normal, or in a browser using any bundler that supports ES modules & webassembly (e.g. Webpack v4 or v5, Vite, Rollup, and most others). | ||
The browser build supports both sync (v4 or v5 syncWebAssembly mode) and async (v5 asyncWebAssembly) builds. When imported in a browser build the module always exports a _promise_, not a fixed value, as this is a requirement for synchronous builds, and you will need to `await` this after import. | ||
For each target (node.js, commonjs bundlers & ESM bundlers) this module exports a different WASM file & setup, with a slightly different entrypoint. These entrypoints all expose a consistent default-export API, in addition to some other exports that may vary (e.g. Node exposes the brotli methods synchronously, while browsers always require an `await` due to WASM limitations). | ||
In both builds, the module exposes two methods: | ||
In all builds (after waiting for the exported promise in browsers) the module exposes two core methods: | ||
@@ -29,2 +29,6 @@ * `compress(Buffer, [options])` - compresses a buffer using Brotli, returning the compressed buffer. An optional options object can be provided. The only currently supported option is `quality`: a number between 1 and 11. | ||
For advanced use data-streaming use cases, `CompressStream` and `DecompressStream` classes for streaming compression are also available. See [the tests](https://github.com/httptoolkit/brotli-wasm/blob/main/test/brotli.spec.ts) for example usage. | ||
### Usage | ||
In node.js: | ||
@@ -44,3 +48,3 @@ | ||
```javascript | ||
import * as brotliPromise from 'brotli-wasm'; | ||
import brotliPromise from 'brotli-wasm'; // Import the default export | ||
@@ -55,5 +59,5 @@ const brotli = await brotliPromise; // Import is async in browsers due to wasm requirements! | ||
You'll need a [browser Buffer polyfill](https://www.npmjs.com/package/browserify-zlib) for the above, or you can do the same using TextEncoder/Decoder instead if you prefer. | ||
The package itself has no runtime dependencies, but you will need a [browser Buffer polyfill](https://www.npmjs.com/package/browserify-zlib) for the above example code, or you can do the same using TextEncoder/Decoder instead if you prefer. | ||
If you want to support node & browsers with the same code, you can use the latter `await` form here everywhere (since awaiting the fixed value in node just returns the value as-is). | ||
If you want to support node & browsers with the same code, you can use the `await` form with the default export everywhere. | ||
@@ -60,0 +64,0 @@ ## Alternatives |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4281471
20
1687
67
29
1