github.com/nektos/act@v0.2.63/pkg/runner/testdata/actions/node12/node_modules/whatwg-url/lib/URL-impl.js (about) 1 "use strict"; 2 const usm = require("./url-state-machine"); 3 4 exports.implementation = class URLImpl { 5 constructor(constructorArgs) { 6 const url = constructorArgs[0]; 7 const base = constructorArgs[1]; 8 9 let parsedBase = null; 10 if (base !== undefined) { 11 parsedBase = usm.basicURLParse(base); 12 if (parsedBase === "failure") { 13 throw new TypeError("Invalid base URL"); 14 } 15 } 16 17 const parsedURL = usm.basicURLParse(url, { baseURL: parsedBase }); 18 if (parsedURL === "failure") { 19 throw new TypeError("Invalid URL"); 20 } 21 22 this._url = parsedURL; 23 24 // TODO: query stuff 25 } 26 27 get href() { 28 return usm.serializeURL(this._url); 29 } 30 31 set href(v) { 32 const parsedURL = usm.basicURLParse(v); 33 if (parsedURL === "failure") { 34 throw new TypeError("Invalid URL"); 35 } 36 37 this._url = parsedURL; 38 } 39 40 get origin() { 41 return usm.serializeURLOrigin(this._url); 42 } 43 44 get protocol() { 45 return this._url.scheme + ":"; 46 } 47 48 set protocol(v) { 49 usm.basicURLParse(v + ":", { url: this._url, stateOverride: "scheme start" }); 50 } 51 52 get username() { 53 return this._url.username; 54 } 55 56 set username(v) { 57 if (usm.cannotHaveAUsernamePasswordPort(this._url)) { 58 return; 59 } 60 61 usm.setTheUsername(this._url, v); 62 } 63 64 get password() { 65 return this._url.password; 66 } 67 68 set password(v) { 69 if (usm.cannotHaveAUsernamePasswordPort(this._url)) { 70 return; 71 } 72 73 usm.setThePassword(this._url, v); 74 } 75 76 get host() { 77 const url = this._url; 78 79 if (url.host === null) { 80 return ""; 81 } 82 83 if (url.port === null) { 84 return usm.serializeHost(url.host); 85 } 86 87 return usm.serializeHost(url.host) + ":" + usm.serializeInteger(url.port); 88 } 89 90 set host(v) { 91 if (this._url.cannotBeABaseURL) { 92 return; 93 } 94 95 usm.basicURLParse(v, { url: this._url, stateOverride: "host" }); 96 } 97 98 get hostname() { 99 if (this._url.host === null) { 100 return ""; 101 } 102 103 return usm.serializeHost(this._url.host); 104 } 105 106 set hostname(v) { 107 if (this._url.cannotBeABaseURL) { 108 return; 109 } 110 111 usm.basicURLParse(v, { url: this._url, stateOverride: "hostname" }); 112 } 113 114 get port() { 115 if (this._url.port === null) { 116 return ""; 117 } 118 119 return usm.serializeInteger(this._url.port); 120 } 121 122 set port(v) { 123 if (usm.cannotHaveAUsernamePasswordPort(this._url)) { 124 return; 125 } 126 127 if (v === "") { 128 this._url.port = null; 129 } else { 130 usm.basicURLParse(v, { url: this._url, stateOverride: "port" }); 131 } 132 } 133 134 get pathname() { 135 if (this._url.cannotBeABaseURL) { 136 return this._url.path[0]; 137 } 138 139 if (this._url.path.length === 0) { 140 return ""; 141 } 142 143 return "/" + this._url.path.join("/"); 144 } 145 146 set pathname(v) { 147 if (this._url.cannotBeABaseURL) { 148 return; 149 } 150 151 this._url.path = []; 152 usm.basicURLParse(v, { url: this._url, stateOverride: "path start" }); 153 } 154 155 get search() { 156 if (this._url.query === null || this._url.query === "") { 157 return ""; 158 } 159 160 return "?" + this._url.query; 161 } 162 163 set search(v) { 164 // TODO: query stuff 165 166 const url = this._url; 167 168 if (v === "") { 169 url.query = null; 170 return; 171 } 172 173 const input = v[0] === "?" ? v.substring(1) : v; 174 url.query = ""; 175 usm.basicURLParse(input, { url, stateOverride: "query" }); 176 } 177 178 get hash() { 179 if (this._url.fragment === null || this._url.fragment === "") { 180 return ""; 181 } 182 183 return "#" + this._url.fragment; 184 } 185 186 set hash(v) { 187 if (v === "") { 188 this._url.fragment = null; 189 return; 190 } 191 192 const input = v[0] === "#" ? v.substring(1) : v; 193 this._url.fragment = ""; 194 usm.basicURLParse(input, { url: this._url, stateOverride: "fragment" }); 195 } 196 197 toJSON() { 198 return this.href; 199 } 200 };