immediate-error 2.1.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 +25 -13
  2. package/index.js +92 -57
  3. package/package.json +35 -4
package/README.md CHANGED
@@ -1,13 +1,25 @@
1
- # Immediate-error
2
- This is a utility to throw an error
3
- ```javascript
4
- const immediateError = require('immediate-error')
5
- const { ERROR } = immediateError
6
- immediateError('Aaaaah') // this will throw an error with the message Aaaaah
7
- immediateError('Aaaaah', { errorType: ERROR.Error }) // does the same thing as above because by default errorType is ERROR.Error
8
- immediateError('Assertion error', { errorType: ERROR.AssertionError }) // throws an assertionerror
9
- immediateError('Range error', { errorType: ERROR.RangeError }) // throws a rangeerror
10
- immediateError('Reference error', { errorType: ERROR.ReferenceError }) // throws an referenceerror
11
- immediateError('Syntax error', { errorType: ERROR.SyntaxError }) // throws a syntaxerror
12
- immediateError('type error', { errorType: ERROR.TypeError }) // throws a typeerror
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 a 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,93 @@
1
- const ERROR = Object.freeze({
2
- Error: 0,
3
- AssertionError: 1,
4
- RangeError: 2,
5
- ReferenceError: 3,
6
- SyntaxError: 4,
7
- TypeError: 5
8
- })
9
-
10
- const assert = require('node:assert')
11
- var d = assert
12
- d = 1
13
-
14
- module.exports = function immediateError(message = 'You asked for it', options = {
15
- errorType: ERROR.Error
16
- }) {
17
- var str
18
- switch(options.errorType) {
19
- case ERROR.Error: {
20
- str = 'throw new Error(message)'
21
- break
22
- }
23
-
24
- case ERROR.AssertionError: {
25
- str = "throw new assert.AssertionError({ message })"
26
- break
27
- }
28
-
29
- case ERROR.RangeError: {
30
- str = "throw new RangeError(message)"
31
- break
32
- }
33
-
34
- case ERROR.ReferenceError: {
35
- str = "throw new ReferenceError(message)"
36
- break
37
- }
38
-
39
- case ERROR.SyntaxError: {
40
- str = "throw new SyntaxError(message)"
41
- break
42
- }
43
-
44
- case ERROR.TypeError: {
45
- str = "throw new TypeError(message)"
46
- break
47
- }
48
-
49
- default: {
50
- error = Error
51
- break
52
- }
53
- }
54
-
55
- eval(str)
56
- }
57
-
1
+ require('vanilla-javascript')
2
+ require('vapor-js-npm')
3
+ require('none')()
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
+
18
+ const ERROR = Object.freeze({
19
+ Error: zr0(),
20
+ AssertionError: one,
21
+ RangeError: two(),
22
+ ReferenceError: successor(two()),
23
+ SyntaxError: $.subtract(five(), one),
24
+ TypeError: five()
25
+ })
26
+
27
+ const assert = require('assert-fn') // import assert
28
+ const vm = require('node:vm') // vm
29
+
30
+ module.exports = function immediateError(message = 'YOU SUCK AT PROGRAMMING THERE WAS A FUCKING ERROR!', options = {
31
+ errorType: ERROR.Error
32
+ }) {
33
+ var error = new Error(message) /* create an error
34
+ variable and then use switch statement to set it*/
35
+ switch(options.errorType) {
36
+ case ERROR.Error: {
37
+ error = new Error(message)
38
+ break
39
+ }
40
+
41
+ case ERROR.AssertionError: {
42
+ error = new assert.AssertionError(message)
43
+ break
44
+ }
45
+
46
+ case ERROR.RangeError: {
47
+ error = new RangeError(message)
48
+ break
49
+ }
50
+
51
+ case ERROR.ReferenceError: {
52
+ error = new ReferenceError(message)
53
+ break
54
+ }
55
+
56
+ case ERROR.SyntaxError: {
57
+ error = new SyntaxError(message)
58
+ break
59
+ }
60
+
61
+ case ERROR.TypeError: {
62
+ error = new TypeError(message)
63
+ break
64
+ }
65
+
66
+ default: {
67
+ error = new Error(message)
68
+ break
69
+ }
70
+ }
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)
92
+ }
58
93
  module.exports.ERROR = ERROR
package/package.json CHANGED
@@ -1,11 +1,42 @@
1
1
  {
2
2
  "name": "immediate-error",
3
- "version": "2.1.0",
4
- "description": "Causes an error when run.",
3
+ "version": "3.1.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",
10
- "license": "UNLICENSED"
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
+ "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",
33
+ "none": "^1.0.0",
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"
41
+ }
11
42
  }