Browse Source

[js] Add the `canParse()` and `parse()` static methods to `URL` (#11802)

* [js] Add the `canParse()` and `parse()` static methods to `URL`

* Fix the previous commit
Cédric Belin 10 months ago
parent
commit
912550d604
1 changed files with 25 additions and 3 deletions
  1. 25 3
      std/js/html/URL.hx

+ 25 - 3
std/js/html/URL.hx

@@ -24,6 +24,8 @@
 
 package js.html;
 
+import haxe.extern.EitherType;
+
 /**
 	The URL interface represents an object providing static methods used for creating object URLs.
 
@@ -36,9 +38,20 @@ extern class URL {
 	/** @throws DOMError */
 	@:overload( function( blob : Blob ) : String {} )
 	static function createObjectURL( source : MediaSource ) : String;
+
 	/** @throws DOMError */
 	static function revokeObjectURL( url : String ) : Void;
-	
+
+	/**
+		Returns a boolean indicating whether or not an absolute URL, or a relative URL combined with a base URL, are parsable and valid.
+	**/
+	static function canParse( url : String, ?base : EitherType<String, URL> ) : Bool;
+
+	/**
+		Returns a newly created `URL` object representing the URL defined by the parameters.
+	**/
+	static function parse( url : String, ?base : EitherType<String, URL> ): Null<URL>;
+
 	/**
 		Is a `DOMString` containing the whole URL.
 	**/
@@ -100,6 +113,15 @@ extern class URL {
 	var hash : String;
 	
 	/** @throws DOMError */
-	function new( url : String, ?base : String ) : Void;
+	function new( url : String, ?base : EitherType<String, URL> );
+
+	/**
+		Returns a JSON representation of this URL.
+	**/
 	function toJSON() : String;
-}
+
+	/**
+		Returns a string representation of this URL.
+	**/
+	function toString() : String;
+}