fp-ts-routing
Version:
A type-safe routing library for TypeScript
62 lines • 1.41 kB
JavaScript
import { Route } from './route';
/**
* @category formatters
* @since 0.4.0
*/
var Formatter = /** @class */ (function () {
function Formatter(run) {
this.run = run;
}
/**
* @since 0.4.0
*/
Formatter.prototype.contramap = function (f) {
var _this = this;
return new Formatter(function (r, b) { return _this.run(r, f(b)); });
};
/**
* @since 0.4.0
*/
Formatter.prototype.then = function (that) {
var _this = this;
return new Formatter(function (r, ab) { return that.run(_this.run(r, ab), ab); });
};
return Formatter;
}());
export { Formatter };
var FORMATTER_URI = 'fp-ts-routing/Formatter';
/**
* @category formatters
* @since 0.5.1
*/
export var formatter = {
URI: FORMATTER_URI,
contramap: function (fa, f) { return fa.contramap(f); }
};
/**
* @category formatters
* @since 0.5.1
*/
export var contramap = function (f) {
return function (fa) {
return formatter.contramap(fa, f);
};
};
/**
* @category formatters
* @since 0.6.0
*/
export var then = function (fb) {
return function (fa) {
return fa.then(fb);
};
};
/**
* @category formatters
* @since 0.4.0
*/
export var format = function (formatter, a, encode) {
if (encode === void 0) { encode = true; }
return formatter.run(Route.empty, a).toString(encode);
};
//# sourceMappingURL=formatter.js.map