(
pathOrHref: string,
search?: {[k: string]: unknown},
hash?: string,
baseUrl?: string,
)
| 173 | normalize(href: string): string; |
| 174 | normalize(path: string, search: {[k: string]: unknown}, hash: string, baseUrl?: string): string; |
| 175 | normalize( |
| 176 | pathOrHref: string, |
| 177 | search?: {[k: string]: unknown}, |
| 178 | hash?: string, |
| 179 | baseUrl?: string, |
| 180 | ): string { |
| 181 | if (arguments.length === 1) { |
| 182 | const parsed = this.parse(pathOrHref, baseUrl); |
| 183 | |
| 184 | if (typeof parsed === 'string') { |
| 185 | return parsed; |
| 186 | } |
| 187 | |
| 188 | const serverUrl = `${parsed.protocol}://${parsed.hostname}${ |
| 189 | parsed.port ? ':' + parsed.port : '' |
| 190 | }`; |
| 191 | |
| 192 | return this.normalize( |
| 193 | this.decodePath(parsed.pathname), |
| 194 | this.decodeSearch(parsed.search), |
| 195 | this.decodeHash(parsed.hash), |
| 196 | serverUrl, |
| 197 | ); |
| 198 | } else { |
| 199 | const encPath = this.encodePath(pathOrHref); |
| 200 | const encSearch = (search && this.encodeSearch(search)) || ''; |
| 201 | const encHash = (hash && this.encodeHash(hash)) || ''; |
| 202 | |
| 203 | let joinedPath = (baseUrl || '') + encPath; |
| 204 | |
| 205 | if (!joinedPath.length || joinedPath[0] !== '/') { |
| 206 | joinedPath = '/' + joinedPath; |
| 207 | } |
| 208 | return joinedPath + encSearch + encHash; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | areEqual(valA: string, valB: string) { |
| 213 | return this.normalize(valA) === this.normalize(valB); |
no test coverage detected