immediate-error 2.1.0 → 3.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.
- package/README.md +25 -13
- package/index.js +61 -57
- package/package.json +23 -4
package/README.md
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
# Immediate-error
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
immediateError('
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
immediateError('
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
# Immediate-error
|
|
2
|
+
|
|
3
|
+
This is a utility to throw an error
|
|
4
|
+
|
|
5
|
+
```javascript
|
|
6
|
+
|
|
7
|
+
const immediateError = require('immediate-error')
|
|
8
|
+
|
|
9
|
+
const { ERROR } = immediateError
|
|
10
|
+
|
|
11
|
+
immediateError('Aaaaah') // this will throw an error with the message Aaaaah
|
|
12
|
+
|
|
13
|
+
immediateError('Aaaaah', { errorType: ERROR.Error }) // does the same thing as above because by default errorType is ERROR.Error
|
|
14
|
+
|
|
15
|
+
immediateError('Assertion error', { errorType: ERROR.AssertionError }) // throws an assertionerror
|
|
16
|
+
|
|
17
|
+
immediateError('Range error', { errorType: ERROR.RangeError }) // throws a rangeerror
|
|
18
|
+
|
|
19
|
+
immediateError('Reference error', { errorType: ERROR.ReferenceError }) // throws an referenceerror
|
|
20
|
+
|
|
21
|
+
immediateError('Syntax error', { errorType: ERROR.SyntaxError }) // throws a syntaxerror
|
|
22
|
+
|
|
23
|
+
immediateError('type error', { errorType: ERROR.TypeError }) // throws a typeerror
|
|
24
|
+
|
|
25
|
+
```
|
package/index.js
CHANGED
|
@@ -1,58 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
1
|
+
require('vanilla-javascript')
|
|
2
|
+
require('none')()
|
|
3
|
+
|
|
4
|
+
const ERROR = Object.freeze({
|
|
5
|
+
Error: 0,
|
|
6
|
+
AssertionError: 1,
|
|
7
|
+
RangeError: 2,
|
|
8
|
+
ReferenceError: 3,
|
|
9
|
+
SyntaxError: 4,
|
|
10
|
+
TypeError: 5
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const assert = require('assert-fn')
|
|
14
|
+
var _____test_no_gray_out = assert
|
|
15
|
+
_____test_no_gray_out = _____test_no_gray_out
|
|
16
|
+
|
|
17
|
+
module.exports = function immediateError(message = 'You asked for it', options = {
|
|
18
|
+
errorType: ERROR.Error
|
|
19
|
+
}) {
|
|
20
|
+
_____test_no_gray_out = options
|
|
21
|
+
var str
|
|
22
|
+
switch(options.errorType) {
|
|
23
|
+
case ERROR.Error: {
|
|
24
|
+
str = 'throw new Error(message)'
|
|
25
|
+
break
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
case ERROR.AssertionError: {
|
|
29
|
+
str = "throw new assert.AssertionError(message)"
|
|
30
|
+
break
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
case ERROR.RangeError: {
|
|
34
|
+
str = "throw new RangeError(message)"
|
|
35
|
+
break
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
case ERROR.ReferenceError: {
|
|
39
|
+
str = "throw new ReferenceError(message)"
|
|
40
|
+
break
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
case ERROR.SyntaxError: {
|
|
44
|
+
str = "throw new SyntaxError(message)"
|
|
45
|
+
break
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
case ERROR.TypeError: {
|
|
49
|
+
str = "throw new TypeError(message)"
|
|
50
|
+
break
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
default: {
|
|
54
|
+
error = Error
|
|
55
|
+
break
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
eval(str)
|
|
60
|
+
}
|
|
61
|
+
|
|
58
62
|
module.exports.ERROR = ERROR
|
package/package.json
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "immediate-error",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Immediate-error",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
9
|
-
"
|
|
10
|
-
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/tj-commits/immediate-error.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"error",
|
|
15
|
+
"throw",
|
|
16
|
+
"immediate-error",
|
|
17
|
+
"tool"
|
|
18
|
+
],
|
|
19
|
+
"author": "tj-commits",
|
|
20
|
+
"license": "UNLICENSED",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/tj-commits/immediate-error/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/tj-commits/immediate-error#readme",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"assert-fn": "^1.0.1",
|
|
27
|
+
"none": "^1.0.0",
|
|
28
|
+
"vanilla-javascript": "^1.1.1"
|
|
29
|
+
}
|
|
11
30
|
}
|