-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webapi): Add 16
URL
examples (#2367)
- Loading branch information
1 parent
6dda47a
commit 1d69481
Showing
17 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"pages": { | ||
"url": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url.js", | ||
"fileName": "url.html", | ||
"title": "Web API Demo: URL", | ||
"type": "js" | ||
}, | ||
"urlConstructor": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-constructor.js", | ||
"fileName": "url-constructor.html", | ||
"title": "Web API Demo: URL Constructor", | ||
"type": "js" | ||
}, | ||
"urlPrototypeHash": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-hash.js", | ||
"fileName": "url-prototype-hash.html", | ||
"title": "Web API Demo: URL.prototype.hash", | ||
"type": "js" | ||
}, | ||
"urlPrototypeHost": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-host.js", | ||
"fileName": "url-prototype-host.html", | ||
"title": "Web API Demo: URL.prototype.host", | ||
"type": "js" | ||
}, | ||
"urlPrototypeHostname": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-hostname.js", | ||
"fileName": "url-prototype-hostname.html", | ||
"title": "Web API Demo: URL.prototype.hostname", | ||
"type": "js" | ||
}, | ||
"urlPrototypeHref": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-href.js", | ||
"fileName": "url-prototype-href.html", | ||
"title": "Web API Demo: URL.prototype.href", | ||
"type": "js" | ||
}, | ||
"urlPrototypeOrigin": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-origin.js", | ||
"fileName": "url-prototype-origin.html", | ||
"title": "Web API Demo: URL.prototype.origin", | ||
"type": "js" | ||
}, | ||
"urlPrototypePassword": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-password.js", | ||
"fileName": "url-prototype-password.html", | ||
"title": "Web API Demo: URL.prototype.password", | ||
"type": "js" | ||
}, | ||
"urlPrototypePathname": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-pathname.js", | ||
"fileName": "url-prototype-pathname.html", | ||
"title": "Web API Demo: URL.prototype.pathname", | ||
"type": "js" | ||
}, | ||
"urlPrototypePort": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-port.js", | ||
"fileName": "url-prototype-port.html", | ||
"title": "Web API Demo: URL.prototype.port", | ||
"type": "js" | ||
}, | ||
"urlPrototypeProtocol": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-protocol.js", | ||
"fileName": "url-prototype-protocol.html", | ||
"title": "Web API Demo: URL.prototype.protocol", | ||
"type": "js" | ||
}, | ||
"urlPrototypeSearch": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-search.js", | ||
"fileName": "url-prototype-search.html", | ||
"title": "Web API Demo: URL.prototype.search", | ||
"type": "js" | ||
}, | ||
"urlPrototypeSearchParams": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-searchparams.js", | ||
"fileName": "url-prototype-searchparams.html", | ||
"title": "Web API Demo: URL.prototype.searchParams", | ||
"type": "js" | ||
}, | ||
"urlPrototypeToJSON": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-tojson.js", | ||
"fileName": "url-prototype-tojson.html", | ||
"title": "Web API Demo: URL.prototype.toJSON()", | ||
"type": "js" | ||
}, | ||
"urlPrototypeToString": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-tostring.js", | ||
"fileName": "url-prototype-tostring.html", | ||
"title": "Web API Demo: URL.prototype.toString()", | ||
"type": "js" | ||
}, | ||
"urlPrototypeUsername": { | ||
"exampleCode": "./live-examples/webapi-examples/url/url-prototype-username.js", | ||
"fileName": "url-prototype-username.html", | ||
"title": "Web API Demo: URL.prototype.username", | ||
"type": "js" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const url1 = new URL('https://en.wikipedia.org/wiki/Mozilla#Software'); | ||
console.log(url1.toString()); | ||
// expected output: "https://en.wikipedia.org/wiki/Mozilla#Software" | ||
|
||
const url2 = new URL('wiki/Mozilla#Software', 'https://en.wikipedia.org'); | ||
console.log(url2.toString()); | ||
// expected output: "https://en.wikipedia.org/wiki/Mozilla#Software" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const url = new URL('https://en.wikipedia.org:443/wiki/Mozilla#Software'); | ||
console.log(url.hash); | ||
// expected output: "#Software" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const url1 = new URL('https://en.wikipedia.org:443/wiki/Mozilla#Software'); | ||
console.log(url1.host); | ||
// expected output: "en.wikipedia.org" | ||
|
||
const url2 = new URL('https://en.wikipedia.org:8080/wiki/Mozilla#Software'); | ||
console.log(url2.host); | ||
// expected output: "en.wikipedia.org:8080" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const url1 = new URL('https://en.wikipedia.org:443/wiki/Mozilla#Software'); | ||
console.log(url1.hostname); | ||
// expected output: "en.wikipedia.org" | ||
|
||
const url2 = new URL('https://en.wikipedia.org:8080/wiki/Mozilla#Software'); | ||
console.log(url2.hostname); | ||
// expected output: "en.wikipedia.org" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const url = new URL('https://en.wikipedia.org:443/wiki/Mozilla#Software'); | ||
console.log(url.href); | ||
// expected output: "https://en.wikipedia.org/wiki/Mozilla#Software" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const url = new URL('https://en.wikipedia.org:443/wiki/Mozilla#Software'); | ||
console.log(url.origin); | ||
// expected output: "https://en.wikipedia.org" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const url = new URL('https://admin:test@en.wikipedia.org:443/wiki/Mozilla#Software'); | ||
console.log(url.password); | ||
// expected output: "test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const url = new URL('https://en.wikipedia.org:443/wiki/Mozilla#Software'); | ||
console.log(url.pathname); | ||
// expected output: "/wiki/Mozilla" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const url1 = new URL('https://en.wikipedia.org:443/wiki/Mozilla#Software'); | ||
console.log(url1.port); | ||
// expected output: "" | ||
|
||
const url2 = new URL('https://en.wikipedia.org:8080/wiki/Mozilla#Software'); | ||
console.log(url2.port); | ||
// expected output: "8080" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const url = new URL('https://en.wikipedia.org:443/wiki/Mozilla#Software'); | ||
console.log(url.protocol); | ||
// expected output: "https:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const url = new URL('https://en.wikipedia.org/w/index.php?title=Mozilla&action=edit'); | ||
console.log(url.search); | ||
// expected output: "?title=Mozilla&action=edit" |
6 changes: 6 additions & 0 deletions
6
live-examples/webapi-examples/url/url-prototype-searchparams.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const url = new URL('https://en.wikipedia.org/w/index.php?title=Mozilla&action=edit'); | ||
const params = url.searchParams; | ||
|
||
params.forEach((value, key) => console.log(`${key} - ${value}`)); | ||
// expected output: "title - Mozilla" | ||
// expected output: "action - edit" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const url = new URL('https://en.wikipedia.org:443/wiki/Mozilla#Software'); | ||
console.log(url.toJSON()); | ||
// expected output: "https://en.wikipedia.org/wiki/Mozilla#Software" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const url = new URL('https://en.wikipedia.org:443/wiki/Mozilla#Software'); | ||
console.log(url.toString()); | ||
// expected output: "https://en.wikipedia.org/wiki/Mozilla#Software" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const url = new URL('https://admin:test@en.wikipedia.org:443/wiki/Mozilla#Software'); | ||
console.log(url.username); | ||
// expected output: "admin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const url = new URL('https://en.wikipedia.org/wiki/Mozilla#Software'); | ||
console.log(url.protocol); | ||
// expected output: "https:" | ||
|
||
console.log(url.hostname); | ||
// expected output: "en.wikipedia.org" | ||
|
||
console.log(url.pathname); | ||
// expected output: "/wiki/Mozilla" | ||
|
||
console.log(url.hash); | ||
// expected output: "#Software" |