immediate-error 6.2.0 → 6.3.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 +5 -8
  2. package/index.js +96 -107
  3. package/package.json +43 -46
package/README.md CHANGED
@@ -38,14 +38,11 @@ immediateError('Error!', MyCustomError) // throws a MyCustomError with the messa
38
38
 
39
39
  ## Why?
40
40
 
41
- This module is great because it uses the best practices in JavaScript such as using dependencies like [`throw-error`](https://npmjs.com/package/throw-error) and [`yanoop`](https://npmjs.com/package/yanoop) to throw errors and using [`es-errors`](https://npmjs.com/package/es-errors) instead of using the error classes natively.
41
+ This module is great because it uses the best practices in JavaScript such as using dependencies like [`yanoop`](https://npmjs.com/package/yanoop) to throw errors and using [`es-errors`](https://npmjs.com/package/es-errors) instead of using the error classes natively.
42
42
 
43
- ## Show your support
44
-
45
- [Follow me on GitHub](https://github.com/tj-commits) and star my repositories.
43
+ ## why?
44
+ why not
46
45
 
47
- ## is this a joke?
46
+ ## Show your support
48
47
 
49
- Of course not!
50
- <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
51
- (Yes, it is.)
48
+ [Follow me on GitHub](https://github.com/tj-commits) and star my repositories.
package/index.js CHANGED
@@ -1,120 +1,109 @@
1
1
  require('vanilla-javascript')
2
2
  require('none')()
3
3
 
4
- const GetIntrinsic = require('get-intrinsic')
5
- const zero = require('number-zero')
6
- const one = require('the-number-one').default
7
- const two = require('two')
8
- const three = require('numeric-constant-three')
9
- const four = require('always-four')
10
- const five = require('five')
11
- const six = require('number-six')
12
- const seven = require('se7en')
13
- const { throwop } = require('yanoop')
14
- const throwError = require('throw-error')
15
- const If = require('if')
16
- const isError = require('is-error')
17
- const assert = require('assert-fn')
18
- const nativeAssert = require('node:assert')
19
- const vm = require('node:vm')
20
- const hasSelfEquality = require('has-self-equality')
21
- const noop = require('noop10')
22
-
23
- const $BaseError = require('es-errors')
24
- const $AssertionError = assert.AssertionError
25
- const $AggregateError = GetIntrinsic('%AggregateError%')
26
- const $RangeError = require('es-errors/range')
27
- const $ReferenceError = require('es-errors/ref')
28
- const $SyntaxError = require('es-errors/syntax')
29
- const $TypeError = require('es-errors/type')
4
+ const GetIntrinsic = require('get-intrinsic')
5
+ const zero = require('number-zero')
6
+ const one = require('the-number-one').default
7
+ const two = require('two')
8
+ const three = require('numeric-constant-three')
9
+ const four = require('always-four')
10
+ const five = require('five')
11
+ const six = require('number-six') // 6
12
+ const seven = require('se7en') // 7
13
+ const { throwop } = require('yanoop')
14
+ const isError = require('is-error')
15
+ const assert = require('assert-fn')
16
+ const nativeAssert = require('node:assert')
17
+ const vm = require('node:vm')
18
+ const hasSelfEquality = require('has-self-equality')
19
+
20
+ const $BaseError = require('es-errors')
21
+ const $AssertionError = assert.AssertionError
22
+ const $AggregateError = GetIntrinsic('%AggregateError%')
23
+ const $RangeError = require('es-errors/range')
24
+ const $ReferenceError = require('es-errors/ref')
25
+ const $SyntaxError = require('es-errors/syntax')
26
+ const $TypeError = require('es-errors/type')
30
27
  const $NativeAssertionError = nativeAssert.AssertionError
31
28
 
32
- const MathRandom = GetIntrinsic('%Math.random%')
29
+ const default_error = 'ERROR!'
33
30
 
34
31
  const ERROR = Object.freeze({
35
- BaseError:zero,
36
- AssertionError: one,
37
- AggregateError: two(),
38
- RangeError: three(),
39
- ReferenceError: four(),
40
- SyntaxError: five(),
41
- TypeError: six(),
42
- NativeAssertionError: seven()
32
+ BaseError: zero,
33
+ AssertionError: one,
34
+ AggregateError: two(),
35
+ RangeError: three(),
36
+ ReferenceError: four(),
37
+ SyntaxError: five(),
38
+ TypeError: six(),
39
+ NativeAssertionError: seven()
43
40
  })
44
41
 
45
- exports.immediateError = function immediateError(message = 'ERROR!', errorType = ERROR.Error) {
46
- var error
47
-
48
- if (hasSelfEquality(isError)) {
49
- switch (errorType) {
50
- case ERROR.BaseError: {
51
- error = new $BaseError(message)
52
- break
53
- }
54
-
55
- case ERROR.AssertionError: {
56
- error = new $AssertionError(message)
57
- break
58
- }
59
-
60
- case ERROR.AggregateError: {
61
- error = new $AggregateError(message)
62
- break
63
- }
64
-
65
- case ERROR.RangeError: {
66
- error = new $RangeError(message)
67
- break
68
- }
69
-
70
- case ERROR.ReferenceError: {
71
- error = new $ReferenceError(message)
72
- break
73
- }
74
-
75
- case ERROR.SyntaxError: {
76
- error = new $SyntaxError(message)
77
- break
78
- }
79
-
80
- case ERROR.TypeError: {
81
- error = new $TypeError(message)
82
- break
83
- }
84
-
85
- case ERROR.NativeAssertionError: {
86
- error = new $NativeAssertionError(message)
87
- break
88
- }
89
-
90
- default: {
91
- try {
92
- error = new errorType(message)
93
- } catch(err) {
94
- [err] // put the error behind bars, where it belongs
95
- error = new $BaseError(message)
96
- }
97
- }
42
+ exports.immediateError = function immediateError(message = default_error, errorType = ERROR.Error) {
43
+ var error
44
+
45
+ if (hasSelfEquality(isError)) {
46
+ switch (errorType) {
47
+ case ERROR.BaseError: {
48
+ error = new $BaseError(message)
49
+ break
50
+ }
51
+
52
+ case ERROR.AssertionError: {
53
+ error = new $AssertionError(message)
54
+ break
55
+ }
56
+
57
+ case ERROR.AggregateError: {
58
+ error = new $AggregateError(message)
59
+ break
60
+ }
61
+
62
+ case ERROR.RangeError: {
63
+ error = new $RangeError(message)
64
+ break
65
+ }
66
+
67
+ case ERROR.ReferenceError: {
68
+ error = new $ReferenceError(message)
69
+ break
70
+ }
71
+
72
+ case ERROR.SyntaxError: {
73
+ error = new $SyntaxError(message)
74
+ break
75
+ }
76
+
77
+ case ERROR.TypeError: {
78
+ error = new $TypeError(message)
79
+ break
80
+ }
81
+
82
+ case ERROR.NativeAssertionError: {
83
+ error = new $NativeAssertionError(message)
84
+ break
98
85
  }
99
- }
100
-
101
- const context = {
102
- error,
103
- throwError,
104
- throwop,
105
- rand: MathRandom(),
106
- If
107
- }
108
- vm.createContext(context)
109
-
110
- const script = new vm.Script(`
111
- If(rand < 0.5).Then(() => {
112
- throwError(error)
113
- }).Else(() => {
114
- throwop(error)
115
- })`, { filename: `ERROR!`})
116
-
117
- script.runInContext(context)
86
+
87
+ default: {
88
+ try {
89
+ error = new errorType(message)
90
+ } catch (err) {
91
+ [err] // put the error behind bars, where it belongs
92
+ error = new $BaseError(message)
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ const context = {
99
+ error,
100
+ throwop
101
+ }
102
+ vm.createContext(context)
103
+
104
+ const script = new vm.Script(`throwop(error)`, { filename: default_error })
105
+
106
+ script.runInContext(context)
118
107
  }
119
108
 
120
109
  exports.ErrorType = ERROR
package/package.json CHANGED
@@ -1,46 +1,43 @@
1
- {
2
- "name": "immediate-error",
3
- "version": "6.2.0",
4
- "description": "Throw errors, better.",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
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
- "always-four": "^1.0.0",
27
- "assert-fn": "^1.0.1",
28
- "es-errors": "^1.3.0",
29
- "five": "^0.8.0",
30
- "get-intrinsic": "^1.3.0",
31
- "has-self-equality": "^0.0.1",
32
- "if": "^2.0.0",
33
- "is-error": "^2.2.2",
34
- "none": "^1.0.0",
35
- "noop10": "^1.0.3",
36
- "number-six": "^1.0.1",
37
- "number-zero": "^1.0.3",
38
- "numeric-constant-three": "^1.0.0",
39
- "se7en": "^1.0.0",
40
- "the-number-one": "^1.0.1",
41
- "throw-error": "^1.0.0",
42
- "two": "^1.0.7",
43
- "vanilla-javascript": "^1.1.1",
44
- "yanoop": "^1.0.0"
45
- }
46
- }
1
+ {
2
+ "name": "immediate-error",
3
+ "version": "6.3.0",
4
+ "description": "Throw errors, better.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
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": "Unlicense",
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
+ "always-four": "^1.0.0",
27
+ "assert-fn": "^1.0.1",
28
+ "es-errors": "^1.3.0",
29
+ "five": "^0.8.0",
30
+ "get-intrinsic": "^1.3.0",
31
+ "has-self-equality": "^0.0.1",
32
+ "is-error": "^2.2.2",
33
+ "none": "^1.0.0",
34
+ "number-six": "^1.0.1",
35
+ "number-zero": "^1.0.3",
36
+ "numeric-constant-three": "^1.0.0",
37
+ "se7en": "^1.0.0",
38
+ "the-number-one": "^1.0.1",
39
+ "two": "^1.0.7",
40
+ "vanilla-javascript": "^1.1.1",
41
+ "yanoop": "^1.0.0"
42
+ }
43
+ }