push
github
23 of 25 branches covered (92.0%)
105 of 109 relevant lines covered (96.33%)
6.87 hits per line
1 |
'use strict'
|
|
2 |
|
1✔ |
3 |
const { inherits } = require('./helpers')
|
1✔ |
4 |
const mimicFn = require('mimic-fn')
|
1✔ |
5 |
|
1✔ |
6 |
const REGEX_CLASS_NAME = /[^0-9a-zA-Z_$]/
|
1✔ |
7 |
|
1✔ |
8 |
function createError (className) { |
|
9 |
if (typeof className !== 'string') { |
|
10 |
throw new TypeError('Expected className to be a string') |
× |
11 |
} |
× |
12 |
|
13✔ |
13 |
if (REGEX_CLASS_NAME.test(className)) {
|
|
14 |
throw new Error('className contains invalid characters') |
× |
15 |
} |
× |
16 |
|
13✔ |
17 |
function ErrorClass () { |
|
18 |
Object.defineProperty(this, 'name', { |
11✔ |
19 |
configurable: true, |
11✔ |
20 |
value: className,
|
11✔ |
21 |
writable: true |
11✔ |
22 |
}) |
11✔ |
23 |
|
11✔ |
24 |
if ('captureStackTrace' in Error) { |
11✔ |
25 |
Error.captureStackTrace(this, this.constructor) |
11✔ |
26 |
} |
11✔ |
27 |
} |
11✔ |
28 |
|
13✔ |
29 |
inherits(ErrorClass, Error) |
13✔ |
30 |
mimicFn(ErrorClass, Error) |
13✔ |
31 |
return ErrorClass
|
13✔ |
32 |
} |
13✔ |
33 |
|
1✔ |
34 |
module.exports = createError |
1✔ |