catch-match 0.2.1 → 1.0.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) 2020 Valeriy Kobzar
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/README.md CHANGED
@@ -1 +1,123 @@
1
1
  # catch-match
2
+
3
+ ## Motivation
4
+
5
+ ```java
6
+ try {
7
+ ...
8
+ } catch (ExceptionClass1 e) {
9
+ ....
10
+ } catch (ExceptionClass2, ExceptionClass3 e) {
11
+ ....
12
+ } catch (any) {
13
+ ...
14
+ } finally {
15
+ ....
16
+ }
17
+ ```
18
+
19
+ ## Getting started
20
+
21
+ ```shell
22
+ yarn add catch-match
23
+
24
+ or
25
+
26
+ npm install catch-match
27
+ ```
28
+
29
+ ```javascript
30
+ import { _try } from 'catch-match';
31
+ ```
32
+
33
+ ## Example 1
34
+ ```javascript
35
+ const result = _try(context => {
36
+ context.tmp = 'any context data';
37
+ console.log('start', context);
38
+ return [1, 2, 3, 4, 5]; // value
39
+ }).catch(SyntaxError, (context) => {
40
+ // noop
41
+ }).catch([TypeError, ReferenceError], (context) => {
42
+ // noop
43
+ }).other((error, context) => {
44
+ // noop
45
+ }).finally(({value, context, error}) => {
46
+ // value: [1, 2, 3, 4, 5]
47
+ // context: {tmp: 'any context data'}
48
+ // error: undefined
49
+ if (!error) {
50
+ return value.reverse();
51
+ }
52
+ });
53
+
54
+ console.log(result);
55
+ // {
56
+ // value: [5, 4, 3, 2, 1]
57
+ // context: {tmp: 'any context data'}
58
+ // error: undefined
59
+ // }
60
+
61
+ ```
62
+
63
+ ## Example 2
64
+ ```javascript
65
+ const result = _try(context => {
66
+ context.tmp = 'any context data';
67
+ console.log('start', context);
68
+ // ...
69
+ throw ReferenceError;
70
+ }).catch(SyntaxError, (context) => {
71
+ // noop
72
+ }).catch([TypeError, ReferenceError], (context) => {
73
+ // context: {tmp: 'any context data'}
74
+ }).other((error, context) => {
75
+ // noop
76
+ }).finally(({value, context, error}) => {
77
+ // value: undefined
78
+ // context: {tmp: 'any context data'}
79
+ // error: ReferenceError
80
+ if (!error) {
81
+ return value.reverse();
82
+ }
83
+ });
84
+
85
+ console.log(result);
86
+ // {
87
+ // value: undefined
88
+ // context: {tmp: 'any context data'}
89
+ // error: ReferenceError
90
+ // }
91
+
92
+ ```
93
+
94
+ ## Example 3
95
+ ```javascript
96
+ const result = _try(context => {
97
+ context.tmp = 'any context data';
98
+ console.log('start', context);
99
+ // ...
100
+ throw SyntaxError;
101
+ }).catch([TypeError, ReferenceError], (context) => {
102
+ // noop
103
+ }).other((error, context) => {
104
+ // error: SyntaxError
105
+ // context: {tmp: 'any context data'}
106
+ context.unexpectedError = true;
107
+ }).finally(({value, context, error}) => {
108
+ // value: undefined
109
+ // context: {tmp: 'any context data', unexpectedError: true}
110
+ // error: SyntaxError
111
+ if (!error) {
112
+ return value.reverse();
113
+ }
114
+ });
115
+
116
+ console.log(result);
117
+ // {
118
+ // value: undefined
119
+ // context: {tmp: 'any context data', unexpectedError: true}
120
+ // error: SyntaxError
121
+ // }
122
+
123
+ ```
File without changes
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,IAAI,CAAI,IAAyB;IAC/C,IAAI,KAAU,CAAC;IACf,IAAI,MAAS,CAAC;IACd,IAAI,OAAO,GAAQ,EAAE,CAAC;IACtB,MAAM,cAAc,GAAG,CAAC,EAAO,EAAE,EAAE,CAAC,EAAE,KAAK,KAAK,IAAI,EAAE,MAAK,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,CAAA,CAAC;IAE9E,IAAI;QACF,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;KACxB;IAAC,OAAO,CAAC,EAAE;QACV,KAAK,GAAG,CAAC,CAAC;KACX;IAED,MAAM,KAAK,GAAG;QACZ,KAAK,EAAE,CAAC,GAAQ,EAAE,OAA+B,EAAE,EAAE;YACnD,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE;gBACpB,OAAO,KAAK,CAAC;aACd;YACD,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE;gBACvB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;aAC7B;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBAC7B,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;aAC9C;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,KAAK,EAAE,CAAC,OAA2C,EAAE,EAAE;YACrD,IAAI,KAAK,EAAE;gBACT,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;aACpC;YACD,OAAO;gBACL,OAAO,EAAE,KAAK,CAAC,OAAO;aACvB,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,CAAC,QAAwC,EAAmB,EAAE;YACrE,OAAO;gBACL,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAC,CAAC,CAAC,CAAC,CAAC,MAAM;gBACpE,KAAK;gBACL,OAAO;aACR,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "catch-match",
3
- "version": "0.2.1",
3
+ "version": "1.0.1",
4
4
  "repository": {
5
5
  "url": "https://github.com/kobzarvs/catch-match"
6
6
  },
7
+ "type": "module",
8
+ "main": "dist/main.js",
7
9
  "scripts": {
8
10
  "build": "tsc"
9
11
  },
package/tsconfig.json CHANGED
@@ -13,7 +13,9 @@
13
13
  "declaration": true,
14
14
  "noUnusedLocals": true,
15
15
  "noUnusedParameters": true,
16
- "noImplicitReturns": true
16
+ "noImplicitReturns": true,
17
+ "alwaysStrict": true,
18
+ "outDir": "dist"
17
19
  },
18
20
  "include": ["./src"]
19
21
  }
package/src/main.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,IAAI,CAAI,IAAyB;IAC/C,IAAI,KAAU,CAAC;IACf,IAAI,MAAS,CAAC;IACd,IAAI,OAAO,GAAQ,EAAE,CAAC;IACtB,MAAM,cAAc,GAAG,CAAC,EAAO,EAAE,EAAE,CAAC,EAAE,KAAK,KAAK,IAAI,EAAE,MAAK,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,CAAA,CAAC;IAE9E,IAAI;QACF,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;KACxB;IAAC,OAAO,CAAC,EAAE;QACV,KAAK,GAAG,CAAC,CAAC;KACX;IAED,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