@@ -107,43 +107,53 @@ export class URL {
107107 }
108108
109109 get hash ( ) : string {
110- throw new Error ( 'URL.hash is not implemented' ) ;
110+ const hashMatch = this . _url . match ( / # ( .* ) $ / ) ;
111+ return hashMatch ? `#${ hashMatch [ 1 ] } ` : '' ;
111112 }
112113
113114 get host ( ) : string {
114- throw new Error ( 'URL.host is not implemented' ) ;
115+ const hostMatch = this . _url . match ( / ^ h t t p s ? : \/ \/ ( [ ^ : / ? # ] + ) / ) ;
116+ const portMatch = this . _url . match ( / : ( \d + ) (? = [ / ? # ] | $ ) / ) ;
117+ return hostMatch ? hostMatch [ 1 ] + ( portMatch ? `:${ portMatch [ 1 ] } ` : '' ) : '' ;
115118 }
116119
117120 get hostname ( ) : string {
118- throw new Error ( 'URL.hostname is not implemented' ) ;
121+ const hostnameMatch = this . _url . match ( / ^ h t t p s ? : \/ \/ ( [ ^ : / ? # ] + ) / ) ;
122+ return hostnameMatch ? hostnameMatch [ 1 ] : '' ;
119123 }
120124
121125 get href ( ) : string {
122126 return this . toString ( ) ;
123127 }
124128
125129 get origin ( ) : string {
126- throw new Error ( 'URL.origin is not implemented' ) ;
130+ const matches = this . _url . match ( / ^ ( h t t p s ? : \/ \/ [ ^ / ] + ) / ) ;
131+ return matches ? matches [ 1 ] : '' ;
127132 }
128133
129134 get password ( ) : string {
130- throw new Error ( 'URL.password is not implemented' ) ;
135+ const passwordMatch = this . _url . match ( / h t t p s ? : \/ \/ .* : ( .* ) @ / ) ;
136+ return passwordMatch ? passwordMatch [ 1 ] : '' ;
131137 }
132138
133139 get pathname ( ) : string {
134- throw new Error ( 'URL.pathname not implemented' ) ;
140+ const pathMatch = this . _url . match ( / h t t p s ? : \/ \/ [ ^ / ] + ( \/ [ ^ ? # ] * ) ? / ) ;
141+ return pathMatch ? pathMatch [ 1 ] || '/' : '/' ;
135142 }
136143
137144 get port ( ) : string {
138- throw new Error ( 'URL.port is not implemented' ) ;
145+ const portMatch = this . _url . match ( / : ( \d + ) (? = [ / ? # ] | $ ) / ) ;
146+ return portMatch ? portMatch [ 1 ] : '' ;
139147 }
140148
141149 get protocol ( ) : string {
142- throw new Error ( 'URL.protocol is not implemented' ) ;
150+ const protocolMatch = this . _url . match ( / ^ ( [ a - z A - Z ] [ a - z A - Z \d + \- . ] * ) : / ) ;
151+ return protocolMatch ? protocolMatch [ 1 ] + ':' : '' ;
143152 }
144153
145154 get search ( ) : string {
146- throw new Error ( 'URL.search is not implemented' ) ;
155+ const searchMatch = this . _url . match ( / \? ( [ ^ # ] * ) / ) ;
156+ return searchMatch ? `?${ searchMatch [ 1 ] } ` : '' ;
147157 }
148158
149159 get searchParams ( ) : URLSearchParams {
0 commit comments