@@ -12,7 +12,6 @@ import type Blob from './Blob';
1212
1313import NativeBlobModule from './NativeBlobModule' ;
1414
15-
1615let BLOB_URL_PREFIX = null ;
1716
1817if (
@@ -73,13 +72,12 @@ export class URL {
7372 return `${ BLOB_URL_PREFIX } ${ blob . data . blobId } ?offset=${ blob . data . offset } &size=${ blob . size } ` ;
7473 }
7574
76-
7775 static revokeObjectURL ( url : string ) {
7876 // Do nothing.
7977 }
8078
8179 // $FlowFixMe[missing-local-annot]
82- constructor ( url : string , base : string | URL ) {
80+ constructor ( url : string , base ? : string | URL ) {
8381 let baseUrl = null ;
8482 if ( ! base || validateBaseUrl ( url ) ) {
8583 this . _url = url ;
@@ -109,14 +107,12 @@ export class URL {
109107 }
110108
111109 get hash ( ) : string {
112- const hashMatch = this . _url . match ( / # ( [ ^ / ] * ) / ) ;
113- return hashMatch ? `#${ hashMatch [ 1 ] } ` : '' ;
110+ throw new Error ( 'URL.hash is not implemented' ) ;
114111 }
115112
116113 get host ( ) : string {
117114 const hostMatch = this . _url . match ( / ^ h t t p s ? : \/ \/ (?: [ ^ @ ] + @ ) ? ( [ ^ : / ? # ] + ) / ) ;
118115 const portMatch = this . _url . match ( / : ( \d + ) (? = [ / ? # ] | $ ) / ) ;
119-
120116 return hostMatch ? hostMatch [ 1 ] + ( portMatch ? `:${ portMatch [ 1 ] } ` : '' ) : '' ;
121117 }
122118
@@ -139,12 +135,6 @@ export class URL {
139135 return passwordMatch ? passwordMatch [ 1 ] : '' ;
140136 }
141137
142- get username ( ) : string {
143-
144- const usernameMatch = this . _url . match ( / ^ h t t p s ? : \/ \/ ( [ ^ : @ ] + ) (?: : [ ^ @ ] * ) ? @ / ) ;
145- return usernameMatch ? usernameMatch [ 1 ] : '' ;
146- }
147-
148138 get pathname ( ) : string {
149139 const pathMatch = this . _url . match ( / h t t p s ? : \/ \/ [ ^ / ] + ( \/ [ ^ ? # ] * ) ? / ) ;
150140 return pathMatch ? pathMatch [ 1 ] || '/' : '/' ;
@@ -186,4 +176,8 @@ export class URL {
186176 return this . _url + separator + instanceString ;
187177 }
188178
179+ get username ( ) : string {
180+ const usernameMatch = this . _url . match ( / ^ h t t p s ? : \/ \/ ( [ ^ : @ ] + ) (?: : [ ^ @ ] * ) ? @ / ) ;
181+ return usernameMatch ? usernameMatch [ 1 ] : '' ;
182+ }
189183}
0 commit comments