generated from ehmicky/template-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.d.ts
39 lines (38 loc) · 1.1 KB
/
main.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
type NormalizeError<ErrorArg> = ErrorArg extends Error ? ErrorArg : Error
/**
* Appends `message` to `error.message`. If `message` ends with `:` or `:\n`,
* prepends it instead.
*
* Returns `error`. If `error` is not an `Error` instance, it is converted to
* one.
*
* @example
* ```js
* wrapErrorMessage(new Error('Message.'), 'Additional message.')
* // Error: Message.
* // Additional message.
*
* wrapErrorMessage(new Error('Message.'), 'Additional message:')
* // Error: Additional message: Message.
*
* wrapErrorMessage(new Error('Message.'), 'Additional message:\n')
* // Error: Additional message:
* // Message.
*
* wrapErrorMessage(new Error('Message.'), '')
* // Error: Message.
*
* const invalidError = 'Message.'
* wrapErrorMessage(invalidError, 'Additional message.')
* // Error: Message.
* // Additional message.
*
* wrapErrorMessage(new Error(' Message with spaces '), ' Additional message ')
* // Error: Message with spaces
* // Additional message
* ```
*/
export default function wrapErrorMessage<ErrorArg>(
error: ErrorArg,
newMessage: string,
): NormalizeError<ErrorArg>