whoops 4.1.7 → 5.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "whoops",
3
3
  "description": "It makes simple throw qualified errors.",
4
4
  "homepage": "https://github.com/Kikobeats/whoops",
5
- "version": "4.1.7",
5
+ "version": "5.0.0",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "josefrancisco.verdu@gmail.com",
@@ -33,22 +33,16 @@
33
33
  "simple",
34
34
  "throw"
35
35
  ],
36
- "dependencies": {
37
- "clean-stack": "~3.0.0",
38
- "mimic-fn": "~3.1.0"
39
- },
40
36
  "devDependencies": {
41
37
  "@commitlint/cli": "latest",
42
38
  "@commitlint/config-conventional": "latest",
43
39
  "@ksmithut/prettier-standard": "latest",
44
40
  "c8": "latest",
45
41
  "ci-publish": "latest",
46
- "conventional-github-releaser": "latest",
47
42
  "finepack": "latest",
48
43
  "git-authors-cli": "latest",
49
- "mocha": "latest",
44
+ "github-generate-release": "latest",
50
45
  "nano-staged": "latest",
51
- "npm-check-updates": "latest",
52
46
  "should": "latest",
53
47
  "simple-git-hooks": "latest",
54
48
  "standard": "latest",
@@ -67,20 +61,22 @@
67
61
  "coveralls": "nyc report --reporter=text-lcov | coveralls",
68
62
  "lint": "standard",
69
63
  "postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
70
- "prerelease": "npm run update:check",
71
64
  "pretest": "npm run lint",
72
65
  "release": "standard-version -a",
73
- "release:github": "conventional-github-releaser -p angular",
66
+ "release:github": "github-generate-release",
74
67
  "release:tags": "git push --follow-tags origin HEAD:master",
75
- "test": "c8 mocha",
76
- "update": "ncu -u",
77
- "update:check": "ncu -- --error-level 2"
68
+ "test": "c8 node --test"
78
69
  },
79
70
  "license": "MIT",
80
71
  "commitlint": {
81
72
  "extends": [
82
73
  "@commitlint/config-conventional"
83
- ]
74
+ ],
75
+ "rules": {
76
+ "body-max-line-length": [
77
+ 0
78
+ ]
79
+ }
84
80
  },
85
81
  "nano-staged": {
86
82
  "*.js": [
package/src/index.js CHANGED
@@ -1,11 +1,37 @@
1
1
  'use strict'
2
2
 
3
- const createExtendError = require('./create-extend-error')
4
- const createError = require('./create-error')
3
+ function createErrorClass (ErrorClass) {
4
+ return (name, defaults) => {
5
+ class CustomError extends ErrorClass {
6
+ constructor (raw = {}) {
7
+ super(raw)
5
8
 
6
- const createErrorClass = ErrorClass => (className, props) => {
7
- const errorClass = createError(className || ErrorClass.name)
8
- return createExtendError(errorClass, props)
9
+ const { message, ...props } = typeof raw === 'string' ? { message: raw } : raw
10
+ const mergedProps = Object.assign({}, defaults, props)
11
+ Object.keys(mergedProps).forEach(key => (this[key] = mergedProps[key]))
12
+
13
+ if (message) this.description = typeof message === 'function' ? message(this) : message
14
+ this.message = this.code ? `${this.code}, ${this.description}` : this.description
15
+ this.name = name || ErrorClass.name
16
+ }
17
+ }
18
+
19
+ // Function to create an instance, allowing use without `new`
20
+ function CustomErrorFactory (props) {
21
+ return new CustomError(props)
22
+ }
23
+
24
+ // Ensure the function's name matches the class name for consistency
25
+ Object.defineProperty(CustomErrorFactory, 'name', {
26
+ value: name || ErrorClass.name,
27
+ writable: false
28
+ })
29
+
30
+ // Make `instanceof` checks work with both the class and factory
31
+ CustomErrorFactory.prototype = CustomError.prototype
32
+
33
+ return CustomErrorFactory
34
+ }
9
35
  }
10
36
 
11
37
  module.exports = createErrorClass(Error)
@@ -1,15 +0,0 @@
1
- 'use strict'
2
-
3
- const { isFunction, composeErrorMessage } = require('./helpers')
4
-
5
- function interfaceObject (error, ...props) {
6
- Object.assign(error, ...props)
7
-
8
- error.description = isFunction(error.message) ? error.message(error) : error.message
9
-
10
- error.message = error.code
11
- ? composeErrorMessage(error.code, error.description)
12
- : error.description
13
- }
14
-
15
- module.exports = interfaceObject
@@ -1,34 +0,0 @@
1
- 'use strict'
2
-
3
- const { inherits } = require('./helpers')
4
- const mimicFn = require('mimic-fn')
5
-
6
- const REGEX_CLASS_NAME = /[^0-9a-zA-Z_$]/
7
-
8
- function createError (className) {
9
- if (typeof className !== 'string') {
10
- throw new TypeError('Expected className to be a string')
11
- }
12
-
13
- if (REGEX_CLASS_NAME.test(className)) {
14
- throw new Error('className contains invalid characters')
15
- }
16
-
17
- function ErrorClass () {
18
- Object.defineProperty(this, 'name', {
19
- configurable: true,
20
- value: className,
21
- writable: true
22
- })
23
-
24
- if ('captureStackTrace' in Error) {
25
- Error.captureStackTrace(this, this.constructor)
26
- }
27
- }
28
-
29
- inherits(ErrorClass, Error)
30
- mimicFn(ErrorClass, Error)
31
- return ErrorClass
32
- }
33
-
34
- module.exports = createError
@@ -1,25 +0,0 @@
1
- 'use strict'
2
-
3
- const cleanStack = require('clean-stack')
4
- const mimicFn = require('mimic-fn')
5
-
6
- const addErrorProps = require('./add-error-props')
7
- const { isString } = require('./helpers')
8
-
9
- function createExtendError (ErrorClass, classProps) {
10
- function ExtendError (props) {
11
- const error = new ErrorClass()
12
- const errorProps = isString(props) ? { message: props } : props
13
- addErrorProps(error, classProps, errorProps)
14
-
15
- error.stack = typeof error.stack === 'string' ? cleanStack(error.stack) : undefined
16
- return error
17
- }
18
-
19
- ExtendError.prototype = ErrorClass.prototype
20
- mimicFn(ExtendError, ErrorClass)
21
-
22
- return ExtendError
23
- }
24
-
25
- module.exports = createExtendError
package/src/helpers.js DELETED
@@ -1,18 +0,0 @@
1
- 'use strict'
2
-
3
- module.exports = {
4
- isFunction: obj => typeof obj === 'function',
5
- isString: obj => typeof obj === 'string',
6
- composeErrorMessage: (code, description) => `${code}, ${description}`,
7
- inherits: (ctor, superCtor) => {
8
- ctor.super_ = superCtor
9
- ctor.prototype = Object.create(superCtor.prototype, {
10
- constructor: {
11
- value: ctor,
12
- enumerable: false,
13
- writable: true,
14
- configurable: true
15
- }
16
- })
17
- }
18
- }