attempt-statement 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 (2) hide show
  1. package/attempt.js +38 -0
  2. package/package.json +11 -0
package/attempt.js ADDED
@@ -0,0 +1,38 @@
1
+ class attempt {
2
+ constructor(handler) {
3
+ if (!(this instanceof attempt)) return new attempt(handler)
4
+ this.trycode = handler
5
+ return this
6
+ }
7
+ rescue(handler) {
8
+ this.rescuehandler = handler
9
+ return this
10
+ }
11
+ else(handler) {
12
+ this.elsehandler = handler
13
+ return this
14
+ }
15
+ ensure(handler) {
16
+ this.ensurehandler = handler
17
+ return this
18
+ }
19
+ end() {
20
+ const dis = this
21
+ let error = false
22
+ try {
23
+ if (this.trycode) this.trycode()
24
+ } catch (e) {
25
+ error = true
26
+ if (this.rescuehandler) this.rescuehandler(e)
27
+ }
28
+
29
+ if (!error && this.elsehandler) {
30
+ this.elsehandler()
31
+ }
32
+
33
+ if (this.ensurehandler) this.ensurehandler()
34
+ }
35
+ }
36
+
37
+
38
+ module.exports = attempt
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "attempt-statement",
3
+ "version": "1.0.0",
4
+ "description": "An attempt statement for js",
5
+ "main": "attempt.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "fox",
10
+ "license": "UNLICENSED"
11
+ }