immediate-error 2.0.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.
Files changed (3) hide show
  1. package/README.md +25 -5
  2. package/index.js +62 -3
  3. package/package.json +20 -5
package/README.md CHANGED
@@ -1,5 +1,25 @@
1
- # Immediate-error
2
- ```javascript
3
- const immediateError = require('immediate-error')
4
- immediateError('Aaaaah') // this will throw an error with the message Aaaaah
5
- ```
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,3 +1,62 @@
1
- module.exports = function immediateError(message = 'You asked for it') {
2
- throw new Error(message)
3
- }
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
+
62
+ module.exports.ERROR = ERROR
package/package.json CHANGED
@@ -1,15 +1,30 @@
1
1
  {
2
2
  "name": "immediate-error",
3
- "version": "2.0.0",
4
- "description": "Causes an error when run.",
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
- "author": "tj-commits/87f",
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",
10
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",
11
25
  "dependencies": {
12
- "fox": "^3.0.0-alpha.1",
13
- "immediate-error": "^0.0.1"
26
+ "assert-fn": "^1.0.1",
27
+ "none": "^1.0.0",
28
+ "vanilla-javascript": "^1.1.1"
14
29
  }
15
30
  }