Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions dist/either.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const exhaustive_1 = require("@freckle/exhaustive");
import { exhaustive } from '@freckle/exhaustive';
const Either = {
// Construct a value with the 'left' tag
Left(left) {
Expand All @@ -19,7 +17,7 @@ const Either = {
case 'right':
return branches.right(e.right);
default:
return (0, exhaustive_1.exhaustive)(e, 'EitherT');
return exhaustive(e, 'EitherT');
}
},
// Wrap a pure value in EitherT by tagging it with 'right'
Expand Down Expand Up @@ -63,4 +61,4 @@ const Either = {
});
}
};
exports.default = Either;
export default Either;
2 changes: 1 addition & 1 deletion dist/formatting.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { type ErrorStackT } from './index';
import { type ErrorStackT } from './index.js';
export declare function formatError(root: ErrorStackT): string;
export declare function saferStringify(root: any): string;
27 changes: 10 additions & 17 deletions dist/formatting.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatError = formatError;
exports.saferStringify = saferStringify;
const times_1 = __importDefault(require("lodash/times"));
const maybe_1 = require("@freckle/maybe");
const exhaustive_1 = require("@freckle/exhaustive");
const path_1 = __importDefault(require("./path"));
import { times } from 'lodash';
import { mapMaybes } from '@freckle/maybe';
import { exhaustive } from '@freckle/exhaustive';
import Path from './path.js';
// Format an ErrorStackT into a human-readable message
//
// For example, the following ErrorStackT:
Expand Down Expand Up @@ -50,7 +43,7 @@ const path_1 = __importDefault(require("./path"));
// The top of the error message applies to the deepest part of the
// data structure. Further down, we provide more context about where
// the error occurred.
function formatError(root) {
export function formatError(root) {
function walk(node, lines) {
switch (node.tag) {
case 'fail': {
Expand All @@ -68,7 +61,7 @@ function formatError(root) {
}
case 'context': {
const { expected, element, input, next } = node;
const path = path_1.default.join(element);
const path = Path.join(element);
const where = path === null || path === undefined ? 'in' : `at key path ${path} of`;
const example = input === null || input === undefined
? []
Expand All @@ -77,7 +70,7 @@ function formatError(root) {
return walk(next, [...newLines, ...lines]);
}
default:
return (0, exhaustive_1.exhaustive)(node, 'ErrorStackT');
return exhaustive(node, 'ErrorStackT');
}
}
return walk(root, []).join('\n');
Expand Down Expand Up @@ -128,15 +121,15 @@ function typeofDeep(root, maxDepth = 20) {
}
}
}
const pairs = (0, maybe_1.mapMaybes)(Object.keys(node), key =>
const pairs = mapMaybes(Object.keys(node), key =>
// eslint-disable-next-line no-prototype-builtins
node.hasOwnProperty(key) ? `${key}: ${walk(node[key], depth + 1)}` : null);
return `{${pairs.join(', ')}}`;
}
return walk(root, 0);
}
// JSON.stringify ignores undefined and throws on circular objects
function saferStringify(root) {
export function saferStringify(root) {
if (root === undefined) {
return 'undefined';
}
Expand All @@ -152,5 +145,5 @@ function saferStringify(root) {
}
// Indent string n spaces
function indent(n, text) {
return `${(0, times_1.default)(n, () => ' ').join('')}${text}`;
return `${times(n, () => ' ').join('')}${text}`;
}
8 changes: 4 additions & 4 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type Moment } from 'moment-timezone';
import { type NonEmptyArray } from '@freckle/non-empty';
import { type PathT } from './path';
import { type EitherT } from './either';
export { saferStringify } from './formatting';
export { parseExpect, parseSuccess, parseFailure } from './test-helper';
import { type PathT } from './path.js';
import { type EitherT } from './either.js';
export { saferStringify } from './formatting.js';
export { parseExpect, parseSuccess, parseFailure } from './test-helper.js';
type LevelT = 'recoverable' | 'fatal';
export type ErrorStackT = {
tag: 'fail';
Expand Down
Loading
Loading