yummies 4.1.1 → 4.2.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/errors.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { Maybe } from './utils/types.js';
2
+ type GetErrorTextEnhancer = (error: any) => string;
3
+ type GetErrorTextFormatErrorFn = (error: Error) => string;
4
+ /**
5
+ * Universal function for transforming any errors into readable error text
6
+ *
7
+ * This function can be enhanced with custom handlers using:
8
+ * - `getErrorText.unknownErrorText`
9
+ * - `getErrorText.formatError`
10
+ * - `getErrorText.enhance`
11
+ */
12
+ export declare const getErrorText: {
13
+ (error: unknown): string;
14
+ unknownErrorText: string;
15
+ formatError: Maybe<GetErrorTextFormatErrorFn>;
16
+ enhance: Maybe<GetErrorTextEnhancer>;
17
+ };
18
+ export {};
19
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,CAAC;AACnD,KAAK,yBAAyB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC;AAE1D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY;YAAW,OAAO;;;;CAkB1C,CAAC"}
package/errors.js ADDED
@@ -0,0 +1,29 @@
1
+ import { typeGuard } from './type-guard/index.js';
2
+ /**
3
+ * Universal function for transforming any errors into readable error text
4
+ *
5
+ * This function can be enhanced with custom handlers using:
6
+ * - `getErrorText.unknownErrorText`
7
+ * - `getErrorText.formatError`
8
+ * - `getErrorText.enhance`
9
+ */
10
+ export const getErrorText = (error) => {
11
+ if (!error) {
12
+ return getErrorText.unknownErrorText;
13
+ }
14
+ if (typeGuard.isString(error)) {
15
+ return error;
16
+ }
17
+ if (error instanceof Error) {
18
+ return getErrorText.formatError?.(error) ?? error.message;
19
+ }
20
+ if (getErrorText.enhance) {
21
+ return getErrorText.enhance(error);
22
+ }
23
+ else {
24
+ return getErrorText.unknownErrorText;
25
+ }
26
+ };
27
+ getErrorText.unknownErrorText = '';
28
+ getErrorText.formatError = null;
29
+ getErrorText.enhance = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yummies",
3
- "version": "4.1.1",
3
+ "version": "4.2.1",
4
4
  "keywords": [],
5
5
  "author": "js2me",
6
6
  "license": "MIT",
@@ -108,6 +108,11 @@
108
108
  "default": "./encodings.js",
109
109
  "types": "./encodings.d.ts"
110
110
  },
111
+ "./errors": {
112
+ "import": "./errors.js",
113
+ "default": "./errors.js",
114
+ "types": "./errors.d.ts"
115
+ },
111
116
  "./file": {
112
117
  "import": "./file.js",
113
118
  "default": "./file.js",