emessages 2.1.1 → 2.1.2

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.cjs CHANGED
@@ -117,13 +117,13 @@ function processEmessage(errorName, config) {
117
117
  } else {
118
118
  switch (consoleType) {
119
119
  case "log":
120
- console.log(`\x1B[30;47m LOG \x1B[0m ${message}`);
120
+ console.log(`\x1B[30;47m ${message} \x1B[0m`);
121
121
  break;
122
122
  case "war":
123
- console.warn(`\x1B[37;43m WARN \x1B[0m ${message}`);
123
+ console.warn(`\x1B[37;43m ${message} \x1B[0m`);
124
124
  break;
125
125
  case "err":
126
- console.error(`\x1B[37;41m ERROR \x1B[0m ${message}`);
126
+ console.error(`\x1B[37;41m ${message} \x1B[0m`);
127
127
  break;
128
128
  }
129
129
  }
@@ -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 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;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,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;;;AFpCA,SAAS,YACP,QACkD;AAClD,QAAM,UAA2B,CAAC;AAClC,MAAI,UAAyB;AAC7B,MAAI,OAAsB;AAC1B,QAAM,aAAa,CAAC,QAAQ,SAAS,SAAS,YAAY,UAAU;AAEpE,aAAW,OAAO,QAAQ;AACxB,QAAI,OAAO,UAAU,eAAe,KAAK,QAAQ,GAAG,GAAG;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,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 ${message} \\x1b[0m`);\r\n break;\r\n case \"war\":\r\n console.warn(`\\x1b[37;43m ${message} \\x1b[0m`);\r\n break;\r\n case \"err\":\r\n console.error(`\\x1b[37;41m ${message} \\x1b[0m`);\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;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,gBAAg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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.mjs CHANGED
@@ -90,13 +90,13 @@ function processEmessage(errorName, config) {
90
90
  } else {
91
91
  switch (consoleType) {
92
92
  case "log":
93
- console.log(`\x1B[30;47m LOG \x1B[0m ${message}`);
93
+ console.log(`\x1B[30;47m ${message} \x1B[0m`);
94
94
  break;
95
95
  case "war":
96
- console.warn(`\x1B[37;43m WARN \x1B[0m ${message}`);
96
+ console.warn(`\x1B[37;43m ${message} \x1B[0m`);
97
97
  break;
98
98
  case "err":
99
- console.error(`\x1B[37;41m ERROR \x1B[0m ${message}`);
99
+ console.error(`\x1B[37;41m ${message} \x1B[0m`);
100
100
  break;
101
101
  }
102
102
  }
@@ -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 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,UA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,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 ${message} \\x1b[0m`);\r\n break;\r\n case \"war\":\r\n console.warn(`\\x1b[37;43m ${message} \\x1b[0m`);\r\n break;\r\n case \"err\":\r\n console.error(`\\x1b[37;41m ${message} \\x1b[0m`);\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,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;;;ACpCA,SAAS,YACP,QACkD;AAClD,QAAM,UAA2B,CAAC;AAClC,MAAI,UAAyB;AAC7B,MAAI,OAAsB;AAC1B,QAAM,aAA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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.1.1",
3
+ "version": "2.1.2",
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",