immediate-error 3.0.0 → 3.1.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/README.md +2 -2
- package/index.js +52 -22
- package/package.json +13 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Immediate-error
|
|
2
2
|
|
|
3
|
-
This is a utility to throw an error
|
|
3
|
+
This is a utility to throw an error.
|
|
4
4
|
|
|
5
5
|
```javascript
|
|
6
6
|
|
|
@@ -16,7 +16,7 @@ immediateError('Assertion error', { errorType: ERROR.AssertionError }) // throws
|
|
|
16
16
|
|
|
17
17
|
immediateError('Range error', { errorType: ERROR.RangeError }) // throws a rangeerror
|
|
18
18
|
|
|
19
|
-
immediateError('Reference error', { errorType: ERROR.ReferenceError }) // throws
|
|
19
|
+
immediateError('Reference error', { errorType: ERROR.ReferenceError }) // throws a referenceerror
|
|
20
20
|
|
|
21
21
|
immediateError('Syntax error', { errorType: ERROR.SyntaxError }) // throws a syntaxerror
|
|
22
22
|
|
package/index.js
CHANGED
|
@@ -1,62 +1,92 @@
|
|
|
1
1
|
require('vanilla-javascript')
|
|
2
|
+
require('vapor-js-npm')
|
|
2
3
|
require('none')()
|
|
3
4
|
|
|
5
|
+
const one = require('the-number-one').default // number one
|
|
6
|
+
const two = require('two') // no2
|
|
7
|
+
const five = require('five') //no5
|
|
8
|
+
const successor = require('successor') // + 1
|
|
9
|
+
global.jQuery = require('jquery')
|
|
10
|
+
require('jquery-basic-arithmetic-plugin') // why not use jquery for math?
|
|
11
|
+
const $ = jQuery // define jquery
|
|
12
|
+
const { throwop } = require('yanoop') // throwop
|
|
13
|
+
const throwError = require('throw-error') // nothing wrong with having another way to throw an error
|
|
14
|
+
const If = require('if') // conditional chaining for javascript
|
|
15
|
+
const clc = require('cli-color')
|
|
16
|
+
|
|
4
17
|
const ERROR = Object.freeze({
|
|
5
|
-
Error:
|
|
6
|
-
AssertionError:
|
|
7
|
-
RangeError:
|
|
8
|
-
ReferenceError:
|
|
9
|
-
SyntaxError:
|
|
10
|
-
TypeError:
|
|
18
|
+
Error:0,
|
|
19
|
+
AssertionError: one,
|
|
20
|
+
RangeError: two(),
|
|
21
|
+
ReferenceError: successor(two()),
|
|
22
|
+
SyntaxError: $.subtract(five(), one),
|
|
23
|
+
TypeError: five()
|
|
11
24
|
})
|
|
12
25
|
|
|
13
|
-
const assert = require('assert-fn')
|
|
14
|
-
|
|
15
|
-
_____test_no_gray_out = _____test_no_gray_out
|
|
26
|
+
const assert = require('assert-fn') // import assert
|
|
27
|
+
const vm = require('node:vm') // vm
|
|
16
28
|
|
|
17
|
-
module.exports = function immediateError(message = '
|
|
29
|
+
module.exports = function immediateError(message = 'YOU SUCK AT PROGRAMMING THERE WAS A FUCKING ERROR!', options = {
|
|
18
30
|
errorType: ERROR.Error
|
|
19
31
|
}) {
|
|
20
|
-
|
|
21
|
-
|
|
32
|
+
var error = new Error(message) /* create an error
|
|
33
|
+
variable and then use switch statement to set it*/
|
|
22
34
|
switch(options.errorType) {
|
|
23
35
|
case ERROR.Error: {
|
|
24
|
-
|
|
36
|
+
error = new Error(message)
|
|
25
37
|
break
|
|
26
38
|
}
|
|
27
39
|
|
|
28
40
|
case ERROR.AssertionError: {
|
|
29
|
-
|
|
41
|
+
error = new assert.AssertionError(message)
|
|
30
42
|
break
|
|
31
43
|
}
|
|
32
44
|
|
|
33
45
|
case ERROR.RangeError: {
|
|
34
|
-
|
|
46
|
+
error = new RangeError(message)
|
|
35
47
|
break
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
case ERROR.ReferenceError: {
|
|
39
|
-
|
|
51
|
+
error = new ReferenceError(message)
|
|
40
52
|
break
|
|
41
53
|
}
|
|
42
54
|
|
|
43
55
|
case ERROR.SyntaxError: {
|
|
44
|
-
|
|
56
|
+
error = new SyntaxError(message)
|
|
45
57
|
break
|
|
46
58
|
}
|
|
47
59
|
|
|
48
60
|
case ERROR.TypeError: {
|
|
49
|
-
|
|
61
|
+
error = new TypeError(message)
|
|
50
62
|
break
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
default: {
|
|
54
|
-
error = Error
|
|
66
|
+
error = new Error(message)
|
|
55
67
|
break
|
|
56
68
|
}
|
|
57
69
|
}
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
// make a vm context
|
|
71
|
+
const context = {
|
|
72
|
+
error,
|
|
73
|
+
throwError,
|
|
74
|
+
throwop,
|
|
75
|
+
rand: Math.random(),
|
|
76
|
+
If,
|
|
77
|
+
console,
|
|
78
|
+
clc
|
|
79
|
+
}
|
|
80
|
+
vm.createContext(context) // Contextify the object.
|
|
81
|
+
const script = new vm.Script(`
|
|
82
|
+
console.log(clc.redBright.bold(\`× THERE WAS AN ERROR!\`))
|
|
83
|
+
If(rand < 0.3).Then(() => {
|
|
84
|
+
throwError(error)
|
|
85
|
+
}).Else().If(rand > 0.3).Then(() => {
|
|
86
|
+
throwop(error)
|
|
87
|
+
}).Else(() => {
|
|
88
|
+
throw error
|
|
89
|
+
})`, { filename: `YOU SUCK AT PROGRAMMING THERE WAS AN ERROR!`})
|
|
90
|
+
script.runInContext(context)
|
|
60
91
|
}
|
|
61
|
-
|
|
62
92
|
module.exports.ERROR = ERROR
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "immediate-error",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Immediate-error",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,7 +24,18 @@
|
|
|
24
24
|
"homepage": "https://github.com/tj-commits/immediate-error#readme",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"assert-fn": "^1.0.1",
|
|
27
|
+
"cli-color": "^2.0.4",
|
|
28
|
+
"five": "^0.8.0",
|
|
29
|
+
"if": "^2.0.0",
|
|
30
|
+
"jquery": "^3.7.1",
|
|
31
|
+
"jquery-basic-arithmetic-plugin": "^1.1.0",
|
|
27
32
|
"none": "^1.0.0",
|
|
28
|
-
"
|
|
33
|
+
"successor": "^1.0.1",
|
|
34
|
+
"the-number-one": "^1.0.1",
|
|
35
|
+
"throw-error": "^1.0.0",
|
|
36
|
+
"two": "^1.0.7",
|
|
37
|
+
"vanilla-javascript": "^1.1.1",
|
|
38
|
+
"vapor-js-npm": "^1.4.6",
|
|
39
|
+
"yanoop": "^1.0.0"
|
|
29
40
|
}
|
|
30
41
|
}
|