Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ if (isJsDom) {
if (isDeno) {
// do deno only stuff
}

if (isHappyDom) {
// do happy-dom only stuff
}
```

ES5 style import
Expand All @@ -64,8 +68,12 @@ if (jsEnv.isJsDom) {
if (jsEnv.isDeno) {
// do deno only stuff
}

if (jsEnv.isHappyDom) {
// do happy DOM only stuff
}
```

## License

MIT © Dineshkumar Pandiyan
MIT © Dineshkumar Pandiyan
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export declare const isWebWorker: boolean;
export declare const isNode: boolean;
export declare const isJsDom: boolean;
export declare const isDeno: boolean;
export declare const isHappyDom: boolean;
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ const isJsDom =
(navigator.userAgent.includes("Node.js") ||
navigator.userAgent.includes("jsdom")));

/**
* @see https://github.com/capricorn86/happy-dom/discussions/481
*/
const isHappyDom =
typeof window !== "undefined" && typeof navigator !== "undefined" && typeof window.happyDOM !== "undefined";

const isDeno =
typeof Deno !== "undefined" &&
typeof Deno.version !== "undefined" &&
typeof Deno.version.deno !== "undefined";

export { isBrowser, isWebWorker, isNode, isJsDom, isDeno };
export { isBrowser, isWebWorker, isNode, isJsDom, isDeno, isHappyDom };
3 changes: 2 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { assert } from "chai";
import { isBrowser, isNode, isWebWorker, isDeno, isJsDom } from "../src";
import { isBrowser, isNode, isWebWorker, isDeno, isJsDom, isHappyDom } from "../src";

console.log({
isBrowser,
isNode,
isWebWorker,
isJsDom,
isDeno,
isHappyDom,
});

describe("Browser or Node.js", () => {
Expand Down