immediate-error 6.1.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 +77 -89
  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,7 +1,6 @@
1
1
  require('vanilla-javascript')
2
2
  require('none')()
3
3
 
4
- const esmRequire = require('esm-wallaby')(module)
5
4
  const GetIntrinsic = require('get-intrinsic')
6
5
  const zero = require('number-zero')
7
6
  const one = require('the-number-one').default
@@ -9,17 +8,14 @@ const two = require('two')
9
8
  const three = require('numeric-constant-three')
10
9
  const four = require('always-four')
11
10
  const five = require('five')
12
- const six = require('number-six')
13
- const seven = require('se7en')
11
+ const six = require('number-six') // 6
12
+ const seven = require('se7en') // 7
14
13
  const { throwop } = require('yanoop')
15
- const throwError = require('throw-error')
16
- const bail = esmRequire('bail').bail
17
- const If = require('if')
18
- const picocolors = require('picocolors')
19
14
  const isError = require('is-error')
20
15
  const assert = require('assert-fn')
21
16
  const nativeAssert = require('node:assert')
22
17
  const vm = require('node:vm')
18
+ const hasSelfEquality = require('has-self-equality')
23
19
 
24
20
  const $BaseError = require('es-errors')
25
21
  const $AssertionError = assert.AssertionError
@@ -30,92 +26,84 @@ const $SyntaxError = require('es-errors/syntax')
30
26
  const $TypeError = require('es-errors/type')
31
27
  const $NativeAssertionError = nativeAssert.AssertionError
32
28
 
29
+ const default_error = 'ERROR!'
30
+
33
31
  const ERROR = Object.freeze({
34
- BaseError:zero,
35
- AssertionError: one,
36
- AggregateError: two(),
37
- RangeError: three(),
38
- ReferenceError: four(),
39
- SyntaxError: five(),
40
- TypeError: six(),
41
- 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()
42
40
  })
43
41
 
44
- exports.immediateError = function immediateError(message = 'ERROR!', errorType = ERROR.Error) {
45
- var error
46
-
47
- if (isError == isError) {
48
- switch (errorType) {
49
- case ERROR.BaseError: {
50
- error = new $BaseError(message)
51
- break
52
- }
53
-
54
- case ERROR.AssertionError: {
55
- error = new $AssertionError(message)
56
- break
57
- }
58
-
59
- case ERROR.RangeError: {
60
- error = new $RangeError(message)
61
- break
62
- }
63
-
64
- case ERROR.ReferenceError: {
65
- error = new $ReferenceError(message)
66
- break
67
- }
68
-
69
- case ERROR.SyntaxError: {
70
- error = new $SyntaxError(message)
71
- break
72
- }
73
-
74
- case ERROR.TypeError: {
75
- error = new $TypeError(message)
76
- break
77
- }
78
-
79
- case ERROR.NativeAssertionError: {
80
- error = new $NativeAssertionError(message)
81
- break
82
- }
83
-
84
- default: {
85
- try {
86
- error = new errorType(message)
87
- } catch(err) {
88
- [err] // put the error behind bars, where it belongs
89
- error = new $BaseError(message)
90
- }
91
- }
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
92
60
  }
93
- } else {
94
- void 0
95
- }
96
-
97
- const context = {
98
- error,
99
- throwError,
100
- throwop,
101
- rand: Math.random(),
102
- If,
103
- console,
104
- picocolors,
105
- bail
106
- }
107
- vm.createContext(context)
108
-
109
- const script = new vm.Script(`
110
- If(rand < 0.3).Then(() => {
111
- throwError(error)
112
- }).Else().If(rand > 0.3 && rand < 0.7).Then(() => {
113
- throwop(error)
114
- }).Else(() => {
115
- bail(error)
116
- })`, { filename: `ERROR!`})
117
-
118
- script.runInContext(context)
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
85
+ }
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)
119
107
  }
120
108
 
121
109
  exports.ErrorType = ERROR
package/package.json CHANGED
@@ -1,46 +1,43 @@
1
- {
2
- "name": "immediate-error",
3
- "version": "6.1.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
- "bail": "^2.0.2",
29
- "es-errors": "^1.3.0",
30
- "esm-wallaby": "^3.2.30",
31
- "five": "^0.8.0",
32
- "get-intrinsic": "^1.3.0",
33
- "if": "^2.0.0",
34
- "is-error": "^2.2.2",
35
- "none": "^1.0.0",
36
- "number-six": "^1.0.1",
37
- "number-zero": "^1.0.3",
38
- "numeric-constant-three": "^1.0.0",
39
- "picocolors": "^1.1.1",
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
+ }