@visulima/disposable-email-domains 1.0.0 → 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
@@ -1,94 +1,94 @@
1
1
  /**
2
- * Options accepted by the lookup helpers.
3
- */
2
+ * Options accepted by the lookup helpers.
3
+ */
4
4
  interface DisposableEmailOptions {
5
5
  /**
6
- * Domains that should never be treated as disposable, even if they appear in
7
- * the built-in list. Checked before the disposable list, with the same
8
- * wildcard/subdomain semantics (so `gmail.com` also allowlists
9
- * `mail.gmail.com`). Useful as a runtime escape hatch for legitimate
10
- * customer domains that leak into upstream sources.
11
- */
6
+ * Domains that should never be treated as disposable, even if they appear in
7
+ * the built-in list. Checked before the disposable list, with the same
8
+ * wildcard/subdomain semantics (so `gmail.com` also allowlists
9
+ * `mail.gmail.com`). Useful as a runtime escape hatch for legitimate
10
+ * customer domains that leak into upstream sources.
11
+ */
12
12
  allowDomains?: Set<string>;
13
13
  /**
14
- * Additional disposable domains to check on top of the built-in list. These
15
- * are matched with the same wildcard/subdomain semantics as the built-in
16
- * list (so a custom `custom-disposable.com` also matches
17
- * `sub.custom-disposable.com`).
18
- */
14
+ * Additional disposable domains to check on top of the built-in list. These
15
+ * are matched with the same wildcard/subdomain semantics as the built-in
16
+ * list (so a custom `custom-disposable.com` also matches
17
+ * `sub.custom-disposable.com`).
18
+ */
19
19
  customDomains?: Set<string>;
20
20
  }
21
21
  /**
22
- * Injects the disposable-domain list explicitly, bypassing the Node filesystem
23
- * loader entirely.
24
- *
25
- * Call this once at startup in edge/browser/bundled runtimes (Cloudflare Workers,
26
- * Next.js middleware/edge, Deno, etc.) where `node:fs` is unavailable or the dist
27
- * file path cannot be resolved. The recommended source is the statically
28
- * importable list:
29
- *
30
- * ```ts
31
- * import { setDomains } from "@visulima/disposable-email-domains";
32
- * import domains from "@visulima/disposable-email-domains/domains" with { type: "json" };
33
- *
34
- * setDomains(domains);
35
- * ```
36
- * @param domains Array of disposable domain strings.
37
- */
22
+ * Injects the disposable-domain list explicitly, bypassing the Node filesystem
23
+ * loader entirely.
24
+ *
25
+ * Call this once at startup in edge/browser/bundled runtimes (Cloudflare Workers,
26
+ * Next.js middleware/edge, Deno, etc.) where `node:fs` is unavailable or the dist
27
+ * file path cannot be resolved. The recommended source is the statically
28
+ * importable list:
29
+ *
30
+ * ```ts
31
+ * import { setDomains } from "@visulima/disposable-email-domains";
32
+ * import domains from "@visulima/disposable-email-domains/domains" with { type: "json" };
33
+ *
34
+ * setDomains(domains);
35
+ * ```
36
+ * @param domains Array of disposable domain strings.
37
+ */
38
38
  declare const setDomains: (domains: ReadonlyArray<string>) => void;
39
39
  /**
40
- * Eagerly loads the built-in disposable-domain list (Node runtimes).
41
- *
42
- * Calling this at process/module startup moves the synchronous read + parse of
43
- * the multi-megabyte `dist/domains.json` off the request hot path, so the first
44
- * `isDisposableEmail` call no longer stalls the event loop mid-request. It is a
45
- * thin async wrapper around the same lazy loader, so calling it is optional and
46
- * idempotent.
47
- * @returns A promise that resolves once the list is loaded (or the load failed).
48
- */
40
+ * Eagerly loads the built-in disposable-domain list (Node runtimes).
41
+ *
42
+ * Calling this at process/module startup moves the synchronous read + parse of
43
+ * the multi-megabyte `dist/domains.json` off the request hot path, so the first
44
+ * `isDisposableEmail` call no longer stalls the event loop mid-request. It is a
45
+ * thin async wrapper around the same lazy loader, so calling it is optional and
46
+ * idempotent.
47
+ * @returns A promise that resolves once the list is loaded (or the load failed).
48
+ */
49
49
  declare const preload: () => Promise<void>;
50
50
  /**
51
- * Reports whether the built-in disposable-domain list is currently loaded.
52
- *
53
- * Returns `false` when the list has not been accessed yet, or when loading
54
- * failed (missing/corrupt `dist/domains.json`). Callers that treat disposable
55
- * detection as a security control can use this to detect the degraded
56
- * fail-open state instead of silently allowing every address.
57
- * @returns True if the built-in list is loaded and non-degraded.
58
- */
51
+ * Reports whether the built-in disposable-domain list is currently loaded.
52
+ *
53
+ * Returns `false` when the list has not been accessed yet, or when loading
54
+ * failed (missing/corrupt `dist/domains.json`). Callers that treat disposable
55
+ * detection as a security control can use this to detect the degraded
56
+ * fail-open state instead of silently allowing every address.
57
+ * @returns True if the built-in list is loaded and non-degraded.
58
+ */
59
59
  declare const isListLoaded: () => boolean;
60
60
  /**
61
- * Extracts and validates the domain from an email address.
62
- * @param email The email address to extract domain from.
63
- * @returns The normalized (lowercased, trimmed) domain string, or undefined if invalid.
64
- */
61
+ * Extracts and validates the domain from an email address.
62
+ * @param email The email address to extract domain from.
63
+ * @returns The normalized (lowercased, trimmed) domain string, or undefined if invalid.
64
+ */
65
65
  declare const extractDomain: (email: string) => string | undefined;
66
66
  /**
67
- * Checks if a bare domain is disposable.
68
- *
69
- * Supports wildcard matching by checking parent domains (e.g.,
70
- * `subdomain.33mail.com` matches `33mail.com`) for the built-in list, custom
71
- * domains, and allowlisted domains alike.
72
- *
73
- * Useful when you already have a bare domain (from an MX lookup or a parsed
74
- * signup form) and do not want to fabricate an `x@domain` address.
75
- * @param domain The domain to check (case-insensitive).
76
- * @param options Either a Set of additional disposable domains or a `DisposableEmailOptions` object.
77
- * @returns True if the domain is disposable, false otherwise.
78
- */
67
+ * Checks if a bare domain is disposable.
68
+ *
69
+ * Supports wildcard matching by checking parent domains (e.g.,
70
+ * `subdomain.33mail.com` matches `33mail.com`) for the built-in list, custom
71
+ * domains, and allowlisted domains alike.
72
+ *
73
+ * Useful when you already have a bare domain (from an MX lookup or a parsed
74
+ * signup form) and do not want to fabricate an `x@domain` address.
75
+ * @param domain The domain to check (case-insensitive).
76
+ * @param options Either a Set of additional disposable domains or a `DisposableEmailOptions` object.
77
+ * @returns True if the domain is disposable, false otherwise.
78
+ */
79
79
  declare const isDisposableDomain: (domain: string, options?: Set<string> | DisposableEmailOptions) => boolean;
80
80
  /**
81
- * Checks if an email address is from a disposable email service.
82
- * @param email The email address to check.
83
- * @param options Either a Set of additional disposable domains, or a `DisposableEmailOptions` object with `allowDomains`/`customDomains`.
84
- * @returns True if the email is from a disposable domain, false otherwise.
85
- */
81
+ * Checks if an email address is from a disposable email service.
82
+ * @param email The email address to check.
83
+ * @param options Either a Set of additional disposable domains, or a `DisposableEmailOptions` object with `allowDomains`/`customDomains`.
84
+ * @returns True if the email is from a disposable domain, false otherwise.
85
+ */
86
86
  declare const isDisposableEmail: (email: string, options?: Set<string> | DisposableEmailOptions) => boolean;
87
87
  /**
88
- * Checks multiple email addresses at once.
89
- * @param emails Array of email addresses to check.
90
- * @param options Either a Set of additional disposable domains, or a `DisposableEmailOptions` object with `allowDomains`/`customDomains`.
91
- * @returns Map of email to boolean indicating if it's disposable.
92
- */
88
+ * Checks multiple email addresses at once.
89
+ * @param emails Array of email addresses to check.
90
+ * @param options Either a Set of additional disposable domains, or a `DisposableEmailOptions` object with `allowDomains`/`customDomains`.
91
+ * @returns Map of email to boolean indicating if it's disposable.
92
+ */
93
93
  declare const areDisposableEmails: (emails: string[], options?: Set<string> | DisposableEmailOptions) => Map<string, boolean>;
94
94
  export { type DisposableEmailOptions, areDisposableEmails, extractDomain, isDisposableDomain, isDisposableEmail, isListLoaded, preload, setDomains };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{createRequire as m}from"node:module";const p=m(import.meta.url),r=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,u=e=>{if(typeof r<"u"&&r.versions&&r.versions.node){const[t,s]=r.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return r.getBuiltinModule(e)}return p(e)},{readFileSync:_}=u("node:fs"),{dirname:h,join:y}=u("node:path"),{fileURLToPath:b}=u("node:url"),g=/\.$/;let n,d=!1,c=!1;const w=b(import.meta.url),j=h(w),v=()=>{try{const e=y(j,"..","dist","domains.json"),t=_(e,"utf8"),s=JSON.parse(t);return Array.isArray(s)?s:[]}catch(e){c||(c=!0,console.warn("[@visulima/disposable-email-domains] Failed to load dist/domains.json; disposable email detection is disabled.",e));return}},f=()=>{if(n===void 0){const e=v();if(e===void 0)return new Set;n=new Set(e),d=!0}return n},T=e=>{n=new Set(e),d=!0,c=!1},q=async()=>{await Promise.resolve(),f()},E=()=>d,D=e=>{if(!e||typeof e!="string")return;const t=e.toLowerCase().trim(),s=t.lastIndexOf("@");return s===-1||s===0||s===t.length-1?void 0:t.slice(s+1).replace(g,"")||void 0},S=e=>e instanceof Set?{customDomains:e}:e??{},l=(e,t,s)=>{if(s.has(e))return!0;for(let o=1;o<t.length;o+=1)if(s.has(t.slice(o).join(".")))return!0;return!1},L=(e,t)=>{if(!e||typeof e!="string")return!1;const{allowDomains:s,customDomains:o}=S(t),i=e.toLowerCase().trim(),a=i.split(".");return s&&s.size>0&&l(i,a,s)?!1:o&&o.size>0&&l(i,a,o)?!0:l(i,a,f())},x=(e,t)=>{const s=D(e);return s?L(s,t):!1},M=(e,t)=>{const s=new Map;for(const o of e)s.set(o,x(o,t));return s};export{M as areDisposableEmails,D as extractDomain,L as isDisposableDomain,x as isDisposableEmail,E as isListLoaded,q as preload,T as setDomains};
1
+ import{createRequire as m}from"node:module";let p;const _=e=>(p??=m(import.meta.url))(e),r=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,u=e=>{if(typeof r<"u"&&r.versions&&r.versions.node){const[t,s]=r.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return r.getBuiltinModule(e)}return _(e)},{readFileSync:h}=u("node:fs"),{dirname:y,join:w}=u("node:path"),{fileURLToPath:j}=u("node:url"),b=/\.$/;let n,d=!1,c=!1;const g=j(import.meta.url),v=y(g),D=()=>{try{const e=w(v,"..","dist","domains.json"),t=h(e,"utf8"),s=JSON.parse(t);if(!Array.isArray(s))throw new TypeError("dist/domains.json did not contain a JSON array.");return s}catch(e){c||(c=!0,console.warn("[@visulima/disposable-email-domains] Failed to load dist/domains.json; disposable email detection is disabled.",e));return}},f=()=>{if(n===void 0){const e=D();if(e===void 0)return new Set;n=new Set(e),d=!0}return n},E=e=>{n=new Set(e),d=!0,c=!1},O=async()=>{await Promise.resolve(),f()},P=()=>d,S=e=>{if(!e||typeof e!="string")return;const t=e.toLowerCase().trim(),s=t.lastIndexOf("@");return s===-1||s===0||s===t.length-1?void 0:t.slice(s+1).replace(b,"")||void 0},L=e=>e instanceof Set?{customDomains:e}:e??{},l=(e,t,s)=>{if(s.has(e))return!0;for(let o=1;o<t.length;o+=1)if(s.has(t.slice(o).join(".")))return!0;return!1},T=(e,t)=>{if(!e||typeof e!="string")return!1;const{allowDomains:s,customDomains:o}=L(t),i=e.toLowerCase().trim(),a=i.split(".");return s&&s.size>0&&l(i,a,s)?!1:o&&o.size>0&&l(i,a,o)?!0:l(i,a,f())},q=(e,t)=>{const s=S(e);return s?T(s,t):!1},R=(e,t)=>{const s=new Map;for(const o of e)s.set(o,q(o,t));return s};export{R as areDisposableEmails,S as extractDomain,T as isDisposableDomain,q as isDisposableEmail,P as isListLoaded,O as preload,E as setDomains};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/disposable-email-domains",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A regularly updated list of disposable and temporary email domains.",
5
5
  "keywords": [
6
6
  "disposable-email",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "./domains": {
45
45
  "types": "./dist/domains.d.ts",
46
- "default": "./dist/domains.json"
46
+ "default": "./dist/domains.js"
47
47
  },
48
48
  "./package.json": "./package.json"
49
49
  },