diggy 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./resolvers/doh-resolver.js";
6
6
  export * from "./resolvers/dot-resolver.js";
7
7
  export * from "./resolvers/node-resolver.js";
8
8
  export * from "./types.js";
9
+ export * from "./utils/detect.js";
9
10
  export * from "./utils/resolve-all-records.js";
10
11
  export * from "./utils/to-dns-record.js";
11
12
  export * from "./utils/to-dns-type.js";
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export * from "./resolvers/doh-resolver.js";
6
6
  export * from "./resolvers/dot-resolver.js";
7
7
  export * from "./resolvers/node-resolver.js";
8
8
  export * from "./types.js";
9
+ export * from "./utils/detect.js";
9
10
  export * from "./utils/resolve-all-records.js";
10
11
  export * from "./utils/to-dns-record.js";
11
12
  export * from "./utils/to-dns-type.js";
@@ -1,5 +1,6 @@
1
1
  import * as _dns from "node:dns/promises";
2
2
  import { DNSRecordType } from "../types.js";
3
+ import { isBrowser, isServerRuntime } from "../utils/detect.js";
3
4
  /**
4
5
  * Returns a DNS resolver that uses Node.js's built-in DNS module.
5
6
  *
@@ -25,11 +26,17 @@ import { DNSRecordType } from "../types.js";
25
26
  * @group Resolvers
26
27
  */
27
28
  export function nodeResolver(servers = []) {
28
- const dns = new _dns.Resolver();
29
- if (servers.length > 0) {
30
- dns.setServers(servers);
29
+ let dns = null;
30
+ if (isServerRuntime()) {
31
+ dns = new _dns.Resolver();
32
+ if (servers.length > 0) {
33
+ dns.setServers(servers);
34
+ }
31
35
  }
32
36
  return async (host, type) => {
37
+ if (isBrowser() || !dns) {
38
+ throw new Error("nodeResolver cannot be used in a browser environment");
39
+ }
33
40
  try {
34
41
  // Handle special cases for A and AAAA records to include TTL
35
42
  if (type === DNSRecordType.A || type === DNSRecordType.AAAA) {
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Checks if the current environment is Node.js., Bun, or Deno.
3
+ */
4
+ export declare function isServerRuntime(): boolean;
5
+ /**
6
+ * Checks if the current environment is a browser.
7
+ */
8
+ export declare function isBrowser(): boolean;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Checks if the current environment is Node.js., Bun, or Deno.
3
+ */
4
+ export function isServerRuntime() {
5
+ return (Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]" ||
6
+ typeof Bun !== "undefined" ||
7
+ (typeof Deno !== "undefined" && typeof Deno.version !== "undefined"));
8
+ }
9
+ /**
10
+ * Checks if the current environment is a browser.
11
+ */
12
+ export function isBrowser() {
13
+ return (typeof window !== "undefined" &&
14
+ Object.prototype.toString.call(window) === "[object Window]");
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diggy",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "Multi-backend DNS resolver for Node.js/Browser — supports dig, DNS over HTTPS, and native Node.js DNS.",
5
5
  "repository": "OzzyCzech/diggy",
6
6
  "website": "https://ozzyczech.github.io/diggy/",
@@ -45,7 +45,9 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@biomejs/biome": "^2.2.0",
48
- "@types/node": "^24.2.1",
48
+ "@types/bun": "^1.2.20",
49
+ "@types/deno": "^2.3.0",
50
+ "@types/node": "^24.3.0",
49
51
  "np": "^10.2.0",
50
52
  "tsx": "^4.20.4",
51
53
  "typedoc": "^0.28.10",