whoops 4.0.1 → 4.1.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/README.md CHANGED
@@ -1,12 +1,8 @@
1
1
  # whoops
2
2
 
3
3
  ![Last version](https://img.shields.io/github/tag/Kikobeats/whoops.svg?style=flat-square)
4
- [![Build Status](http://img.shields.io/travis/Kikobeats/whoops/master.svg?style=flat-square)](https://travis-ci.org/Kikobeats/whoops)
5
4
  [![Coverage Status](https://img.shields.io/coveralls/Kikobeats/whoops.svg?style=flat-square)](https://coveralls.io/github/Kikobeats/whoops)
6
- [![Dependency status](http://img.shields.io/david/Kikobeats/whoops.svg?style=flat-square)](https://david-dm.org/Kikobeats/whoops)
7
- [![Dev Dependencies Status](http://img.shields.io/david/dev/Kikobeats/whoops.svg?style=flat-square)](https://david-dm.org/Kikobeats/whoops#info=devDependencies)
8
5
  [![NPM Status](http://img.shields.io/npm/dm/whoops.svg?style=flat-square)](https://www.npmjs.org/package/whoops)
9
- [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square)](https://paypal.me/kikobeats)
10
6
 
11
7
  > It makes simple throw qualified errors. Inspired in [errno](https://github.com/rvagg/node-errno), [create-error-class](https://github.com/floatdrop/create-error-class) and [fault](https://github.com/wooorm/fault).
12
8
 
@@ -14,7 +10,7 @@
14
10
 
15
11
  - An easy way to create qualified errors.
16
12
  - Using the standard `Error` interface in browser and NodeJS.
17
- - Attach extra information, depending of your case of use.
13
+ - Attach extra information, being flexible with whatever user case.
18
14
 
19
15
  This library is a compromise to provide a clean API for use `Error` native class.
20
16
 
@@ -48,30 +44,36 @@ Call `whoops` to get a constructor function. Every time you call the constructor
48
44
  ```js
49
45
  const whoops = require('whoops')
50
46
  const myError = whoops()
51
-
52
47
  throw myError()
53
48
  ```
54
49
 
55
- If you provided a `className` you get a qualified constructor function that extends from `Error`:
50
+ Create domain specific errors providing a `className` as first argument:
56
51
 
57
52
  ```js
58
53
  const whoops = require('whoops')
59
54
  const userError = whoops('userError')
60
-
61
55
  throw userError()
62
56
  ```
63
57
 
64
- Providing `props` as second parameter you can attach extra information that always will be associated with the `error`:
58
+ The qualified error will be extends from `Error`:
65
59
 
66
60
  ```js
67
61
  const whoops = require('whoops')
68
- const userError = whoops('userError', {code: 'ENOVALID'})
62
+ const userError = whoops('userError')
63
+ const error = userError()
64
+ console.log(error instanceof Error); // => true
65
+ ```
66
+
67
+ Attach extra information passing a `props` as second argument:
69
68
 
69
+ ```js
70
+ const whoops = require('whoops')
71
+ const userError = whoops('userError', {code: 'ENOVALID'})
70
72
  const err = userError()
71
73
  console.log(`My error code is ${err.code}`) // => My error code is ENOVALID
72
74
  ```
73
75
 
74
- Also, you can associate dynamic `props` at the moment of the `error`:
76
+ You can associate dynamic `props` as well:
75
77
 
76
78
  ```js
77
79
  const whoops = require('whoops')
@@ -126,6 +128,12 @@ switch (err.name) {
126
128
  };
127
129
  ```
128
130
 
131
+ ## Related
132
+
133
+ - [create-error-class](https://github.com/floatdrop/create-error-class) – Create error class.
134
+ - [fault](https://github.com/wooorm/fault) – Functional errors with formatted output.
135
+
136
+
129
137
  ## License
130
138
 
131
139
  MIT © [Kiko Beats](http://www.kikobeats.com)
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const {isFunction, composeErrorMessage} = require('./helpers')
3
+ const { isFunction, composeErrorMessage } = require('./helpers')
4
4
 
5
5
  function interfaceObject (error, ...props) {
6
6
  Object.assign(error, ...props)
@@ -8,8 +8,8 @@ function interfaceObject (error, ...props) {
8
8
  error.description = isFunction(error.message) ? error.message(error) : error.message
9
9
 
10
10
  error.message = error.code
11
- ? composeErrorMessage(error.code, error.description)
12
- : error.description
11
+ ? composeErrorMessage(error.code, error.description)
12
+ : error.description
13
13
  }
14
14
 
15
15
  module.exports = interfaceObject
@@ -1,13 +1,18 @@
1
1
  'use strict'
2
2
 
3
- const {inherits} = require('./helpers')
3
+ const { inherits } = require('./helpers')
4
4
  const mimicFn = require('mimic-fn')
5
5
 
6
6
  const REGEX_CLASS_NAME = /[^0-9a-zA-Z_$]/
7
7
 
8
8
  function createError (className) {
9
- if (typeof className !== 'string') throw new TypeError('Expected className to be a string')
10
- if (REGEX_CLASS_NAME.test(className)) throw new Error('className contains invalid characters')
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
+ }
11
16
 
12
17
  function ErrorClass () {
13
18
  Object.defineProperty(this, 'name', {
@@ -16,7 +21,9 @@ function createError (className) {
16
21
  writable: true
17
22
  })
18
23
 
19
- Error.captureStackTrace(this, this.constructor)
24
+ if ('captureStackTrace' in Error) {
25
+ Error.captureStackTrace(this, this.constructor)
26
+ }
20
27
  }
21
28
 
22
29
  inherits(ErrorClass, Error)
@@ -4,12 +4,12 @@ const cleanStack = require('clean-stack')
4
4
  const mimicFn = require('mimic-fn')
5
5
 
6
6
  const addErrorProps = require('./add-error-props')
7
- const {isString} = require('./helpers')
7
+ const { isString } = require('./helpers')
8
8
 
9
9
  function createExtendError (ErrorClass, classProps) {
10
10
  function ExtendError (props) {
11
11
  const error = new ErrorClass()
12
- const errorProps = isString(props) ? {message: props} : props
12
+ const errorProps = isString(props) ? { message: props } : props
13
13
  addErrorProps(error, classProps, errorProps)
14
14
 
15
15
  error.stack = cleanStack(error.stack)
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.0.1",
5
+ "version": "4.1.1",
6
6
  "main": "lib/index.js",
7
7
  "author": {
8
8
  "email": "josefrancisco.verdu@gmail.com",
@@ -24,15 +24,26 @@
24
24
  "throw"
25
25
  ],
26
26
  "dependencies": {
27
- "clean-stack": "~1.3.0",
28
- "mimic-fn": "~1.1.0"
27
+ "clean-stack": "~3.0.0",
28
+ "mimic-fn": "~3.1.0"
29
29
  },
30
30
  "devDependencies": {
31
- "coveralls": "latest",
31
+ "@commitlint/cli": "latest",
32
+ "@commitlint/config-conventional": "latest",
33
+ "c8": "latest",
34
+ "ci-publish": "latest",
35
+ "conventional-github-releaser": "latest",
36
+ "finepack": "latest",
37
+ "git-authors-cli": "latest",
32
38
  "mocha": "latest",
33
- "nyc": "latest",
39
+ "nano-staged": "latest",
40
+ "npm-check-updates": "latest",
41
+ "prettier-standard": "latest",
34
42
  "should": "latest",
35
- "standard": "latest"
43
+ "simple-git-hooks": "latest",
44
+ "standard": "latest",
45
+ "standard-markdown": "latest",
46
+ "standard-version": "latest"
36
47
  },
37
48
  "engines": {
38
49
  "node": ">= 8"
@@ -42,12 +53,40 @@
42
53
  ],
43
54
  "scripts": {
44
55
  "clean": "rm -rf node_modules",
56
+ "contributors": "(git-authors-cli && finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
45
57
  "coveralls": "nyc report --reporter=text-lcov | coveralls",
46
58
  "lint": "standard lib",
59
+ "postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
60
+ "prerelease": "npm run update:check && npm run contributors",
47
61
  "pretest": "npm run lint",
48
- "test": "nyc mocha"
62
+ "release": "standard-version -a",
63
+ "release:github": "conventional-github-releaser -p angular",
64
+ "release:tags": "git push --follow-tags origin HEAD:master",
65
+ "test": "c8 mocha",
66
+ "update": "ncu -u",
67
+ "update:check": "ncu -- --error-level 2"
49
68
  },
50
69
  "license": "MIT",
70
+ "commitlint": {
71
+ "extends": [
72
+ "@commitlint/config-conventional"
73
+ ]
74
+ },
75
+ "nano-staged": {
76
+ "*.js": [
77
+ "prettier-standard"
78
+ ],
79
+ "*.md": [
80
+ "standard-markdown"
81
+ ],
82
+ "package.json": [
83
+ "finepack"
84
+ ]
85
+ },
86
+ "simple-git-hooks": {
87
+ "commit-msg": "npx commitlint --edit",
88
+ "pre-commit": "npx nano-staged"
89
+ },
51
90
  "standard": {
52
91
  "env": "mocha"
53
92
  }
package/CHANGELOG.md DELETED
@@ -1,240 +0,0 @@
1
- <a name="4.0.1"></a>
2
- ## 4.0.1 (2017-08-08)
3
-
4
- * Reducing library size ([ce26a2d](https://github.com/kikobeats/whoops/commit/ce26a2d))
5
- * Update README.md ([2e71ec2](https://github.com/kikobeats/whoops/commit/2e71ec2))
6
-
7
-
8
-
9
- <a name="4.0.0"></a>
10
- # 4.0.0 (2017-08-08)
11
-
12
- * refactor ([ca6e60e](https://github.com/kikobeats/whoops/commit/ca6e60e))
13
- * Remove unnecessasry ([6ec4220](https://github.com/kikobeats/whoops/commit/6ec4220))
14
- * Support attach props into constructor ([8dd67b9](https://github.com/kikobeats/whoops/commit/8dd67b9))
15
- * Update builds ([6e6275c](https://github.com/kikobeats/whoops/commit/6e6275c))
16
- * Update docs ([515c498](https://github.com/kikobeats/whoops/commit/515c498))
17
- * Update README.md ([a0dc9b0](https://github.com/kikobeats/whoops/commit/a0dc9b0))
18
- * Update README.md ([b289826](https://github.com/kikobeats/whoops/commit/b289826))
19
- * Update README.md ([bf87a1f](https://github.com/kikobeats/whoops/commit/bf87a1f))
20
-
21
-
22
-
23
- <a name="3.1.1"></a>
24
- ## 3.1.1 (2017-07-18)
25
-
26
- * Update README.md ([4561a8b](https://github.com/kikobeats/whoops/commit/4561a8b))
27
- * docs(readme): add Greenkeeper badge ([9b93e2c](https://github.com/kikobeats/whoops/commit/9b93e2c))
28
- * chore(package): update clean-stack to version 1.2.0 ([b2cb039](https://github.com/kikobeats/whoops/commit/b2cb039))
29
- * chore(package): update clean-stack to version 1.3.0 ([12fb684](https://github.com/kikobeats/whoops/commit/12fb684))
30
-
31
-
32
-
33
- <a name="3.1.0"></a>
34
- # 3.1.0 (2016-12-19)
35
-
36
- * Add description field ([6b3b308](https://github.com/kikobeats/whoops/commit/6b3b308))
37
- * Drop node 5 from testing ([c223c7f](https://github.com/kikobeats/whoops/commit/c223c7f))
38
-
39
-
40
-
41
- <a name="3.0.3"></a>
42
- ## 3.0.3 (2016-12-19)
43
-
44
- * 80 → 100 lines ([a117bb8](https://github.com/kikobeats/whoops/commit/a117bb8))
45
- * Avoid inline regexp declaration ([2f91173](https://github.com/kikobeats/whoops/commit/2f91173))
46
- * Better docs ([591d743](https://github.com/kikobeats/whoops/commit/591d743))
47
- * Test refactor ([58fb3dc](https://github.com/kikobeats/whoops/commit/58fb3dc))
48
- * Update deps ([c0d5a49](https://github.com/kikobeats/whoops/commit/c0d5a49))
49
- * Update README.md ([c9c32f8](https://github.com/kikobeats/whoops/commit/c9c32f8))
50
-
51
-
52
-
53
- <a name="3.0.2"></a>
54
- ## 3.0.2 (2016-09-13)
55
-
56
- * chore(package): update clean-stack to version 1.0.0 ([ff0f4ce](https://github.com/kikobeats/whoops/commit/ff0f4ce))
57
- * Update ([ce66183](https://github.com/kikobeats/whoops/commit/ce66183))
58
-
59
-
60
-
61
- <a name="3.0.1"></a>
62
- ## 3.0.1 (2016-08-01)
63
-
64
- * Avoid eval for setup function name ([1ecde20](https://github.com/kikobeats/whoops/commit/1ecde20))
65
- * Remove interface string façade ([14c5932](https://github.com/kikobeats/whoops/commit/14c5932))
66
- * Remove unncessary check ([6a4d469](https://github.com/kikobeats/whoops/commit/6a4d469))
67
- * Rename extend-error → create-extend-error ([fd3726e](https://github.com/kikobeats/whoops/commit/fd3726e))
68
- * Setup Error name in constructor ([4ac076d](https://github.com/kikobeats/whoops/commit/4ac076d))
69
-
70
-
71
-
72
- <a name="3.0.0"></a>
73
- # 3.0.0 (2016-07-30)
74
-
75
- * Add clean-stack dep ([7f32385](https://github.com/kikobeats/whoops/commit/7f32385))
76
- * Drop < 4 node support ([185ae66](https://github.com/kikobeats/whoops/commit/185ae66))
77
- * Fix dep ([a87c1ea](https://github.com/kikobeats/whoops/commit/a87c1ea))
78
- * Refactor fn template ([942a189](https://github.com/kikobeats/whoops/commit/942a189))
79
- * Remove capture-stack-trace dep ([5fdae23](https://github.com/kikobeats/whoops/commit/5fdae23))
80
- * Remove string interface with 3 params ([5439d61](https://github.com/kikobeats/whoops/commit/5439d61))
81
- * Remove unnecessary dep ([78d6dac](https://github.com/kikobeats/whoops/commit/78d6dac))
82
- * Update docs ([34f5e8c](https://github.com/kikobeats/whoops/commit/34f5e8c))
83
-
84
-
85
-
86
- <a name="2.2.0"></a>
87
- # 2.2.0 (2016-07-30)
88
-
89
- * Add coverage ([1547649](https://github.com/kikobeats/whoops/commit/1547649))
90
- * Move pretty on different pkg ([3640943](https://github.com/kikobeats/whoops/commit/3640943))
91
- * Refactor scaffold ([5907391](https://github.com/kikobeats/whoops/commit/5907391))
92
- * Remove browser build ([e0e3621](https://github.com/kikobeats/whoops/commit/e0e3621))
93
-
94
-
95
-
96
- <a name="2.1.0"></a>
97
- # 2.1.0 (2016-05-19)
98
-
99
- * Add missing dependency ([b832bf0](https://github.com/kikobeats/whoops/commit/b832bf0))
100
- * Add pretty output ([a1c6e4c](https://github.com/kikobeats/whoops/commit/a1c6e4c))
101
- * Update docs ([1b6c6a8](https://github.com/kikobeats/whoops/commit/1b6c6a8))
102
- * Update README.md ([30224fe](https://github.com/kikobeats/whoops/commit/30224fe))
103
- * Update travis builds ([44e69b5](https://github.com/kikobeats/whoops/commit/44e69b5))
104
-
105
-
106
-
107
- <a name="2.0.1"></a>
108
- ## 2.0.1 (2016-02-07)
109
-
110
-
111
- * lock dependency ([9d36dd5](https://github.com/kikobeats/whoops/commit/9d36dd5))
112
-
113
-
114
-
115
- <a name="2.0.0"></a>
116
- # 2.0.0 (2016-02-03)
117
-
118
-
119
- * 2.0.0 releases ([c7ba44a](https://github.com/kikobeats/whoops/commit/c7ba44a))
120
- * Little refactor ([4fb84a1](https://github.com/kikobeats/whoops/commit/4fb84a1))
121
- * Refactor tests ([5fc36b1](https://github.com/kikobeats/whoops/commit/5fc36b1))
122
- * Setup correctly instanceof ([6436f3e](https://github.com/kikobeats/whoops/commit/6436f3e))
123
- * YEAH ([2c8b56b](https://github.com/kikobeats/whoops/commit/2c8b56b))
124
-
125
-
126
-
127
- <a name="1.1.1"></a>
128
- ## 1.1.1 (2016-01-28)
129
-
130
-
131
- * 1.1.1 releases ([60cb701](https://github.com/kikobeats/whoops/commit/60cb701))
132
- * Add standard as devDependency ([313a136](https://github.com/kikobeats/whoops/commit/313a136))
133
- * Remove lodash.forEach dep ([f5f96ee](https://github.com/kikobeats/whoops/commit/f5f96ee))
134
- * setup correctly bumped ([75d190b](https://github.com/kikobeats/whoops/commit/75d190b))
135
- * Update README.md ([ec8d39c](https://github.com/kikobeats/whoops/commit/ec8d39c))
136
- * Update README.md ([ff486b4](https://github.com/kikobeats/whoops/commit/ff486b4))
137
- * Update README.md ([23527e7](https://github.com/kikobeats/whoops/commit/23527e7))
138
-
139
-
140
-
141
- <a name="1.1.0"></a>
142
- # 1.1.0 (2016-01-14)
143
-
144
-
145
- * releases ([5fff532](https://github.com/kikobeats/whoops/commit/5fff532))
146
- * Add .create method ([1315768](https://github.com/kikobeats/whoops/commit/1315768))
147
- * Add coffe as devDependency ([ce75ae9](https://github.com/kikobeats/whoops/commit/ce75ae9))
148
- * Add custom message function in object factory ([470414c](https://github.com/kikobeats/whoops/commit/470414c))
149
- * bye coffee ([6a3a1d4](https://github.com/kikobeats/whoops/commit/6a3a1d4))
150
- * bye config ([e920003](https://github.com/kikobeats/whoops/commit/e920003))
151
- * Little tests refactor ([d3abb53](https://github.com/kikobeats/whoops/commit/d3abb53))
152
- * Update description and documentation ([0ad3cba](https://github.com/kikobeats/whoops/commit/0ad3cba))
153
- * Update scripts ([29240d2](https://github.com/kikobeats/whoops/commit/29240d2))
154
-
155
-
156
-
157
- <a name="1.0.1"></a>
158
- ## 1.0.1 (2015-11-23)
159
-
160
-
161
- * 1.0.1 releases ([56e26f2](https://github.com/kikobeats/whoops/commit/56e26f2))
162
- * Fix typos in README.md ([e9063f2](https://github.com/kikobeats/whoops/commit/e9063f2))
163
- * Merge branch 'master' of github.com:kikobeats/whoops ([a363134](https://github.com/kikobeats/whoops/commit/a363134))
164
- * Merge pull request #4 from jorrit/patch-1 ([d9156f6](https://github.com/kikobeats/whoops/commit/d9156f6))
165
- * rewrite to avoid new ([23e586b](https://github.com/kikobeats/whoops/commit/23e586b))
166
- * update to upgrade bower.json ([b18589d](https://github.com/kikobeats/whoops/commit/b18589d))
167
-
168
-
169
-
170
- <a name="1.0.0"></a>
171
- # 1.0.0 (2015-11-20)
172
-
173
-
174
- * 1.0.0 releases ([447ae1e](https://github.com/kikobeats/whoops/commit/447ae1e))
175
- * refactored and renamed ([cf2b458](https://github.com/kikobeats/whoops/commit/cf2b458))
176
- * removed extra spaces ([931245d](https://github.com/kikobeats/whoops/commit/931245d))
177
- * updated ([9bf0fde](https://github.com/kikobeats/whoops/commit/9bf0fde))
178
- * updated bumped config ([4583c59](https://github.com/kikobeats/whoops/commit/4583c59))
179
- * updated dependencies ([3d7ec1b](https://github.com/kikobeats/whoops/commit/3d7ec1b))
180
- * updated documentation ([6ea514b](https://github.com/kikobeats/whoops/commit/6ea514b))
181
- * updated renaming ([4b9306c](https://github.com/kikobeats/whoops/commit/4b9306c))
182
- * updated travis builds ([a330eae](https://github.com/kikobeats/whoops/commit/a330eae))
183
-
184
-
185
-
186
- <a name="0.2.0"></a>
187
- # 0.2.0 (2015-10-01)
188
-
189
-
190
- * 0.2.0 releases ([aff1849](https://github.com/kikobeats/whoops/commit/aff1849))
191
- * Added format for string constructor ([d584188](https://github.com/kikobeats/whoops/commit/d584188))
192
- * improve example ([aa2d318](https://github.com/kikobeats/whoops/commit/aa2d318))
193
- * little suite of tests 😁 ([5e11def](https://github.com/kikobeats/whoops/commit/5e11def))
194
- * Update package.json ([1120535](https://github.com/kikobeats/whoops/commit/1120535))
195
- * updated ([d5fc2d9](https://github.com/kikobeats/whoops/commit/d5fc2d9))
196
-
197
-
198
-
199
- <a name="0.1.3"></a>
200
- ## 0.1.3 (2015-07-28)
201
-
202
-
203
- * 0.1.3 releases ([e0de222](https://github.com/kikobeats/whoops/commit/e0de222))
204
- * fixed devDependencies ([bccbf41](https://github.com/kikobeats/whoops/commit/bccbf41))
205
- * updated bumped settings ([67ff23e](https://github.com/kikobeats/whoops/commit/67ff23e))
206
-
207
-
208
-
209
- <a name="0.1.2"></a>
210
- ## 0.1.2 (2015-07-28)
211
-
212
-
213
- * 0.1.2 releases ([7273df6](https://github.com/kikobeats/whoops/commit/7273df6))
214
-
215
-
216
-
217
- <a name="0.1.1"></a>
218
- ## 0.1.1 (2015-07-28)
219
-
220
-
221
- * 0.1.1 release ([6fcf6d7](https://github.com/kikobeats/whoops/commit/6fcf6d7))
222
- * 0.1.1 releases ([15d607b](https://github.com/kikobeats/whoops/commit/15d607b))
223
- * Update README.md ([d5e55b8](https://github.com/kikobeats/whoops/commit/d5e55b8))
224
- * Update README.md ([869be0a](https://github.com/kikobeats/whoops/commit/869be0a))
225
- * Update README.md ([8344dab](https://github.com/kikobeats/whoops/commit/8344dab))
226
- * updated dependencies ([afe3a10](https://github.com/kikobeats/whoops/commit/afe3a10))
227
-
228
-
229
-
230
- <a name="0.1.0"></a>
231
- # 0.1.0 (2015-07-26)
232
-
233
-
234
- * 0.1.0 releases ([594c110](https://github.com/kikobeats/whoops/commit/594c110))
235
- * added documentation and more examples ([3e68abb](https://github.com/kikobeats/whoops/commit/3e68abb))
236
- * first approach ([c52341b](https://github.com/kikobeats/whoops/commit/c52341b))
237
- * Update README.md ([e7172ab](https://github.com/kikobeats/whoops/commit/e7172ab))
238
-
239
-
240
-