Skip to content

Commit a9e99d9

Browse files
authored
feat: Add support for Bun (#23)
* Add support for Bun * docs: Add missing example * Update `isBun` checker Credits to @paradoxloop * Remove obsolete tests
1 parent a34ba2c commit a9e99d9

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Check in which environment the code is running - browser/node.js/webworker/jsdom
77

88

99

10-
> [!NOTE]
10+
> [!NOTE]
1111
> To help release v3.0.0, please try [v3.0.0-pre.0](https://github.com/flexdinesh/browser-or-node/releases/tag/3.0.0-pre.0) and let us know if you run into issues.
1212
1313
## Install
@@ -22,7 +22,7 @@ Import the checks and use it in your code. Works with both ESM and CJS imports.
2222

2323
```js
2424
import * as jsEnv from "browser-or-node";
25-
// import { isBrowser, isNode, isWebWorker, isJsDom, isDeno } from "browser-or-node";
25+
// import { isBrowser, isNode, isWebWorker, isJsDom, isDeno, isBun } from "browser-or-node";
2626
// const jsEnv = require("browser-or-node");
2727

2828
if (jsEnv.isBrowser) {
@@ -44,6 +44,10 @@ if (jsEnv.isJsDom) {
4444
if (jsEnv.isDeno) {
4545
// do deno only stuff
4646
}
47+
48+
if (jsEnv.isBun) {
49+
// do bun only stuff
50+
}
4751
```
4852

4953
## License

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ const isDeno: boolean =
3131
// @ts-expect-error
3232
typeof Deno.version.deno !== "undefined";
3333

34-
export { isBrowser, isWebWorker, isNode, isJsDom, isDeno };
34+
35+
/** @see {@link https://bun.sh/guides/util/detect-bun} */
36+
const isBun = typeof process !== "undefined" && process.versions != null && process.versions.bun != null;
37+
38+
export { isBrowser, isWebWorker, isNode, isJsDom, isDeno, isBun };

0 commit comments

Comments
 (0)