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