immediate-error 8.0.0 → 9.0.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,251 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ Noitce: ai generated this changelog, so it might not be completely accurate.
5
+
6
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
+
9
+ ## [9.0.0]
10
+ ### Added
11
+ - `getError` function to get robustly cached errors
12
+
13
+ ### Changed
14
+ - Internal logic to get errors to be more robust
15
+ - Removed dependency problem
16
+
17
+ ## [8.1.0]
18
+ ### THIS VERSION IS DEPRECATED: Dependency problem
19
+
20
+ ### Added
21
+ - This changelog
22
+
23
+ ## [8.0.0]
24
+ ### THIS VERSION IS DEPRECATED: Dependency problem
25
+
26
+ ### Added
27
+ - "use struct" directive for struct mode
28
+ - Dependencies: `is-`, `n0p3-es2015-cjs`, `deep-freeze-node3`, `@uppercase-letters/e`, `@uppercase-letters/o`, `@uppercase-letters/r`, `@rightpad/concat`, `as-array`
29
+ - `CreateError` helper function
30
+ - Improved error construction using functional programming utilities
31
+
32
+ ### Changed
33
+ - Default error message now constructed using `concat` with uppercase letters
34
+ - Updated dependencies versions
35
+ - Simplified test file
36
+
37
+ ### Removed
38
+ - `es-object-atoms`, `true-value`, `yanoop` dependencies
39
+
40
+ ## [7.2.0]
41
+
42
+ ### Changed
43
+ - Minor adjustment in vm.Script args formatting
44
+
45
+ ### Updated
46
+ - `@positive-numbers/zero` to `^4.0.0`
47
+
48
+ ## [7.1.0]
49
+
50
+ ### Changed
51
+ - Replaced `get-intrinsic` with `es-intrinsic-cache`
52
+
53
+ ## [7.0.0]
54
+
55
+ ### Added
56
+ - Support for `EvalError` and `URIError`
57
+ - `es-error-intrinsics` for better error handling
58
+ - `bail` for error throwing
59
+ - Stack trace capture using `Error.captureStackTrace`
60
+
61
+ ### Changed
62
+ - Error types: Removed `AggregateError`, `AssertionError`, `NativeAssertionError`; Added `EvalError`, `URIError`
63
+ - Updated API to use `bail` in vm context
64
+ - Repository URL changed to `in-fp`
65
+ - Author changed to "10x'ly Made"
66
+
67
+ ### Removed
68
+ - `assert-fn`, `es-object-atoms`, `number-zero` dependencies
69
+ - Some keywords from package.json
70
+
71
+ ### Updated
72
+ - Tests to reflect new error types
73
+
74
+ ## [6.4.0]
75
+
76
+ ### Added
77
+ - Functional programming refactor using `switch-in-fp`, `construct-new`, `attempt-statement`
78
+ - `@positive-numbers/*` dependencies for numbers
79
+ - Jest tests
80
+ - TypeScript definitions (`index.d.ts`)
81
+
82
+ ### Changed
83
+ - Major code refactor to FP style
84
+ - Dependencies updated to scoped packages
85
+ - Description changed to "throw errors in fp"
86
+ - Test script added
87
+ - Keywords updated with FP and other terms
88
+
89
+ ### Removed
90
+ - Old dependencies replaced with new ones
91
+
92
+ ## [6.3.0]
93
+
94
+ ### Changed
95
+ - Code formatting and indentation
96
+ - License changed to "Unlicense"
97
+ - Removed some dependencies: `if`, `noop10`, `se7en`, `the-number-one`, `two`, `vanilla-javascript`
98
+
99
+ ### Removed
100
+ - "why?" section from README
101
+
102
+ ## [6.2.0]
103
+
104
+ ### Changed
105
+ - Simplified code structure
106
+ - Updated vm script logic
107
+ - Removed dependencies: `bail`, `esm-wallaby`, `picocolors`
108
+
109
+ ### Added
110
+ - `has-self-equality`, `noop10` dependencies
111
+
112
+ ## [6.1.0]
113
+ ### 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.
114
+
115
+ ### Added
116
+ - `AggregateError` support
117
+ - Updated README with `AggregateError` example
118
+ - Updated TypeScript definitions
119
+
120
+ ## [6.0.0]
121
+ ### 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.
122
+
123
+ ### Added
124
+ - `AggregateError` to error types
125
+ - `get-intrinsic` for intrinsics
126
+
127
+ ### Changed
128
+ - Error types mapping
129
+ - Removed some dependencies: `jquery*`, `successor`, `vanilla-javascript`
130
+
131
+ ### Updated
132
+ - `es-errors` to `^1.3.0`
133
+
134
+ ## [5.1.1]
135
+ ### 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.
136
+
137
+ ### Changed
138
+ - Replaced `cli-color` with `picocolors`
139
+
140
+ ## [5.1.0]
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.
142
+
143
+ ### Changed
144
+ - Description updated to "Throw errors, better."
145
+
146
+ ## [5.0.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.
148
+
149
+ ### Added
150
+ - `esm-wallaby` for ESM requiring
151
+ - `bail` for error throwing
152
+
153
+ ### Changed
154
+ - Updated vm script to use `bail` with random logic
155
+
156
+ ## [4.0.0]
157
+
158
+ ### Added
159
+ - ES modules export style
160
+ - Support for custom error classes
161
+ - `es-errors` for proper error constructors
162
+ - TypeScript definitions
163
+ - More error types: `BaseError`, `AssertionError`, `AggregateError`, `NativeAssertionError`
164
+
165
+ ### Changed
166
+ - Major API change: `immediateError(message, errorType)`
167
+ - Removed `fox` dependency
168
+ - Updated README with new usage
169
+ - License to "Unlicense"
170
+
171
+ ### Removed
172
+ - Old dependencies
173
+
174
+ ## [3.1.3]
175
+
176
+ ### Added
177
+ - `FuckingError` class
178
+ - More number dependencies for error type values
179
+ - Updated README with `FuckingError` example
180
+
181
+ ## [3.1.2]
182
+
183
+ ### Changed
184
+ - Removed console.log from vm script
185
+
186
+ ## [3.1.1]
187
+
188
+ ### Removed
189
+ - `integer-value-positive-zero` dependency
190
+
191
+ ## [3.1.0]
192
+
193
+ ### Added
194
+ - Many new dependencies for numbers, jQuery, etc.
195
+ - Complex vm context with random error throwing
196
+ - Updated README
197
+
198
+ ### Changed
199
+ - Default message to aggressive one
200
+ - Error creation using packages for numbers
201
+
202
+ ## [3.0.0]
203
+
204
+ ### Added
205
+ - Repository, keywords, author info
206
+ - Many dependencies: `vanilla-javascript`, `vapor-js-npm`, etc.
207
+ - vm context for error throwing
208
+
209
+ ### Changed
210
+ - Description to "Immediate-error"
211
+ - Major code changes with more complexity
212
+
213
+ ## [2.1.0]
214
+
215
+ ### Added
216
+ - ERROR object with multiple error types
217
+ - eval-based error throwing
218
+
219
+ ### Changed
220
+ - License to "UNLICENSED"
221
+ - Removed dependencies
222
+
223
+ ### Updated
224
+ - README with more examples
225
+
226
+ ## [2.0.0]
227
+
228
+ ### Changed
229
+ - Simplified to throw `new Error(message)` with default message (logic that makes sense)
230
+ - Updated README example
231
+
232
+ ## [1.0.1]
233
+
234
+ ### Changed
235
+ - Author to "tj-commits/87f"
236
+
237
+ ## [1.0.0]
238
+
239
+ ### Added
240
+ - README.md with usage
241
+ - Self-dependency (circular?)
242
+
243
+ ### Changed
244
+ - Version to 1.0.0
245
+
246
+ ## [0.0.1]
247
+
248
+ ### Added
249
+ - Initial release
250
+ - Basic index.js that requires 'fox', which is a pure ESM module, so it would throw an error since the package is CommonJS
251
+ - package.json with basic info
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,8 +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
37
40
 
38
41
  ```
42
+
43
+ Getting Cached Errors:
44
+ ```javascript
45
+ const { getError, ErrorType } = require("immediate-error")
46
+
47
+ const TypeErrorConstructor = getError(ErrorType.TypeError)
48
+
49
+ console.log(TypeErrorConstructor === TypeError) // true
50
+ ```
51
+
52
+ ### Changelog
53
+ See Changelog in [CHANGELOG.md](https://github.com/enterprise-npm-ai/immediate-error/blob/main/CHANGELOG.md)
54
+
39
55
  ## License
40
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/output.txt ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "immediate-error",
3
- "version": "8.0.0",
3
+ "version": "9.0.0",
4
4
  "description": "throw errors in fp",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/in-fp/immediate-error.git"
11
+ "url": "git+https://github.com/enterprise-npm-ai/immediate-error.git"
12
12
  },
13
13
  "keywords": [
14
14
  "error",
@@ -36,7 +36,7 @@
36
36
  "jest",
37
37
  "67",
38
38
  "fp",
39
- "in-fp",
39
+ "enterprise-npm-ai",
40
40
  "sigmaskibidi",
41
41
  "tj-commits",
42
42
  "skibidi-toilet-hacker",
@@ -45,13 +45,14 @@
45
45
  "author": "10x'ly Made",
46
46
  "license": "Unlicense",
47
47
  "bugs": {
48
- "url": "https://github.com/in-fp/immediate-error/issues"
48
+ "url": "https://github.com/enterprise-npm-ai/immediate-error/issues"
49
49
  },
50
- "homepage": "https://github.com/in-fp/immediate-error#readme",
50
+ "homepage": "https://github.com/enterprise-npm-ai/immediate-error#readme",
51
51
  "dependencies": {
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-in-fp": "^3.0.0",
74
+ "simple-lru-cache": "^0.0.2",
74
75
  "true-value": "^2.0.5"
75
76
  },
76
77
  "devDependencies": {