catch-match 0.2.3 → 1.0.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +110 -0
  3. package/package.json +1 -1
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,111 @@
1
1
  # catch-match
2
+
3
+ ## Motivation
4
+
5
+ ## Java example
6
+
7
+ ```java
8
+ try {
9
+ ...
10
+ } catch (ExceptionClass1 e) {
11
+ ....
12
+ } catch (ExceptionClass2, ExceptionClass3 e) {
13
+ ....
14
+ } catch (any) {
15
+ ...
16
+ } finally {
17
+ ....
18
+ }
19
+ ```
20
+
21
+ ## Example 1
22
+ ```javascript
23
+ const result = _try(context => {
24
+ context.tmp = 'any context data';
25
+ console.log('start', context);
26
+ return [1, 2, 3, 4, 5]; // value
27
+ }).catch(SyntaxError, (context) => {
28
+ // noop
29
+ }).catch([TypeError, ReferenceError], (context) => {
30
+ // noop
31
+ }).other((error, context) => {
32
+ // noop
33
+ }).finally(({value, context, error}) => {
34
+ // value: [1, 2, 3, 4, 5]
35
+ // context: {tmp: 'any context data'}
36
+ // error: undefined
37
+ if (!error) {
38
+ return value.reverse();
39
+ }
40
+ });
41
+
42
+ console.log(result);
43
+ // {
44
+ // value: [5, 4, 3, 2, 1]
45
+ // context: {tmp: 'any context data'}
46
+ // error: undefined
47
+ // }
48
+
49
+ ```
50
+
51
+ ## Example 2
52
+ ```javascript
53
+ const result = _try(context => {
54
+ context.tmp = 'any context data';
55
+ console.log('start', context);
56
+ // ...
57
+ throw ReferenceError;
58
+ }).catch(SyntaxError, (context) => {
59
+ // noop
60
+ }).catch([TypeError, ReferenceError], (context) => {
61
+ // context: {tmp: 'any context data'}
62
+ }).other((error, context) => {
63
+ // noop
64
+ }).finally(({value, context, error}) => {
65
+ // value: undefined
66
+ // context: {tmp: 'any context data'}
67
+ // error: ReferenceError
68
+ if (!error) {
69
+ return value.reverse();
70
+ }
71
+ });
72
+
73
+ console.log(result);
74
+ // {
75
+ // value: undefined
76
+ // context: {tmp: 'any context data'}
77
+ // error: ReferenceError
78
+ // }
79
+
80
+ ```
81
+
82
+ ## Example 3
83
+ ```javascript
84
+ const result = _try(context => {
85
+ context.tmp = 'any context data';
86
+ console.log('start', context);
87
+ // ...
88
+ throw SyntaxError;
89
+ }).catch([TypeError, ReferenceError], (context) => {
90
+ // noop
91
+ }).other((error, context) => {
92
+ // error: SyntaxError
93
+ // context: {tmp: 'any context data'}
94
+ context.unexpectedError = true;
95
+ }).finally(({value, context, error}) => {
96
+ // value: undefined
97
+ // context: {tmp: 'any context data', unexpectedError: true}
98
+ // error: SyntaxError
99
+ if (!error) {
100
+ return value.reverse();
101
+ }
102
+ });
103
+
104
+ console.log(result);
105
+ // {
106
+ // value: undefined
107
+ // context: {tmp: 'any context data', unexpectedError: true}
108
+ // error: SyntaxError
109
+ // }
110
+
111
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catch-match",
3
- "version": "0.2.3",
3
+ "version": "1.0.0",
4
4
  "repository": {
5
5
  "url": "https://github.com/kobzarvs/catch-match"
6
6
  },