1 | import { getFunctionName } from '.';
|
2 | import { fold } from 'fp-ts/es6/Either';
|
3 | function stringify(v) {
|
4 | if (typeof v === 'function') {
|
5 | return getFunctionName(v);
|
6 | }
|
7 | if (typeof v === 'number' && !isFinite(v)) {
|
8 | if (isNaN(v)) {
|
9 | return 'NaN';
|
10 | }
|
11 | return v > 0 ? 'Infinity' : '-Infinity';
|
12 | }
|
13 | return JSON.stringify(v);
|
14 | }
|
15 | function getContextPath(context) {
|
16 | return context.map(function (_a) {
|
17 | var key = _a.key, type = _a.type;
|
18 | return key + ": " + type.name;
|
19 | }).join('/');
|
20 | }
|
21 | function getMessage(e) {
|
22 | return e.message !== undefined
|
23 | ? e.message
|
24 | : "Invalid value " + stringify(e.value) + " supplied to " + getContextPath(e.context);
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 | export function failure(es) {
|
30 | return es.map(getMessage);
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 | export function success() {
|
36 | return ['No errors!'];
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 | export var PathReporter = {
|
42 | report: fold(failure, success)
|
43 | };
|