Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

URL-impl.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. "use strict";
  2. const usm = require("./url-state-machine");
  3. const urlencoded = require("./urlencoded");
  4. const URLSearchParams = require("./URLSearchParams");
  5. exports.implementation = class URLImpl {
  6. constructor(globalObject, constructorArgs) {
  7. const url = constructorArgs[0];
  8. const base = constructorArgs[1];
  9. let parsedBase = null;
  10. if (base !== undefined) {
  11. parsedBase = usm.basicURLParse(base);
  12. if (parsedBase === null) {
  13. throw new TypeError(`Invalid base URL: ${base}`);
  14. }
  15. }
  16. const parsedURL = usm.basicURLParse(url, { baseURL: parsedBase });
  17. if (parsedURL === null) {
  18. throw new TypeError(`Invalid URL: ${url}`);
  19. }
  20. const query = parsedURL.query !== null ? parsedURL.query : "";
  21. this._url = parsedURL;
  22. // We cannot invoke the "new URLSearchParams object" algorithm without going through the constructor, which strips
  23. // question mark by default. Therefore the doNotStripQMark hack is used.
  24. this._query = URLSearchParams.createImpl(globalObject, [query], { doNotStripQMark: true });
  25. this._query._url = this;
  26. }
  27. get href() {
  28. return usm.serializeURL(this._url);
  29. }
  30. set href(v) {
  31. const parsedURL = usm.basicURLParse(v);
  32. if (parsedURL === null) {
  33. throw new TypeError(`Invalid URL: ${v}`);
  34. }
  35. this._url = parsedURL;
  36. this._query._list.splice(0);
  37. const { query } = parsedURL;
  38. if (query !== null) {
  39. this._query._list = urlencoded.parseUrlencodedString(query);
  40. }
  41. }
  42. get origin() {
  43. return usm.serializeURLOrigin(this._url);
  44. }
  45. get protocol() {
  46. return `${this._url.scheme}:`;
  47. }
  48. set protocol(v) {
  49. usm.basicURLParse(`${v}:`, { url: this._url, stateOverride: "scheme start" });
  50. }
  51. get username() {
  52. return this._url.username;
  53. }
  54. set username(v) {
  55. if (usm.cannotHaveAUsernamePasswordPort(this._url)) {
  56. return;
  57. }
  58. usm.setTheUsername(this._url, v);
  59. }
  60. get password() {
  61. return this._url.password;
  62. }
  63. set password(v) {
  64. if (usm.cannotHaveAUsernamePasswordPort(this._url)) {
  65. return;
  66. }
  67. usm.setThePassword(this._url, v);
  68. }
  69. get host() {
  70. const url = this._url;
  71. if (url.host === null) {
  72. return "";
  73. }
  74. if (url.port === null) {
  75. return usm.serializeHost(url.host);
  76. }
  77. return `${usm.serializeHost(url.host)}:${usm.serializeInteger(url.port)}`;
  78. }
  79. set host(v) {
  80. if (this._url.cannotBeABaseURL) {
  81. return;
  82. }
  83. usm.basicURLParse(v, { url: this._url, stateOverride: "host" });
  84. }
  85. get hostname() {
  86. if (this._url.host === null) {
  87. return "";
  88. }
  89. return usm.serializeHost(this._url.host);
  90. }
  91. set hostname(v) {
  92. if (this._url.cannotBeABaseURL) {
  93. return;
  94. }
  95. usm.basicURLParse(v, { url: this._url, stateOverride: "hostname" });
  96. }
  97. get port() {
  98. if (this._url.port === null) {
  99. return "";
  100. }
  101. return usm.serializeInteger(this._url.port);
  102. }
  103. set port(v) {
  104. if (usm.cannotHaveAUsernamePasswordPort(this._url)) {
  105. return;
  106. }
  107. if (v === "") {
  108. this._url.port = null;
  109. } else {
  110. usm.basicURLParse(v, { url: this._url, stateOverride: "port" });
  111. }
  112. }
  113. get pathname() {
  114. if (this._url.cannotBeABaseURL) {
  115. return this._url.path[0];
  116. }
  117. if (this._url.path.length === 0) {
  118. return "";
  119. }
  120. return `/${this._url.path.join("/")}`;
  121. }
  122. set pathname(v) {
  123. if (this._url.cannotBeABaseURL) {
  124. return;
  125. }
  126. this._url.path = [];
  127. usm.basicURLParse(v, { url: this._url, stateOverride: "path start" });
  128. }
  129. get search() {
  130. if (this._url.query === null || this._url.query === "") {
  131. return "";
  132. }
  133. return `?${this._url.query}`;
  134. }
  135. set search(v) {
  136. const url = this._url;
  137. if (v === "") {
  138. url.query = null;
  139. this._query._list = [];
  140. return;
  141. }
  142. const input = v[0] === "?" ? v.substring(1) : v;
  143. url.query = "";
  144. usm.basicURLParse(input, { url, stateOverride: "query" });
  145. this._query._list = urlencoded.parseUrlencodedString(input);
  146. }
  147. get searchParams() {
  148. return this._query;
  149. }
  150. get hash() {
  151. if (this._url.fragment === null || this._url.fragment === "") {
  152. return "";
  153. }
  154. return `#${this._url.fragment}`;
  155. }
  156. set hash(v) {
  157. if (v === "") {
  158. this._url.fragment = null;
  159. return;
  160. }
  161. const input = v[0] === "#" ? v.substring(1) : v;
  162. this._url.fragment = "";
  163. usm.basicURLParse(input, { url: this._url, stateOverride: "fragment" });
  164. }
  165. toJSON() {
  166. return this.href;
  167. }
  168. };