Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 0108341

Browse files
authored
Merge pull request #90 from exoego/url
Overhaul url module
2 parents a325ce7 + d0c4fb2 commit 0108341

File tree

5 files changed

+60
-77
lines changed

5 files changed

+60
-77
lines changed

app/current/src/main/scala/io/scalajs/nodejs/url/URL.scala

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.scalajs.nodejs
22
package url
33

4+
import com.thoughtworks.enableIf
45
import io.scalajs.nodejs.events.IEventEmitter
56

67
import scala.scalajs.js
@@ -114,20 +115,16 @@ object URL extends IEventEmitter {
114115
* Take a parsed URL object, and return a formatted URL string.
115116
* @example url.format(urlObj)
116117
*/
118+
@deprecated("Use URL instead", "Node.js v11.0.0")
117119
def format(urlObj: URLObject): String = js.native
118120

119121
/**
120-
* Take a URL string, and return an object.
121-
*
122-
* Pass true as the second argument to also parse the query string using the querystring module. If true then the
123-
* query property will always be assigned an object, and the search property will always be a (possibly empty)
124-
* string. If false then the query property will not be parsed or decoded. Defaults to false.
125-
*
126-
* Pass true as the third argument to treat //foo/bar as { host: 'foo', pathname: '/bar' } rather
127-
* than { pathname: '//foo/bar' }. Defaults to false.
128-
* @example url.parse(urlStr[, parseQueryString][, slashesDenoteHost])
122+
* Returns a customizable serialization of a URL String representation of a WHATWG URL object.
123+
* @param url the given [[URL]]
124+
* @param options the given [[UrlFormatOptions options]]
125+
* @return a customizable serialization of a URL String representation of a WHATWG URL object.
129126
*/
130-
def parse(urlStr: String, parseQueryString: String, slashesDenoteHost: Boolean): URLObject = js.native
127+
def format(url: URL, options: UrlFormatOptions = js.native): String = js.native
131128

132129
/**
133130
* Take a URL string, and return an object.
@@ -140,32 +137,13 @@ object URL extends IEventEmitter {
140137
* than { pathname: '//foo/bar' }. Defaults to false.
141138
* @example url.parse(urlStr[, parseQueryString][, slashesDenoteHost])
142139
*/
143-
def parse(urlStr: String, parseQueryString: String): URLObject = js.native
140+
@deprecated("Use URL instead", "Node.js v11.0.0")
141+
def parse(urlStr: String, parseQueryString: Boolean, slashesDenoteHost: Boolean): URLObject = js.native
144142

145-
/**
146-
* Take a URL string, and return an object.
147-
*
148-
* Pass true as the second argument to also parse the query string using the querystring module. If true then the
149-
* query property will always be assigned an object, and the search property will always be a (possibly empty)
150-
* string. If false then the query property will not be parsed or decoded. Defaults to false.
151-
*
152-
* Pass true as the third argument to treat //foo/bar as { host: 'foo', pathname: '/bar' } rather
153-
* than { pathname: '//foo/bar' }. Defaults to false.
154-
* @example url.parse(urlStr[, parseQueryString][, slashesDenoteHost])
155-
*/
156-
def parse(urlStr: String, slashesDenoteHost: Boolean): URLObject = js.native
143+
@deprecated("Use URL instead", "Node.js v11.0.0")
144+
def parse(urlStr: String, parseQueryString: Boolean): URLObject = js.native
157145

158-
/**
159-
* Take a URL string, and return an object.
160-
*
161-
* Pass true as the second argument to also parse the query string using the querystring module. If true then the
162-
* query property will always be assigned an object, and the search property will always be a (possibly empty)
163-
* string. If false then the query property will not be parsed or decoded. Defaults to false.
164-
*
165-
* Pass true as the third argument to treat //foo/bar as { host: 'foo', pathname: '/bar' } rather
166-
* than { pathname: '//foo/bar' }. Defaults to false.
167-
* @example url.parse(urlStr[, parseQueryString][, slashesDenoteHost])
168-
*/
146+
@deprecated("Use URL instead", "Node.js v11.0.0")
169147
def parse(urlStr: String): URLObject = js.native
170148

171149
/**
@@ -176,6 +154,27 @@ object URL extends IEventEmitter {
176154
* url.resolve('http://example.com/one', '/two') // 'http://example.com/two'
177155
* @example url.resolve(from, to)
178156
*/
157+
@deprecated("Use URL instead", "Node.js v11.0.0")
179158
def resolve(from: String, to: String): String = js.native
180159

160+
/**
161+
* Returns the Punycode ASCII serialization of the domain. If domain is an invalid domain, the empty string is returned.
162+
* @param domain the domain
163+
* @return the Punycode ASCII serialization of the domain
164+
*/
165+
def domainToASCII(domain: String): String = js.native
166+
167+
/**
168+
* Returns the Unicode serialization of the domain. If domain is an invalid domain, the empty string is returned.
169+
* @param domain the domain
170+
* @return the Unicode serialization of the domain
171+
*/
172+
def domainToUnicode(domain: String): String = js.native
173+
174+
@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs10)
175+
def fileURLToPath(url: URL | String): String = js.native
176+
177+
@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs10)
178+
def pathToFileURL(url: String): URL = js.native
179+
181180
}

app/current/src/main/scala/io/scalajs/nodejs/url/URLObject.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import scala.scalajs.js
66
* Parsed URL Object
77
*/
88
@js.native
9+
@deprecated("Use URL instead", "Node.js v11.0.0")
910
trait URLObject extends js.Object {
1011

1112
/**

app/current/src/main/scala/io/scalajs/nodejs/url/URLSearchParams.scala

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import scala.scalajs.js.annotation.JSImport
1313
*/
1414
@js.native
1515
@JSImport("url", "URLSearchParams")
16-
class URLSearchParams extends js.Object {
16+
class URLSearchParams() extends js.Object {
1717

1818
/**
1919
* Parse the string as a query string, and use it to instantiate a new URLSearchParams object.
@@ -43,7 +43,7 @@ class URLSearchParams extends js.Object {
4343
* iterable are key-value pairs, and can themselves be any iterable object.
4444
* @param it An iterable object whose elements are key-value pairs
4545
*/
46-
def this(it: Iterator[_]) = this()
46+
def this(it: js.Iterable[js.Tuple2[String, String]]) = this()
4747

4848
/////////////////////////////////////////////////////////////////////////////////
4949
// Methods
@@ -67,7 +67,7 @@ class URLSearchParams extends js.Object {
6767
* a JavaScript Array. The first item of the Array is the name, the second item of the Array is the value.
6868
* @return an iterable of an array of results
6969
*/
70-
def entries(): Iterable[js.Array[String]] = js.native
70+
def entries(): js.Iterator[js.Tuple2[String, String]] = js.native
7171

7272
/**
7373
* Iterates over each name-value pair in the query and invokes the given function.
@@ -98,9 +98,9 @@ class URLSearchParams extends js.Object {
9898

9999
/**
100100
* Returns an ES6 Iterator over the names of each name-value pair.
101-
* @return an [[Iterable Iterator]] over the names of each name-value pair.
101+
* @return an [[js.Iterator Iterator]] over the names of each name-value pair.
102102
*/
103-
def keys(): Iterable[String] = js.native
103+
def keys(): js.Iterator[String] = js.native
104104

105105
/**
106106
* Sets the value in the URLSearchParams object associated with name to value. If there are any pre-existing
@@ -119,44 +119,8 @@ class URLSearchParams extends js.Object {
119119

120120
/**
121121
* Returns an ES6 Iterator over the values of each name-value pair.
122-
* @return an [[Iterable Iterator]] over the values of each name-value pair.
122+
* @return an [[js.Iterator Iterator]] over the values of each name-value pair.
123123
*/
124-
def values(): Iterable[String] = js.native
125-
126-
/**
127-
* Returns the Punycode ASCII serialization of the domain. If domain is an invalid domain, the empty string is returned.
128-
* @param domain the domain
129-
* @return the Punycode ASCII serialization of the domain
130-
*/
131-
def domainToASCII(domain: String): String = js.native
132-
133-
/**
134-
* Returns the Unicode serialization of the domain. If domain is an invalid domain, the empty string is returned.
135-
* @param domain the domain
136-
* @return the Unicode serialization of the domain
137-
*/
138-
def domainToUnicode(domain: String): String = js.native
139-
140-
/**
141-
* Returns a customizable serialization of a URL String representation of a WHATWG URL object.
142-
* @param url the given [[URL]]
143-
* @param options the given [[UrlFormatOptions options]]
144-
* @return a customizable serialization of a URL String representation of a WHATWG URL object.
145-
*/
146-
def format(url: URL, options: UrlFormatOptions = js.native): String = js.native
124+
def values(): js.Iterator[String] = js.native
147125

148126
}
149-
150-
/**
151-
* URL Format Options
152-
* @param auth true if the serialized URL string should include the username and password, false otherwise. Defaults to true.
153-
* @param fragment true if the serialized URL string should include the fragment, false otherwise. Defaults to true.
154-
* @param search true if the serialized URL string should include the search query, false otherwise. Defaults to true.
155-
* @param unicode true if Unicode characters appearing in the host component of the URL string should be encoded
156-
* directly as opposed to being Punycode encoded. Defaults to false.
157-
*/
158-
class UrlFormatOptions(val auth: js.UndefOr[Boolean] = js.undefined,
159-
val fragment: js.UndefOr[Boolean] = js.undefined,
160-
val search: js.UndefOr[Boolean] = js.undefined,
161-
val unicode: js.UndefOr[Boolean] = js.undefined)
162-
extends js.Object
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.scalajs.nodejs.url
2+
3+
import scala.scalajs.js
4+
5+
/**
6+
* URL Format Options
7+
*
8+
* @param auth true if the serialized URL string should include the username and password, false otherwise. Defaults to true.
9+
* @param fragment true if the serialized URL string should include the fragment, false otherwise. Defaults to true.
10+
* @param search true if the serialized URL string should include the search query, false otherwise. Defaults to true.
11+
* @param unicode true if Unicode characters appearing in the host component of the URL string should be encoded
12+
* directly as opposed to being Punycode encoded. Defaults to false.
13+
*/
14+
class UrlFormatOptions(val auth: js.UndefOr[Boolean] = js.undefined,
15+
val fragment: js.UndefOr[Boolean] = js.undefined,
16+
val search: js.UndefOr[Boolean] = js.undefined,
17+
val unicode: js.UndefOr[Boolean] = js.undefined)
18+
extends js.Object

app/current/src/main/scala/io/scalajs/nodejs/url/package.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import scala.scalajs.js.|
1010
*/
1111
package object url {
1212

13+
@deprecated("", "")
1314
type Iterable[A] = js.Array[A] | Iterator[A]
1415

1516
}

0 commit comments

Comments
 (0)