fp-ts-std
Version:
The missing pseudo-standard library for fp-ts.
50 lines (49 loc) • 2.37 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Eq = exports.getHostname = exports.getOrigin = exports.setHash = exports.modifyHash = exports.getHash = exports.setParams = exports.modifyParams = exports.getParams = exports.setPathname = exports.modifyPathname = exports.getPathname = exports.toString = exports.isStringlyURL = exports.isURL = exports.parseO = exports.parse = exports.unsafeParse = exports.clone = void 0;
const E = require("fp-ts/Either");
const Eq_ = require("fp-ts/Eq");
const O = require("fp-ts/Option");
const function_1 = require("fp-ts/function");
const Str = require("fp-ts/string");
const Function_1 = require("./Function");
const Params = require("./URLSearchParams");
const constructor = (x) => new URL(x);
exports.clone = constructor;
exports.unsafeParse = constructor;
const parse = (f) => (x) => E.tryCatch(() => (0, exports.unsafeParse)(x), e => f(e));
exports.parse = parse;
exports.parseO = (0, function_1.flow)((0, exports.parse)(function_1.identity), O.fromEither);
exports.isURL = (0, Function_1.isInstanceOf)(URL);
exports.isStringlyURL = (0, function_1.flow)(exports.parseO, O.isSome);
const toString = (x) => x.toString();
exports.toString = toString;
const getPathname = (x) => x.pathname;
exports.getPathname = getPathname;
const modifyPathname = (f) => (0, function_1.flow)(exports.clone, x => {
x.pathname = f(x.pathname);
return x;
});
exports.modifyPathname = modifyPathname;
exports.setPathname = (0, function_1.flow)(function_1.constant, exports.modifyPathname);
const getParams = (x) => x.searchParams;
exports.getParams = getParams;
const modifyParams = (f) => (0, function_1.flow)(exports.clone, x => {
x.search = Params.toString(f(x.searchParams));
return x;
});
exports.modifyParams = modifyParams;
exports.setParams = (0, function_1.flow)(function_1.constant, exports.modifyParams);
const getHash = (x) => x.hash;
exports.getHash = getHash;
const modifyHash = (f) => (0, function_1.flow)(exports.clone, x => {
x.hash = f(x.hash);
return x;
});
exports.modifyHash = modifyHash;
exports.setHash = (0, function_1.flow)(function_1.constant, exports.modifyHash);
const getOrigin = (x) => x.origin;
exports.getOrigin = getOrigin;
const getHostname = (x) => x.hostname;
exports.getHostname = getHostname;
exports.Eq = Eq_.contramap(exports.toString)(Str.Eq);
;