catch-match 2.0.1 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +48 -1
- package/dist/__tests__/main.test.d.ts +1 -0
- package/dist/__tests__/main.test.js +440 -0
- package/dist/__tests__/main.test.js.map +1 -0
- package/dist/main.d.ts +16 -11
- package/dist/main.js +82 -28
- package/dist/main.js.map +1 -1
- package/package.json +8 -2
- package/src/__tests__/main.test.ts +485 -206
- package/src/main.ts +101 -48
package/dist/main.js
CHANGED
@@ -1,44 +1,98 @@
|
|
1
|
-
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
10
|
+
export function $try(body) {
|
11
|
+
let caught = false;
|
2
12
|
let error;
|
13
|
+
let bodyResponse;
|
3
14
|
let result;
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
15
|
+
const isSameError = (e1, error) => e1 === error || e1 === (error === null || error === void 0 ? void 0 : error.constructor);
|
16
|
+
function handleErrors(err, err2, handler) {
|
17
|
+
if (isSameError(err, err2) || (Array.isArray(err) && err.some(e => isSameError(e, err2)))) {
|
18
|
+
handler(err2);
|
19
|
+
caught = true;
|
20
|
+
}
|
8
21
|
}
|
9
|
-
|
10
|
-
|
22
|
+
function buildResult(br) {
|
23
|
+
if (br instanceof Promise) {
|
24
|
+
const bodyPromise = br;
|
25
|
+
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
26
|
+
bodyPromise.then((response) => {
|
27
|
+
resolve({
|
28
|
+
value: response,
|
29
|
+
error: undefined,
|
30
|
+
});
|
31
|
+
}).catch((e) => {
|
32
|
+
resolve({
|
33
|
+
value: undefined,
|
34
|
+
error: e,
|
35
|
+
});
|
36
|
+
});
|
37
|
+
}));
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
return {
|
41
|
+
value: br,
|
42
|
+
error: undefined,
|
43
|
+
};
|
44
|
+
}
|
11
45
|
}
|
12
46
|
const chain = {
|
13
47
|
catch: (err, handler) => {
|
14
|
-
if (
|
15
|
-
|
48
|
+
if (result instanceof Promise) {
|
49
|
+
result.then((response) => {
|
50
|
+
typeof response.error !== 'undefined' && !caught && handleErrors(err, response.error, handler);
|
51
|
+
});
|
16
52
|
}
|
17
|
-
|
18
|
-
|
53
|
+
else {
|
54
|
+
error && !caught && handleErrors(err, error, handler);
|
19
55
|
}
|
20
|
-
|
21
|
-
err.some(isSameInstance) && handler(context);
|
22
|
-
}
|
23
|
-
return chain;
|
56
|
+
return result;
|
24
57
|
},
|
25
|
-
other: (
|
26
|
-
if (
|
27
|
-
|
58
|
+
other: (callback) => {
|
59
|
+
if (result instanceof Promise) {
|
60
|
+
result.then((response) => {
|
61
|
+
typeof response.error !== 'undefined' && !caught && callback(response.error);
|
62
|
+
});
|
28
63
|
}
|
29
|
-
|
30
|
-
|
31
|
-
}
|
64
|
+
else {
|
65
|
+
typeof result.error !== 'undefined' && !caught && callback && callback(result.error);
|
66
|
+
}
|
67
|
+
return result;
|
32
68
|
},
|
33
69
|
finally: (callback) => {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
}
|
70
|
+
if (result instanceof Promise) {
|
71
|
+
result.then((response) => {
|
72
|
+
callback(response);
|
73
|
+
});
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
callback({
|
77
|
+
value: result.value,
|
78
|
+
error: result.error,
|
79
|
+
});
|
80
|
+
}
|
81
|
+
return result;
|
39
82
|
},
|
40
83
|
};
|
41
|
-
|
84
|
+
try {
|
85
|
+
bodyResponse = body();
|
86
|
+
result = Object.assign(buildResult(bodyResponse), chain);
|
87
|
+
}
|
88
|
+
catch (e) {
|
89
|
+
error = e;
|
90
|
+
result = Object.assign(chain, {
|
91
|
+
value: undefined,
|
92
|
+
error: e,
|
93
|
+
});
|
94
|
+
}
|
95
|
+
return result;
|
42
96
|
}
|
43
|
-
export default
|
97
|
+
export default $try;
|
44
98
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;;;;AAgCA,MAAM,UAAU,IAAI,CAAS,IAAqB;IAChD,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,KAA2E,CAAC;IAChF,IAAI,YAAsC,CAAC;IAC3C,IAAI,MAAiC,CAAC;IAEtC,MAAM,WAAW,GAAG,CAAC,EAAO,EAAE,KAAU,EAAE,EAAE,CAAC,EAAE,KAAK,KAAK,IAAI,EAAE,MAAK,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,CAAA,CAAC;IAEvF,SAAS,YAAY,CAAC,GAAU,EAAE,IAAS,EAAE,OAA8D;QACzG,IAAI,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE;YACzF,OAAO,CAAC,IAAI,CAAC,CAAC;YACd,MAAM,GAAG,IAAI,CAAC;SACf;IACH,CAAC;IAED,SAAS,WAAW,CAAC,EAAuB;QAC1C,IAAI,EAAE,YAAY,OAAO,EAAE;YACzB,MAAM,WAAW,GAAG,EAAqB,CAAC;YAC1C,OAAO,IAAI,OAAO,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;iBAAM;gBACL,OAAO,MAAM,CAAC,KAAK,KAAK,WAAW,IAAI,CAAC,MAAM,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACtF;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE;YACpB,IAAI,MAAM,YAAY,OAAO,EAAE;gBAC7B,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;oBACvB,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBACrB,CAAC,CAAC,CAAC;aACJ;iBAAM;gBACL,QAAQ,CAAC;oBACP,KAAK,EAAE,MAAM,CAAC,KAAK;oBACnB,KAAK,EAAE,MAAM,CAAC,KAAK;iBACpB,CAAC,CAAC;aACJ;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;IAEF,IAAI;QACF,YAAY,GAAG,IAAI,EAAE,CAAC;QACtB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,CAAC;KAC1D;IAAC,OAAO,CAAC,EAAE;QACV,KAAK,GAAG,CAAC,CAAC;QACV,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;YAC5B,KAAK,EAAE,SAAS;YAChB,KAAK,EAAE,CAAC;SACT,CAAC,CAAC;KACJ;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,eAAe,IAAI,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "catch-match",
|
3
|
-
"version": "
|
3
|
+
"version": "3.0.3",
|
4
4
|
"repository": {
|
5
5
|
"url": "https://github.com/kobzarvs/catch-match"
|
6
6
|
},
|
@@ -12,7 +12,13 @@
|
|
12
12
|
"errors",
|
13
13
|
"exceptions",
|
14
14
|
"throw",
|
15
|
-
"finally"
|
15
|
+
"finally",
|
16
|
+
"promises",
|
17
|
+
"resolve",
|
18
|
+
"reject",
|
19
|
+
"flow",
|
20
|
+
"control",
|
21
|
+
"process"
|
16
22
|
],
|
17
23
|
"main": "dist/main.js",
|
18
24
|
"scripts": {
|