fp-ts-routing
Version:
A type-safe routing library for TypeScript
68 lines • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.format = exports.then = exports.contramap = exports.formatter = exports.Formatter = void 0;
var route_1 = require("./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;
}());
exports.Formatter = Formatter;
var FORMATTER_URI = 'fp-ts-routing/Formatter';
/**
* @category formatters
* @since 0.5.1
*/
exports.formatter = {
URI: FORMATTER_URI,
contramap: function (fa, f) { return fa.contramap(f); }
};
/**
* @category formatters
* @since 0.5.1
*/
var contramap = function (f) {
return function (fa) {
return exports.formatter.contramap(fa, f);
};
};
exports.contramap = contramap;
/**
* @category formatters
* @since 0.6.0
*/
var then = function (fb) {
return function (fa) {
return fa.then(fb);
};
};
exports.then = then;
/**
* @category formatters
* @since 0.4.0
*/
var format = function (formatter, a, encode) {
if (encode === void 0) { encode = true; }
return formatter.run(route_1.Route.empty, a).toString(encode);
};
exports.format = format;
//# sourceMappingURL=formatter.js.map