git.schokokeks.org
Repositories
Help
Report an Issue
fs-words.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
565e59b
Branches
Tags
develop-client_server
master
typescript
fs-words.git
client
lib
plankton
url
logic-impl.js
[upd] client:lib:plankton
Christian Fraß
commited
565e59b
at 2021-03-12 22:00:08
logic-impl.js
Blame
History
Raw
/* This file is part of »bacterio-plankton:url«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:url« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:url« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:url«. If not, see <http://www.gnu.org/licenses/>. */ /* This file is part of »bacterio-plankton:url«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:url« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:url« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:url«. If not, see <http://www.gnu.org/licenses/>. */ var lib_url; (function (lib_url) { /** * @author fenris */ function encode(url, { "protocol": protocol = null, "host": host = null, "port": port = null, "path": path = null, "arguments": arguments_ = null, } = {}) { let result = ""; // protocol { if (url.hasOwnProperty("protocol") && (url.protocol !== null)) { result = `${url.protocol}:${result}`; } } // host { if (url.hasOwnProperty("host") && (url.host !== null)) { result = `${result}//${url.host}`; } } // port { if (url.hasOwnProperty("port") && (url.port !== null)) { result = `${result}:${url.port.toString()}`; } } // path { if (url.hasOwnProperty("path") && (url.path !== null)) { const path = encodeURI(url.path); result = `${result}${path}`; } } // arguments { if (url.hasOwnProperty("arguments") && (url.arguments !== null)) { const suffix = Object.keys(url.arguments).map(key => `${key}=${url.arguments[key]}`).join("&"); const suffix_ = encodeURI(suffix); result = `${result}?${suffix_}`; } } return result; } lib_url.encode = encode; /** * @author fenris * @todo arguments */ function decode(url_raw) { const regexp = new RegExp("^([^:]*)://([^:]*):([^/]*)/(.*)$"); const matching = regexp.exec(url_raw); if (matching === null) { throw (new Error("url could not be decoded")); } else { const url = { "protocol": matching[1], "host": matching[2], "port": parseInt(matching[3]), "path": ("/" + matching[4]), }; return url; } } lib_url.decode = decode; })(lib_url || (lib_url = {})); /* This file is part of »bacterio-plankton:url«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:url« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:url« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:url«. If not, see <http://www.gnu.org/licenses/>. */ var lib_url; (function (lib_url) { /** * @author fenris */ lib_trait.attend("code", "url", { "from": { "name": "any" }, "to": { "name": "string" } }, { "encode": () => (x) => { return lib_url.encode(x); }, "decode": () => (y) => { return lib_url.decode(y); } }); })(lib_url || (lib_url = {})); /* This file is part of »bacterio-plankton:url«. Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' <info@greenscale.de> »bacterio-plankton:url« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »bacterio-plankton:url« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:url«. If not, see <http://www.gnu.org/licenses/>. */ var lib_url; (function (lib_url) { /** * @author fenris */ class class_url { /** * @author fenris */ constructor() { } /** * @implementation * @author fenris */ encode(x) { return lib_url.encode(x); } /** * @implementation * @author fenris */ decode(x) { return lib_url.decode(x); } } lib_url.class_url = class_url; })(lib_url || (lib_url = {}));