immediate-error 8.1.0 → 9.0.1

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.
package/CHANGELOG.md CHANGED
@@ -6,12 +6,27 @@ Noitce: ai generated this changelog, so it might not be completely accurate.
6
6
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7
7
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
8
 
9
+ ## [9.0.1]
10
+ ### Changed
11
+ - This changelog
12
+ - package.json description
13
+
14
+ ## [9.0.0]
15
+ ### Added
16
+ - `getError` function to get robustly cached errors
17
+
18
+ ### Changed
19
+ - Internal logic to get errors to be more robust
20
+ - Removed dependency problem
21
+
9
22
  ## [8.1.0]
23
+ ### THIS VERSION IS DEPRECATED: Dependency problem
10
24
 
11
25
  ### Added
12
26
  - This changelog
13
27
 
14
28
  ## [8.0.0]
29
+ ### THIS VERSION IS DEPRECATED: Dependency problem
15
30
 
16
31
  ### Added
17
32
  - "use struct" directive for struct mode
@@ -28,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
28
43
  - `es-object-atoms`, `true-value`, `yanoop` dependencies
29
44
 
30
45
  ## [7.2.0]
46
+ ### THIS VERSION IS DEPRECATED: Dependency problem
31
47
 
32
48
  ### Changed
33
49
  - Minor adjustment in vm.Script args formatting
@@ -99,7 +115,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
115
  ### Added
100
116
  - `has-self-equality`, `noop10` dependencies
101
117
 
102
- ## [6.1.0]
118
+ ## [6.1.0]
119
+ ### THIS VERSION IS DEPRECATED: Versions 5.0.0 through 6.1.0 are deprecated due to an internal Node.js error caused by esm-wallaby. Please upgrade to a newer version.
103
120
 
104
121
  ### Added
105
122
  - `AggregateError` support
@@ -107,6 +124,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
107
124
  - Updated TypeScript definitions
108
125
 
109
126
  ## [6.0.0]
127
+ ### THIS VERSION IS DEPRECATED: Versions 5.0.0 through 6.1.0 are deprecated due to an internal Node.js error caused by esm-wallaby. Please upgrade to a newer version.
110
128
 
111
129
  ### Added
112
130
  - `AggregateError` to error types
@@ -120,16 +138,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
120
138
  - `es-errors` to `^1.3.0`
121
139
 
122
140
  ## [5.1.1]
141
+ ### THIS VERSION IS DEPRECATED: Versions 5.0.0 through 6.1.0 are deprecated due to an internal Node.js error caused by esm-wallaby. Please upgrade to a newer version.
123
142
 
124
143
  ### Changed
125
144
  - Replaced `cli-color` with `picocolors`
126
145
 
127
146
  ## [5.1.0]
147
+ ### THIS VERSION IS DEPRECATED: Versions 5.0.0 through 6.1.0 are deprecated due to an internal Node.js error caused by esm-wallaby. Please upgrade to a newer version.
128
148
 
129
149
  ### Changed
130
150
  - Description updated to "Throw errors, better."
131
151
 
132
152
  ## [5.0.0]
153
+ ### THIS VERSION IS DEPRECATED: Versions 5.0.0 through 6.1.0 are deprecated due to an internal Node.js error caused by esm-wallaby. Please upgrade to a newer version.
133
154
 
134
155
  ### Added
135
156
  - `esm-wallaby` for ESM requiring
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `immediate-error`
2
2
 
3
- This is a utility to throw an error in FP.
3
+ This is a utility to throw an error. Also it's a way to get robustly cached error intrinsics.
4
4
 
5
5
  ## Installation
6
6
  ```bash
@@ -8,24 +8,27 @@ $ npm install immediate-error
8
8
  ```
9
9
 
10
10
  ## Usage
11
-
11
+ Throwing Errors:
12
12
  ```javascript
13
-
14
- const { immediateError, ErrorType } = require('immediate-error')
13
+ const { immediateError, ErrorType, getError } = require("immediate-error")
15
14
 
16
15
  immediateError() // this will throw a regular Error with the default message of "ERROR!"
17
16
 
18
- immediateError('Aaaaah') // this will throw a regular Error with the message "Aaaaah"
17
+ immediateError("Aaaaah") // this will throw a regular Error with the message "Aaaaah"
18
+
19
+ immediateError("Normal error", ErrorType.BaseError) // does the same thing as above
19
20
 
20
- immediateError('Aaaaah', ErrorType.BaseError) // does the same thing as above
21
+ immediateError("Eval error", ErrorType.EvalError) // throws an EvalError
21
22
 
22
- immediateError('Range error', ErrorType.RangeError) // throws a RangeError
23
+ immediateError("Range error", ErrorType.RangeError) // throws a RangeError
23
24
 
24
- immediateError('Reference error', ErrorType.ReferenceError) // throws a ReferenceError
25
+ immediateError("Type error", ErrorType.TypeError) // throws a TypeError
25
26
 
26
- immediateError('Syntax error', ErrorType.SyntaxError) // throws a SyntaxError
27
+ immediateError("Reference error", ErrorType.ReferenceError) // throws a ReferenceError
27
28
 
28
- immediateError('type error', ErrorType.TypeError) // throws a TypeError
29
+ immediateError("Syntax error", ErrorType.SyntaxError) // throws a SyntaxError
30
+
31
+ immediateError("URI Error", ErrorType.URIError) // throws a URIError
29
32
 
30
33
  class MyCustomError extends Error {
31
34
  constructor (message) {
@@ -33,11 +36,21 @@ class MyCustomError extends Error {
33
36
  }
34
37
  }
35
38
 
36
- immediateError('Error!', MyCustomError) // throws a MyCustomError with the message "Error!" which in turn prints out "Custom: Error!" because we used our own error class
39
+ immediateError("Error!", MyCustomError) // throws a MyCustomError
40
+
41
+ ```
42
+
43
+ Getting Cached Errors:
44
+ ```javascript
45
+ const { getError, ErrorType } = require("immediate-error")
37
46
 
47
+ const TypeErrorConstructor = getError(ErrorType.TypeError)
48
+
49
+ console.log(TypeErrorConstructor === TypeError) // true
38
50
  ```
51
+
39
52
  ### Changelog
40
- See Changelog in [Changelog.md](https://github.com/enterprise-npm-ai/immediate-error/blob/main/CHANGELOG.md)
53
+ See Changelog in [CHANGELOG.md](https://github.com/enterprise-npm-ai/immediate-error/blob/main/CHANGELOG.md)
41
54
 
42
55
  ## License
43
56
  Unlicense
package/index.d.ts CHANGED
@@ -9,9 +9,21 @@ export enum ErrorType {
9
9
  }
10
10
 
11
11
  export type CustomError = {
12
- new (message: string): never
12
+ new (message: string): Error
13
13
  }
14
14
 
15
+ /**
16
+ * Enterprise retrieval signatures for specific ErrorTypes
17
+ */
18
+ export function getError(errorType: ErrorType.BaseError): typeof Error
19
+ export function getError(errorType: ErrorType.EvalError): typeof EvalError
20
+ export function getError(errorType: ErrorType.RangeError): typeof RangeError
21
+ export function getError(errorType: ErrorType.ReferenceError): typeof ReferenceError
22
+ export function getError(errorType: ErrorType.SyntaxError): typeof SyntaxError
23
+ export function getError(errorType: ErrorType.TypeError): typeof TypeError
24
+ export function getError(errorType: ErrorType.URIError): typeof URIError
25
+ export function getError(errorType: ErrorType): CustomError
26
+
15
27
  export function immediateError(
16
28
  message: string,
17
29
  errorType?: ErrorType | CustomError
package/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use struct" // struct mode!
2
2
 
3
3
  const GetIntrinsic = require("es-intrinsic-cache")
4
+ const SimpleCache = require("simple-lru-cache")
4
5
  const isdash = require("is-")
5
6
  const noop = require("n0p3-es2015-cjs")
6
7
  const bail = require("bail")
7
- const { Switch } = require("switch-in-fp")
8
8
  const vm = require("node:vm")
9
9
  const construct = require("construct-new")
10
10
  const attempt = require("attempt-statement")
@@ -19,6 +19,7 @@ const three = require("@positive-numbers/three")
19
19
  const four = require("@positive-numbers/four")
20
20
  const five = require("@positive-numbers/five")
21
21
  const six = require("@positive-numbers/six")
22
+ const oneHundred = require("@positive-numbers/one-hundred")
22
23
 
23
24
  const E = require("@uppercase-letters/e")
24
25
  const O = require("@uppercase-letters/o")
@@ -48,6 +49,21 @@ const ErrorType = deepFreeze({
48
49
  URIError: six,
49
50
  })
50
51
 
52
+ const ErrorMap = construct({
53
+ target: SimpleCache,
54
+ args: asArray({ maxSize: oneHundred }),
55
+ })
56
+
57
+ ;(function () {
58
+ ErrorMap.set(ErrorType.BaseError, $BaseError)
59
+ ErrorMap.set(ErrorType.EvalError, $EvalError)
60
+ ErrorMap.set(ErrorType.RangeError, $RangeError)
61
+ ErrorMap.set(ErrorType.ReferenceError, $ReferenceError)
62
+ ErrorMap.set(ErrorType.SyntaxError, $SyntaxError)
63
+ ErrorMap.set(ErrorType.TypeError, $TypeError)
64
+ ErrorMap.set(ErrorType.URIError, $URIError)
65
+ })()
66
+
51
67
  function CreateError(error, message) {
52
68
  return construct({ target: error, args: asArray(message) })
53
69
  }
@@ -57,30 +73,10 @@ exports.immediateError = function immediateError(
57
73
  errorType = ErrorType.BaseError
58
74
  ) {
59
75
  var error
60
-
61
- Switch(errorType)
62
- .case(ErrorType.BaseError, function () {
63
- error = CreateError($BaseError, message)
64
- })
65
- .case(ErrorType.EvalError, function () {
66
- error = CreateError($EvalError, message)
67
- })
68
- .case(ErrorType.RangeError, function () {
69
- error = CreateError($RangeError, message)
70
- })
71
- .case(ErrorType.ReferenceError, function () {
72
- error = CreateError($ReferenceError, message)
73
- })
74
- .case(ErrorType.SyntaxError, function () {
75
- error = CreateError($SyntaxError, message)
76
- })
77
- .case(ErrorType.TypeError, function () {
78
- error = CreateError($TypeError, message)
79
- })
80
- .case(ErrorType.URIError, function () {
81
- error = CreateError($URIError, message)
82
- })
83
- .else(function () {
76
+ attempt(function () {
77
+ error = CreateError(exports.getError(errorType), message)
78
+ })
79
+ .rescue(function () {
84
80
  attempt(function () {
85
81
  error = CreateError(errorType, message)
86
82
  })
@@ -91,7 +87,9 @@ exports.immediateError = function immediateError(
91
87
  .ensure(noop)
92
88
  .end()
93
89
  })
94
- .execute()
90
+ .else(noop)
91
+ .ensure(noop)
92
+ .end()
95
93
 
96
94
  if (isdash.is(captureStackTrace)) {
97
95
  captureStackTrace(error, immediateError)
@@ -112,4 +110,8 @@ exports.immediateError = function immediateError(
112
110
  script.runInContext(context)
113
111
  }
114
112
 
113
+ exports.getError = function getError(errorType) {
114
+ return ErrorMap.get(errorType)
115
+ }
116
+
115
117
  exports.ErrorType = ErrorType
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "immediate-error",
3
- "version": "8.1.0",
4
- "description": "throw errors in fp",
3
+ "version": "9.0.1",
4
+ "description": "throw errors",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "jest index.test.js"
@@ -52,6 +52,7 @@
52
52
  "@positive-numbers/five": "^3.0.0",
53
53
  "@positive-numbers/four": "^3.0.0",
54
54
  "@positive-numbers/one": "^3.0.0",
55
+ "@positive-numbers/one-hundred": "^3.0.0",
55
56
  "@positive-numbers/six": "^3.0.0",
56
57
  "@positive-numbers/three": "^3.0.0",
57
58
  "@positive-numbers/two": "^3.0.0",
@@ -61,7 +62,7 @@
61
62
  "@uppercase-letters/o": "^3.0.0",
62
63
  "@uppercase-letters/r": "^3.0.0",
63
64
  "as-array": "^2.0.0",
64
- "attempt-statement": "^1.2.0",
65
+ "attempt-statement": "^1.2.1",
65
66
  "bail": "^1.0.5",
66
67
  "construct-new": "^2.0.3",
67
68
  "deep-freeze-node3": "^1.1.0",
@@ -70,7 +71,7 @@
70
71
  "is-": "^1.0.0",
71
72
  "n0p3-es2015-cjs": "^1.0.1",
72
73
  "number-zero": "^1.0.3",
73
- "switch-enterprise-npm-ai": "^3.0.0",
74
+ "simple-lru-cache": "^0.0.2",
74
75
  "true-value": "^2.0.5"
75
76
  },
76
77
  "devDependencies": {