emessages 2.0.1 → 2.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 arhan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs CHANGED
@@ -93,17 +93,40 @@ function parseConfig(config) {
93
93
  }
94
94
  function processEmessage(errorName, config) {
95
95
  const message = config.message;
96
- const type = config.type ?? "err";
97
- switch (type) {
98
- case "log":
99
- console.log(message);
100
- break;
101
- case "war":
102
- console.warn(message);
103
- break;
104
- case "err":
105
- console.error(message);
106
- break;
96
+ let consoleType;
97
+ if (config.type === false) {
98
+ consoleType = false;
99
+ } else if (config.type === true || config.type === void 0) {
100
+ consoleType = "err";
101
+ } else {
102
+ consoleType = config.type;
103
+ }
104
+ if (consoleType) {
105
+ if (isBrowser()) {
106
+ switch (consoleType) {
107
+ case "log":
108
+ console.log(message);
109
+ break;
110
+ case "war":
111
+ console.warn(message);
112
+ break;
113
+ case "err":
114
+ console.error(message);
115
+ break;
116
+ }
117
+ } else {
118
+ switch (consoleType) {
119
+ case "log":
120
+ console.log(`\x1B[30;47m LOG \x1B[0m ${message}`);
121
+ break;
122
+ case "war":
123
+ console.warn(`\x1B[37;43m WARN \x1B[0m ${message}`);
124
+ break;
125
+ case "err":
126
+ console.error(`\x1B[37;41m ERROR \x1B[0m ${message}`);
127
+ break;
128
+ }
129
+ }
107
130
  }
108
131
  if (config.toast && isBrowser()) {
109
132
  showToast(message, config.toast);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/store.ts","../src/utils.ts"],"sourcesContent":["import { individualMessageStore, globalMessageStore } from \"./store\";\r\nimport type {\r\n EmessageConfig,\r\n EmessageOptions,\r\n StoredEmessage,\r\n ToastConfig,\r\n} from \"./types\";\r\nimport { isBrowser, showToast } from \"./utils\";\r\n\r\nfunction parseConfig(\r\n config: Record<string, any>\r\n): { name: string; options: StoredEmessage } | null {\r\n const options: EmessageOptions = {};\r\n let message: string | null = null;\r\n let name: string | null = null;\r\n const optionKeys = [\"type\", \"break\", \"toast\", \"returnEM\", \"callBack\"];\r\n\r\n for (const key in config) {\r\n if (Object.prototype.hasOwnProperty.call(config, key)) {\r\n if (optionKeys.includes(key)) {\r\n (options as any)[key] = config[key];\r\n } else {\r\n if (name !== null) {\r\n console.warn(\r\n `emessages: Found multiple potential error names in one config object. Using first one found: \"${name}\".`\r\n );\r\n continue;\r\n }\r\n name = key;\r\n message = String(config[key]);\r\n }\r\n }\r\n }\r\n\r\n if (name === null || message === null) {\r\n console.error(\r\n \"emessages: Invalid config object. Could not find error name and message.\",\r\n config\r\n );\r\n return null;\r\n }\r\n\r\n return { name, options: { ...options, message } };\r\n}\r\n\r\nfunction processEmessage(\r\n errorName: string,\r\n config: StoredEmessage\r\n): string | void {\r\n const message = config.message;\r\n const type = config.type ?? \"err\";\r\n\r\n // 1. Console log\r\n switch (type) {\r\n case \"log\":\r\n console.log(message);\r\n break;\r\n case \"war\":\r\n console.warn(message);\r\n break;\r\n case \"err\":\r\n console.error(message);\r\n break;\r\n }\r\n\r\n // 2. Toast notification\r\n if (config.toast && isBrowser()) {\r\n showToast(message, config.toast);\r\n }\r\n\r\n // 3. Callback\r\n if (config.callBack) {\r\n try {\r\n config.callBack();\r\n } catch (e: any) {\r\n console.error(\r\n `emessages: Error in callBack for \"${errorName}\":`,\r\n e.message\r\n );\r\n }\r\n }\r\n\r\n // 4. Return error message\r\n if (config.returnEM) {\r\n return message;\r\n }\r\n\r\n // 5. Break execution\r\n if (config.break ?? true) {\r\n if (isBrowser()) {\r\n throw new Error(message);\r\n } else {\r\n process.exit(1);\r\n }\r\n }\r\n}\r\n\r\nexport function Emessage(...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n individualMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n}\r\n\r\nEmessage.global = function (...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n globalMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n};\r\n\r\nexport function showE(error: string | Record<string, any>): string | void {\r\n let config: StoredEmessage | null = null;\r\n let errorName: string | null = null;\r\n\r\n if (typeof error === \"string\") {\r\n errorName = error;\r\n config =\r\n individualMessageStore.get(error) ?? globalMessageStore.get(error) ?? null;\r\n if (!config) {\r\n console.error(`emessages: Error \"${error}\" not found.`);\r\n return;\r\n }\r\n } else if (typeof error === \"object\" && error !== null) {\r\n const parsed = parseConfig(error);\r\n if (parsed) {\r\n errorName = parsed.name;\r\n config = parsed.options;\r\n } else {\r\n console.error(\"emessages: Invalid object passed to showE.\");\r\n return;\r\n }\r\n } else {\r\n console.error(\"emessages: Invalid argument passed to showE.\");\r\n return;\r\n }\r\n\r\n if (config && errorName) {\r\n return processEmessage(errorName, config);\r\n }\r\n}\r\n","import type { StoredEmessage } from \"./types\";\r\n\r\nexport const individualMessageStore = new Map<string, StoredEmessage>();\r\nexport const globalMessageStore = new Map<string, StoredEmessage>();\r\n","import { ToastConfig } from \"./types\";\r\n\r\nexport function isBrowser(): boolean {\r\n return typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\r\n}\r\n\r\nexport function showToast(\r\n message: string,\r\n toastConfig: boolean | ToastConfig\r\n): void {\r\n if (!isBrowser()) {\r\n return;\r\n }\r\n\r\n const toast = document.createElement(\"div\");\r\n\r\n const config: ToastConfig = typeof toastConfig === \"object\" ? toastConfig : {};\r\n\r\n toast.textContent = config.message || message;\r\n\r\n // Base styles are applied via CSS, but some can be defaults.\r\n toast.className = \"emessage-toast\";\r\n if (config.style) {\r\n toast.classList.add(...config.style.split(\" \"));\r\n }\r\n\r\n // Positioning\r\n const position = config.position || \"top-right\";\r\n toast.setAttribute(\"data-position\", position);\r\n\r\n document.body.appendChild(toast);\r\n\r\n // Animate in\r\n setTimeout(() => {\r\n toast.classList.add(\"visible\");\r\n }, 10);\r\n\r\n // Animate out and remove\r\n setTimeout(() => {\r\n toast.classList.remove(\"visible\");\r\n toast.addEventListener(\"transitionend\", () => {\r\n if (toast.parentElement) {\r\n toast.parentElement.removeChild(toast);\r\n }\r\n });\r\n }, 3000);\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,yBAAyB,oBAAI,IAA4B;AAC/D,IAAM,qBAAqB,oBAAI,IAA4B;;;ACD3D,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AACrE;AAEO,SAAS,UACd,SACA,aACM;AACN,MAAI,CAAC,UAAU,GAAG;AAChB;AAAA,EACF;AAEA,QAAM,QAAQ,SAAS,cAAc,KAAK;AAE1C,QAAM,SAAsB,OAAO,gBAAgB,WAAW,cAAc,CAAC;AAE7E,QAAM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AAAA,IACF;AAAA,EACF,WAAW,OAAO,UAAU,YAAY,UAAU,MAAM;AACtD,UAAM,SAAS,YAAY,KAAK;AAChC,QAAI,QAAQ;AACV,kBAAY,OAAO;AACnB,eAAS,OAAO;AAAA,IAClB,OAAO;AACL,cAAQ,MAAM,4CAA4C;AAC1D;AAAA,IACF;AAAA,EACF,OAAO;AACL,YAAQ,MAAM,8CAA8C;AAC5D;AAAA,EACF;AAEA,MAAI,UAAU,WAAW;AACvB,WAAO,gBAAgB,WAAW,MAAM;AAAA,EAC1C;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/store.ts","../src/utils.ts"],"sourcesContent":["import { individualMessageStore, globalMessageStore } from \"./store\";\r\nimport type {\r\n EmessageConfig,\r\n EmessageOptions,\r\n StoredEmessage,\r\n ToastConfig,\r\n MessageType,\r\n} from \"./types\";\r\nimport { isBrowser, showToast } from \"./utils\";\r\n\r\nfunction parseConfig(\r\n config: Record<string, any>\r\n): { name: string; options: StoredEmessage } | null {\r\n const options: EmessageOptions = {};\r\n let message: string | null = null;\r\n let name: string | null = null;\r\n const optionKeys = [\"type\", \"break\", \"toast\", \"returnEM\", \"callBack\"];\r\n\r\n for (const key in config) {\r\n if (Object.prototype.hasOwnProperty.call(config, key)) {\r\n if (optionKeys.includes(key)) {\r\n (options as any)[key] = config[key];\r\n } else {\r\n if (name !== null) {\r\n console.warn(\r\n `emessages: Found multiple potential error names in one config object. Using first one found: \"${name}\".`\r\n );\r\n continue;\r\n }\r\n name = key;\r\n message = String(config[key]);\r\n }\r\n }\r\n }\r\n\r\n if (name === null || message === null) {\r\n console.error(\r\n \"emessages: Invalid config object. Could not find error name and message.\",\r\n config\r\n );\r\n return null;\r\n }\r\n\r\n return { name, options: { ...options, message } };\r\n}\r\n\r\nfunction processEmessage(\r\n errorName: string,\r\n config: StoredEmessage\r\n): string | void {\r\n const message = config.message;\r\n\r\n let consoleType: MessageType | false;\r\n if (config.type === false) {\r\n consoleType = false;\r\n } else if (config.type === true || config.type === undefined) {\r\n consoleType = \"err\";\r\n } else {\r\n consoleType = config.type;\r\n }\r\n\r\n // 1. Console log\r\n if (consoleType) {\r\n if (isBrowser()) {\r\n switch (consoleType) {\r\n case \"log\":\r\n console.log(message);\r\n break;\r\n case \"war\":\r\n console.warn(message);\r\n break;\r\n case \"err\":\r\n console.error(message);\r\n break;\r\n }\r\n } else {\r\n switch (consoleType) {\r\n case \"log\":\r\n console.log(`\\x1b[30;47m LOG \\x1b[0m ${message}`);\r\n break;\r\n case \"war\":\r\n console.warn(`\\x1b[37;43m WARN \\x1b[0m ${message}`);\r\n break;\r\n case \"err\":\r\n console.error(`\\x1b[37;41m ERROR \\x1b[0m ${message}`);\r\n break;\r\n }\r\n }\r\n }\r\n\r\n // 2. Toast notification\r\n if (config.toast && isBrowser()) {\r\n showToast(message, config.toast);\r\n }\r\n\r\n // 3. Callback\r\n if (config.callBack) {\r\n try {\r\n config.callBack();\r\n } catch (e: any) {\r\n console.error(\r\n `emessages: Error in callBack for \"${errorName}\":`,\r\n e.message\r\n );\r\n }\r\n }\r\n\r\n // 4. Return error message\r\n if (config.returnEM) {\r\n return message;\r\n }\r\n\r\n // 5. Break execution\r\n if (config.break ?? true) {\r\n if (isBrowser()) {\r\n throw new Error(message);\r\n } else {\r\n process.exit(1);\r\n }\r\n }\r\n}\r\n\r\nexport function Emessage(...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n individualMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n}\r\n\r\nEmessage.global = function (...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n globalMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n};\r\n\r\nexport function showE(error: string | Record<string, any>): string | void {\r\n let config: StoredEmessage | null = null;\r\n let errorName: string | null = null;\r\n\r\n if (typeof error === \"string\") {\r\n errorName = error;\r\n config =\r\n individualMessageStore.get(error) ?? globalMessageStore.get(error) ?? null;\r\n if (!config) {\r\n console.error(`emessages: Error \"${error}\" not found.`);\r\n return;\r\n }\r\n } else if (typeof error === \"object\" && error !== null) {\r\n const parsed = parseConfig(error);\r\n if (parsed) {\r\n errorName = parsed.name;\r\n config = parsed.options;\r\n } else {\r\n console.error(\"emessages: Invalid object passed to showE.\");\r\n return;\r\n }\r\n } else {\r\n console.error(\"emessages: Invalid argument passed to showE.\");\r\n return;\r\n }\r\n\r\n if (config && errorName) {\r\n return processEmessage(errorName, config);\r\n }\r\n}\r\n","import type { StoredEmessage } from \"./types\";\r\n\r\nexport const individualMessageStore = new Map<string, StoredEmessage>();\r\nexport const globalMessageStore = new Map<string, StoredEmessage>();\r\n","import { ToastConfig } from \"./types\";\r\n\r\nexport function isBrowser(): boolean {\r\n return typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\r\n}\r\n\r\nexport function showToast(\r\n message: string,\r\n toastConfig: boolean | ToastConfig\r\n): void {\r\n if (!isBrowser()) {\r\n return;\r\n }\r\n\r\n const toast = document.createElement(\"div\");\r\n\r\n const config: ToastConfig = typeof toastConfig === \"object\" ? toastConfig : {};\r\n\r\n toast.textContent = config.message || message;\r\n\r\n // Base styles are applied via CSS, but some can be defaults.\r\n toast.className = \"emessage-toast\";\r\n if (config.style) {\r\n toast.classList.add(...config.style.split(\" \"));\r\n }\r\n\r\n // Positioning\r\n const position = config.position || \"top-right\";\r\n toast.setAttribute(\"data-position\", position);\r\n\r\n document.body.appendChild(toast);\r\n\r\n // Animate in\r\n setTimeout(() => {\r\n toast.classList.add(\"visible\");\r\n }, 10);\r\n\r\n // Animate out and remove\r\n setTimeout(() => {\r\n toast.classList.remove(\"visible\");\r\n toast.addEventListener(\"transitionend\", () => {\r\n if (toast.parentElement) {\r\n toast.parentElement.removeChild(toast);\r\n }\r\n });\r\n }, 3000);\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA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AAU;AACnB,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,SAAS,MAAM;AACxB,QAAI,UAAU,GAAG;AACf,YAAM,IAAI,MAAM,OAAO;AAAA,IACzB,OAAO;AACL,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AACF;AAEO,SAAS,YAAY,SAA2B;AACrD,aAAW,UAAU,SAAS;AAC5B,UAAM,SAAS,YAAY,MAAM;AACjC,QAAI,QAAQ;AACV,6BAAuB,IAAI,OAAO,MAAM,OAAO,OAAO;AAAA,IACxD;AAAA,EACF;AACF;AAEA,SAAS,SAAS,YAAa,SAA2B;AACxD,aAAW,UAAU,SAAS;AAC5B,UAAM,SAAS,YAAY,MAAM;AACjC,QAAI,QAAQ;AACV,yBAAmB,IAAI,OAAO,MAAM,OAAO,OAAO;AAAA,IACpD;AAAA,EACF;AACF;AAEO,SAAS,MAAM,OAAoD;AACxE,MAAI,SAAgC;AACpC,MAAI,YAA2B;AAE/B,MAAI,OAAO,UAAU,UAAU;AAC7B,gBAAY;AACZ,aACE,uBAAuB,IAAI,KAAK,KAAK,mBAAmB,IAAI,KAAK,KAAK;AACxE,QAAI,CAAC,QAAQ;AACX,cAAQ,MAAM,qBAAqB,KAAK,cAAc;AACtD;AAAA,IACF;AAAA,EACF,WAAW,OAAO,UAAU,YAAY,UAAU,MAAM;AACtD,UAAM,SAAS,YAAY,KAAK;AAChC,QAAI,QAAQ;AACV,kBAAY,OAAO;AACnB,eAAS,OAAO;AAAA,IAClB,OAAO;AACL,cAAQ,MAAM,4CAA4C;AAC1D;AAAA,IACF;AAAA,EACF,OAAO;AACL,YAAQ,MAAM,8CAA8C;AAC5D;AAAA,EACF;AAEA,MAAI,UAAU,WAAW;AACvB,WAAO,gBAAgB,WAAW,MAAM;AAAA,EAC1C;AACF;","names":[]}
package/dist/index.d.cts CHANGED
@@ -5,7 +5,7 @@ interface ToastConfig {
5
5
  position?: "top" | "right" | "left" | "bottom" | "center" | "top right" | "top left" | "bottom right" | "bottom left";
6
6
  }
7
7
  interface EmessageOptions {
8
- type?: MessageType;
8
+ type?: MessageType | boolean;
9
9
  break?: boolean;
10
10
  toast?: boolean | ToastConfig;
11
11
  returnEM?: boolean;
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ interface ToastConfig {
5
5
  position?: "top" | "right" | "left" | "bottom" | "center" | "top right" | "top left" | "bottom right" | "bottom left";
6
6
  }
7
7
  interface EmessageOptions {
8
- type?: MessageType;
8
+ type?: MessageType | boolean;
9
9
  break?: boolean;
10
10
  toast?: boolean | ToastConfig;
11
11
  returnEM?: boolean;
package/dist/index.mjs CHANGED
@@ -66,17 +66,40 @@ function parseConfig(config) {
66
66
  }
67
67
  function processEmessage(errorName, config) {
68
68
  const message = config.message;
69
- const type = config.type ?? "err";
70
- switch (type) {
71
- case "log":
72
- console.log(message);
73
- break;
74
- case "war":
75
- console.warn(message);
76
- break;
77
- case "err":
78
- console.error(message);
79
- break;
69
+ let consoleType;
70
+ if (config.type === false) {
71
+ consoleType = false;
72
+ } else if (config.type === true || config.type === void 0) {
73
+ consoleType = "err";
74
+ } else {
75
+ consoleType = config.type;
76
+ }
77
+ if (consoleType) {
78
+ if (isBrowser()) {
79
+ switch (consoleType) {
80
+ case "log":
81
+ console.log(message);
82
+ break;
83
+ case "war":
84
+ console.warn(message);
85
+ break;
86
+ case "err":
87
+ console.error(message);
88
+ break;
89
+ }
90
+ } else {
91
+ switch (consoleType) {
92
+ case "log":
93
+ console.log(`\x1B[30;47m LOG \x1B[0m ${message}`);
94
+ break;
95
+ case "war":
96
+ console.warn(`\x1B[37;43m WARN \x1B[0m ${message}`);
97
+ break;
98
+ case "err":
99
+ console.error(`\x1B[37;41m ERROR \x1B[0m ${message}`);
100
+ break;
101
+ }
102
+ }
80
103
  }
81
104
  if (config.toast && isBrowser()) {
82
105
  showToast(message, config.toast);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/store.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["import type { StoredEmessage } from \"./types\";\r\n\r\nexport const individualMessageStore = new Map<string, StoredEmessage>();\r\nexport const globalMessageStore = new Map<string, StoredEmessage>();\r\n","import { ToastConfig } from \"./types\";\r\n\r\nexport function isBrowser(): boolean {\r\n return typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\r\n}\r\n\r\nexport function showToast(\r\n message: string,\r\n toastConfig: boolean | ToastConfig\r\n): void {\r\n if (!isBrowser()) {\r\n return;\r\n }\r\n\r\n const toast = document.createElement(\"div\");\r\n\r\n const config: ToastConfig = typeof toastConfig === \"object\" ? toastConfig : {};\r\n\r\n toast.textContent = config.message || message;\r\n\r\n // Base styles are applied via CSS, but some can be defaults.\r\n toast.className = \"emessage-toast\";\r\n if (config.style) {\r\n toast.classList.add(...config.style.split(\" \"));\r\n }\r\n\r\n // Positioning\r\n const position = config.position || \"top-right\";\r\n toast.setAttribute(\"data-position\", position);\r\n\r\n document.body.appendChild(toast);\r\n\r\n // Animate in\r\n setTimeout(() => {\r\n toast.classList.add(\"visible\");\r\n }, 10);\r\n\r\n // Animate out and remove\r\n setTimeout(() => {\r\n toast.classList.remove(\"visible\");\r\n toast.addEventListener(\"transitionend\", () => {\r\n if (toast.parentElement) {\r\n toast.parentElement.removeChild(toast);\r\n }\r\n });\r\n }, 3000);\r\n}\r\n","import { individualMessageStore, globalMessageStore } from \"./store\";\r\nimport type {\r\n EmessageConfig,\r\n EmessageOptions,\r\n StoredEmessage,\r\n ToastConfig,\r\n} from \"./types\";\r\nimport { isBrowser, showToast } from \"./utils\";\r\n\r\nfunction parseConfig(\r\n config: Record<string, any>\r\n): { name: string; options: StoredEmessage } | null {\r\n const options: EmessageOptions = {};\r\n let message: string | null = null;\r\n let name: string | null = null;\r\n const optionKeys = [\"type\", \"break\", \"toast\", \"returnEM\", \"callBack\"];\r\n\r\n for (const key in config) {\r\n if (Object.prototype.hasOwnProperty.call(config, key)) {\r\n if (optionKeys.includes(key)) {\r\n (options as any)[key] = config[key];\r\n } else {\r\n if (name !== null) {\r\n console.warn(\r\n `emessages: Found multiple potential error names in one config object. Using first one found: \"${name}\".`\r\n );\r\n continue;\r\n }\r\n name = key;\r\n message = String(config[key]);\r\n }\r\n }\r\n }\r\n\r\n if (name === null || message === null) {\r\n console.error(\r\n \"emessages: Invalid config object. Could not find error name and message.\",\r\n config\r\n );\r\n return null;\r\n }\r\n\r\n return { name, options: { ...options, message } };\r\n}\r\n\r\nfunction processEmessage(\r\n errorName: string,\r\n config: StoredEmessage\r\n): string | void {\r\n const message = config.message;\r\n const type = config.type ?? \"err\";\r\n\r\n // 1. Console log\r\n switch (type) {\r\n case \"log\":\r\n console.log(message);\r\n break;\r\n case \"war\":\r\n console.warn(message);\r\n break;\r\n case \"err\":\r\n console.error(message);\r\n break;\r\n }\r\n\r\n // 2. Toast notification\r\n if (config.toast && isBrowser()) {\r\n showToast(message, config.toast);\r\n }\r\n\r\n // 3. Callback\r\n if (config.callBack) {\r\n try {\r\n config.callBack();\r\n } catch (e: any) {\r\n console.error(\r\n `emessages: Error in callBack for \"${errorName}\":`,\r\n e.message\r\n );\r\n }\r\n }\r\n\r\n // 4. Return error message\r\n if (config.returnEM) {\r\n return message;\r\n }\r\n\r\n // 5. Break execution\r\n if (config.break ?? true) {\r\n if (isBrowser()) {\r\n throw new Error(message);\r\n } else {\r\n process.exit(1);\r\n }\r\n }\r\n}\r\n\r\nexport function Emessage(...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n individualMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n}\r\n\r\nEmessage.global = function (...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n globalMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n};\r\n\r\nexport function showE(error: string | Record<string, any>): string | void {\r\n let config: StoredEmessage | null = null;\r\n let errorName: string | null = null;\r\n\r\n if (typeof error === \"string\") {\r\n errorName = error;\r\n config =\r\n individualMessageStore.get(error) ?? globalMessageStore.get(error) ?? null;\r\n if (!config) {\r\n console.error(`emessages: Error \"${error}\" not found.`);\r\n return;\r\n }\r\n } else if (typeof error === \"object\" && error !== null) {\r\n const parsed = parseConfig(error);\r\n if (parsed) {\r\n errorName = parsed.name;\r\n config = parsed.options;\r\n } else {\r\n console.error(\"emessages: Invalid object passed to showE.\");\r\n return;\r\n }\r\n } else {\r\n console.error(\"emessages: Invalid argument passed to showE.\");\r\n return;\r\n }\r\n\r\n if (config && errorName) {\r\n return processEmessage(errorName, config);\r\n }\r\n}\r\n"],"mappings":";AAEO,IAAM,yBAAyB,oBAAI,IAA4B;AAC/D,IAAM,qBAAqB,oBAAI,IAA4B;;;ACD3D,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AACrE;AAEO,SAAS,UACd,SACA,aACM;AACN,MAAI,CAAC,UAAU,GAAG;AAChB;AAAA,EACF;AAEA,QAAM,QAAQ,SAAS,cAAc,KAAK;AAE1C,QAAM,SAAsB,OAAO,gBAAgB,WAAW,cAAc,CAAC;AAE7E,QAAM,cAAc,OAAO,WAAW;AAGtC,QAAM,YAAY;AAClB,MAAI,OAAO,OAAO;AAChB,UAAM,UAAU,IAAI,GAAG,OAAO,MAAM,MAAM,GAAG,CAAC;AAAA,EAChD;AAGA,QAAM,WAAW,OAAO,YAAY;AACpC,QAAM,aAAa,iBAAiB,QAAQ;AAE5C,WAAS,KAAK,YAAY,KAAK;AAG/B,aAAW,MAAM;AACf,UAAM,UAAU,IAAI,SAAS;AAAA,EAC/B,GAAG,EAAE;AAGL,aAAW,MAAM;AACf,UAAM,UAAU,OAAO,SAAS;AAChC,UAAM,iBAAiB,iBAAiB,MAAM;AAC5C,UAAI,MAAM,eAAe;AACvB,cAAM,cAAc,YAAY,KAAK;AAAA,MACvC;AAAA,IACF,CAAC;AAAA,EACH,GAAG,GAAI;AACT;;;ACrCA,SAAS,YACP,QACkD;AAClD,QAAM,UAA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AG;AACf,YAAM,IAAI,MAAM,OAAO;AAAA,IACzB,OAAO;AACL,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AACF;AAEO,SAAS,YAAY,SAA2B;AACrD,aAAW,UAAU,SAAS;AAC5B,UAAM,SAAS,YAAY,MAAM;AACjC,QAAI,QAAQ;AACV,6BAAuB,IAAI,OAAO,MAAM,OAAO,OAAO;AAAA,IACxD;AAAA,EACF;AACF;AAEA,SAAS,SAAS,YAAa,SAA2B;AACxD,aAAW,UAAU,SAAS;AAC5B,UAAM,SAAS,YAAY,MAAM;AACjC,QAAI,QAAQ;AACV,yBAAmB,IAAI,OAAO,MAAM,OAAO,OAAO;AAAA,IACpD;AAAA,EACF;AACF;AAEO,SAAS,MAAM,OAAoD;AACxE,MAAI,SAAgC;AACpC,MAAI,YAA2B;AAE/B,MAAI,OAAO,UAAU,UAAU;AAC7B,gBAAY;AACZ,aACE,uBAAuB,IAAI,KAAK,KAAK,mBAAmB,IAAI,KAAK,KAAK;AACxE,QAAI,CAAC,QAAQ;AACX,cAAQ,MAAM,qBAAqB,KAAK,cAAc;AACtD;AAAA,IACF;AAAA,EACF,WAAW,OAAO,UAAU,YAAY,UAAU,MAAM;AACtD,UAAM,SAAS,YAAY,KAAK;AAChC,QAAI,QAAQ;AACV,kBAAY,OAAO;AACnB,eAAS,OAAO;AAAA,IAClB,OAAO;AACL,cAAQ,MAAM,4CAA4C;AAC1D;AAAA,IACF;AAAA,EACF,OAAO;AACL,YAAQ,MAAM,8CAA8C;AAC5D;AAAA,EACF;AAEA,MAAI,UAAU,WAAW;AACvB,WAAO,gBAAgB,WAAW,MAAM;AAAA,EAC1C;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/store.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["import type { StoredEmessage } from \"./types\";\r\n\r\nexport const individualMessageStore = new Map<string, StoredEmessage>();\r\nexport const globalMessageStore = new Map<string, StoredEmessage>();\r\n","import { ToastConfig } from \"./types\";\r\n\r\nexport function isBrowser(): boolean {\r\n return typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\r\n}\r\n\r\nexport function showToast(\r\n message: string,\r\n toastConfig: boolean | ToastConfig\r\n): void {\r\n if (!isBrowser()) {\r\n return;\r\n }\r\n\r\n const toast = document.createElement(\"div\");\r\n\r\n const config: ToastConfig = typeof toastConfig === \"object\" ? toastConfig : {};\r\n\r\n toast.textContent = config.message || message;\r\n\r\n // Base styles are applied via CSS, but some can be defaults.\r\n toast.className = \"emessage-toast\";\r\n if (config.style) {\r\n toast.classList.add(...config.style.split(\" \"));\r\n }\r\n\r\n // Positioning\r\n const position = config.position || \"top-right\";\r\n toast.setAttribute(\"data-position\", position);\r\n\r\n document.body.appendChild(toast);\r\n\r\n // Animate in\r\n setTimeout(() => {\r\n toast.classList.add(\"visible\");\r\n }, 10);\r\n\r\n // Animate out and remove\r\n setTimeout(() => {\r\n toast.classList.remove(\"visible\");\r\n toast.addEventListener(\"transitionend\", () => {\r\n if (toast.parentElement) {\r\n toast.parentElement.removeChild(toast);\r\n }\r\n });\r\n }, 3000);\r\n}\r\n","import { individualMessageStore, globalMessageStore } from \"./store\";\r\nimport type {\r\n EmessageConfig,\r\n EmessageOptions,\r\n StoredEmessage,\r\n ToastConfig,\r\n MessageType,\r\n} from \"./types\";\r\nimport { isBrowser, showToast } from \"./utils\";\r\n\r\nfunction parseConfig(\r\n config: Record<string, any>\r\n): { name: string; options: StoredEmessage } | null {\r\n const options: EmessageOptions = {};\r\n let message: string | null = null;\r\n let name: string | null = null;\r\n const optionKeys = [\"type\", \"break\", \"toast\", \"returnEM\", \"callBack\"];\r\n\r\n for (const key in config) {\r\n if (Object.prototype.hasOwnProperty.call(config, key)) {\r\n if (optionKeys.includes(key)) {\r\n (options as any)[key] = config[key];\r\n } else {\r\n if (name !== null) {\r\n console.warn(\r\n `emessages: Found multiple potential error names in one config object. Using first one found: \"${name}\".`\r\n );\r\n continue;\r\n }\r\n name = key;\r\n message = String(config[key]);\r\n }\r\n }\r\n }\r\n\r\n if (name === null || message === null) {\r\n console.error(\r\n \"emessages: Invalid config object. Could not find error name and message.\",\r\n config\r\n );\r\n return null;\r\n }\r\n\r\n return { name, options: { ...options, message } };\r\n}\r\n\r\nfunction processEmessage(\r\n errorName: string,\r\n config: StoredEmessage\r\n): string | void {\r\n const message = config.message;\r\n\r\n let consoleType: MessageType | false;\r\n if (config.type === false) {\r\n consoleType = false;\r\n } else if (config.type === true || config.type === undefined) {\r\n consoleType = \"err\";\r\n } else {\r\n consoleType = config.type;\r\n }\r\n\r\n // 1. Console log\r\n if (consoleType) {\r\n if (isBrowser()) {\r\n switch (consoleType) {\r\n case \"log\":\r\n console.log(message);\r\n break;\r\n case \"war\":\r\n console.warn(message);\r\n break;\r\n case \"err\":\r\n console.error(message);\r\n break;\r\n }\r\n } else {\r\n switch (consoleType) {\r\n case \"log\":\r\n console.log(`\\x1b[30;47m LOG \\x1b[0m ${message}`);\r\n break;\r\n case \"war\":\r\n console.warn(`\\x1b[37;43m WARN \\x1b[0m ${message}`);\r\n break;\r\n case \"err\":\r\n console.error(`\\x1b[37;41m ERROR \\x1b[0m ${message}`);\r\n break;\r\n }\r\n }\r\n }\r\n\r\n // 2. Toast notification\r\n if (config.toast && isBrowser()) {\r\n showToast(message, config.toast);\r\n }\r\n\r\n // 3. Callback\r\n if (config.callBack) {\r\n try {\r\n config.callBack();\r\n } catch (e: any) {\r\n console.error(\r\n `emessages: Error in callBack for \"${errorName}\":`,\r\n e.message\r\n );\r\n }\r\n }\r\n\r\n // 4. Return error message\r\n if (config.returnEM) {\r\n return message;\r\n }\r\n\r\n // 5. Break execution\r\n if (config.break ?? true) {\r\n if (isBrowser()) {\r\n throw new Error(message);\r\n } else {\r\n process.exit(1);\r\n }\r\n }\r\n}\r\n\r\nexport function Emessage(...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n individualMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n}\r\n\r\nEmessage.global = function (...configs: EmessageConfig[]) {\r\n for (const config of configs) {\r\n const parsed = parseConfig(config);\r\n if (parsed) {\r\n globalMessageStore.set(parsed.name, parsed.options);\r\n }\r\n }\r\n};\r\n\r\nexport function showE(error: string | Record<string, any>): string | void {\r\n let config: StoredEmessage | null = null;\r\n let errorName: string | null = null;\r\n\r\n if (typeof error === \"string\") {\r\n errorName = error;\r\n config =\r\n individualMessageStore.get(error) ?? globalMessageStore.get(error) ?? null;\r\n if (!config) {\r\n console.error(`emessages: Error \"${error}\" not found.`);\r\n return;\r\n }\r\n } else if (typeof error === \"object\" && error !== null) {\r\n const parsed = parseConfig(error);\r\n if (parsed) {\r\n errorName = parsed.name;\r\n config = parsed.options;\r\n } else {\r\n console.error(\"emessages: Invalid object passed to showE.\");\r\n return;\r\n }\r\n } else {\r\n console.error(\"emessages: Invalid argument passed to showE.\");\r\n return;\r\n }\r\n\r\n if (config && errorName) {\r\n return processEmessage(errorName, config);\r\n }\r\n}\r\n"],"mappings":";AAEO,IAAM,yBAAyB,oBAAI,IAA4B;AAC/D,IAAM,qBAAqB,oBAAI,IAA4B;;;ACD3D,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AACrE;AAEO,SAAS,UACd,SACA,aACM;AACN,MAAI,CAAC,UAAU,GAAG;AAChB;AAAA,EACF;AAEA,QAAM,QAAQ,SAAS,cAAc,KAAK;AAE1C,QAAM,SAAsB,OAAO,gBAAgB,WAAW,cAAc,CAAC;AAE7E,QAAM,cAAc,OAAO,WAAW;AAGtC,QAAM,YAAY;AAClB,MAAI,OAAO,OAAO;AAChB,UAAM,UAAU,IAAI,GAAG,OAAO,MAAM,MAAM,GAAG,CAAC;AAAA,EAChD;AAGA,QAAM,WAAW,OAAO,YAAY;AACpC,QAAM,aAAa,iBAAiB,QAAQ;AAE5C,WAAS,KAAK,YAAY,KAAK;AAG/B,aAAW,MAAM;AACf,UAAM,UAAU,IAAI,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AAI,OAAO,UAAU,UAAU;AAC7B,gBAAY;AACZ,aACE,uBAAuB,IAAI,KAAK,KAAK,mBAAmB,IAAI,KAAK,KAAK;AACxE,QAAI,CAAC,QAAQ;AACX,cAAQ,MAAM,qBAAqB,KAAK,cAAc;AACtD;AAAA,IACF;AAAA,EACF,WAAW,OAAO,UAAU,YAAY,UAAU,MAAM;AACtD,UAAM,SAAS,YAAY,KAAK;AAChC,QAAI,QAAQ;AACV,kBAAY,OAAO;AACnB,eAAS,OAAO;AAAA,IAClB,OAAO;AACL,cAAQ,MAAM,4CAA4C;AAC1D;AAAA,IACF;AAAA,EACF,OAAO;AACL,YAAQ,MAAM,8CAA8C;AAC5D;AAAA,EACF;AAEA,MAAI,UAAU,WAAW;AACvB,WAAO,gBAAgB,WAAW,MAAM;AAAA,EAC1C;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emessages",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
4
  "description": "A flexible error handling library for JS/TS. Define custom errors with console, toast, and callbacks, supporting global/local scopes and all environments.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -25,6 +25,7 @@
25
25
  "notification"
26
26
  ],
27
27
  "sideEffects": true,
28
+ "license": "MIT",
28
29
  "scripts": {
29
30
  "build": "tsup"
30
31
  },