Skip to content

Commit

Permalink
feat(webapi): Add 16 URL examples (#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedziolkaMichal authored Jul 22, 2023
1 parent 6dda47a commit 1d69481
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 0 deletions.
100 changes: 100 additions & 0 deletions live-examples/webapi-examples/url/meta.json
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"
}
}
}
7 changes: 7 additions & 0 deletions live-examples/webapi-examples/url/url-constructor.js
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"
3 changes: 3 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-hash.js
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"
7 changes: 7 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-host.js
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"
7 changes: 7 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-hostname.js
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"
3 changes: 3 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-href.js
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"
3 changes: 3 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-origin.js
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"
3 changes: 3 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-password.js
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"
3 changes: 3 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-pathname.js
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"
7 changes: 7 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-port.js
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"
3 changes: 3 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-protocol.js
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:"
3 changes: 3 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-search.js
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"
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"
3 changes: 3 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-tojson.js
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"
3 changes: 3 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-tostring.js
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"
3 changes: 3 additions & 0 deletions live-examples/webapi-examples/url/url-prototype-username.js
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"
12 changes: 12 additions & 0 deletions live-examples/webapi-examples/url/url.js
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"

0 comments on commit 1d69481

Please sign in to comment.