UNPKG

984 BJavaScriptView Raw
1import { getFunctionName } from '.';
2import { fold } from 'fp-ts/es6/Either';
3function 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}
15function getContextPath(context) {
16 return context.map(function (_a) {
17 var key = _a.key, type = _a.type;
18 return key + ": " + type.name;
19 }).join('/');
20}
21function getMessage(e) {
22 return e.message !== undefined
23 ? e.message
24 : "Invalid value " + stringify(e.value) + " supplied to " + getContextPath(e.context);
25}
26/**
27 * @since 1.0.0
28 */
29export function failure(es) {
30 return es.map(getMessage);
31}
32/**
33 * @since 1.0.0
34 */
35export function success() {
36 return ['No errors!'];
37}
38/**
39 * @since 1.0.0
40 */
41export var PathReporter = {
42 report: fold(failure, success)
43};