yummies 4.1.1 → 4.2.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/errors.d.ts +19 -0
- package/errors.d.ts.map +1 -0
- package/errors.js +29 -0
- package/package.json +6 -1
package/errors.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Maybe } from './utils/types.js';
|
|
2
|
+
type ErrorToTextEnhancer = (error: any) => string;
|
|
3
|
+
type ErrorToTextFormatErrorFn = (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
|
+
* - `errorToText.unknownErrorText`
|
|
9
|
+
* - `errorToText.formatError`
|
|
10
|
+
* - `errorToText.enhance`
|
|
11
|
+
*/
|
|
12
|
+
export declare const errorToText: {
|
|
13
|
+
(error: unknown): string;
|
|
14
|
+
unknownErrorText: string;
|
|
15
|
+
formatError: Maybe<ErrorToTextFormatErrorFn>;
|
|
16
|
+
enhance: Maybe<ErrorToTextEnhancer>;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=errors.d.ts.map
|
package/errors.d.ts.map
ADDED
|
@@ -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,mBAAmB,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,CAAC;AAClD,KAAK,wBAAwB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC;AAEzD;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW;YAAW,OAAO;;;;CAkBzC,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
|
+
* - `errorToText.unknownErrorText`
|
|
7
|
+
* - `errorToText.formatError`
|
|
8
|
+
* - `errorToText.enhance`
|
|
9
|
+
*/
|
|
10
|
+
export const errorToText = (error) => {
|
|
11
|
+
if (!error) {
|
|
12
|
+
return errorToText.unknownErrorText;
|
|
13
|
+
}
|
|
14
|
+
if (typeGuard.isString(error)) {
|
|
15
|
+
return error;
|
|
16
|
+
}
|
|
17
|
+
if (error instanceof Error) {
|
|
18
|
+
return errorToText.formatError?.(error) ?? error.message;
|
|
19
|
+
}
|
|
20
|
+
if (errorToText.enhance) {
|
|
21
|
+
return errorToText.enhance(error);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return errorToText.unknownErrorText;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
errorToText.unknownErrorText = '';
|
|
28
|
+
errorToText.formatError = null;
|
|
29
|
+
errorToText.enhance = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yummies",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
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",
|