Skip to content

Commit 7a3a331

Browse files
committed
add deno checker
1 parent abc5214 commit 7a3a331

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (isBrowser) {
1111
More thoroughly:
1212

1313
```js
14-
import { isJsDom, isNode, isBrowser } from "is-in-browser";
14+
import { isJsDom, isNode, isBrowser, isDeno } from "is-in-browser";
1515

1616
if (isBrowser) {
1717
// you're in the browser
@@ -25,6 +25,10 @@ if (isJsDom) {
2525
if (isNode) {
2626
// you're in the Node
2727
}
28+
29+
if (isDeno) {
30+
// you're in the Deno
31+
}
2832
```
2933

3034
## CommonJS

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ export const isBrowser =
1111
typeof document === "object" &&
1212
document.nodeType === 9;
1313

14+
export const isDeno =
15+
typeof window === "object" &&
16+
typeof window.Deno === "object"
17+
1418
export default isBrowser;

src/node.check.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { isBrowser, isNode, isJsDom } from "./index";
1+
import { isBrowser, isNode, isJsDom, isDeno } from "./index";
22

33
console.log(isBrowser ? "❌" : "✅", "browser:", isBrowser);
44
console.log(isNode ? "✅" : "❌", "node:", isNode);
55
console.log(isBrowser ? "❌" : "✅", "js-dom:", isJsDom);
6+
console.log(isDeno ? "❌" : "✅", "deno:", isDeno);
7+
68

79
if (isBrowser || !isNode || isJsDom) {
810
process.exit(1);

src/test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import isInBrowser, { isBrowser, isJsDom, isNode } from ".";
1+
import isInBrowser, { isBrowser, isDeno, isJsDom, isNode } from ".";
22

33
test("isInBrowser", () => {
44
// jest runs jsdom, so true
@@ -13,5 +13,8 @@ test("isInBrowser", () => {
1313
// jest runs on Node, so true
1414
expect(isNode).toBe(true);
1515

16+
// jest runs on Deno, so true
17+
expect(isDeno).toBe(true);
18+
1619
// jest runs JSDOm, so true
1720
});

0 commit comments

Comments
 (0)