{"id":1603,"date":"2023-04-02T22:31:06","date_gmt":"2023-04-02T13:31:06","guid":{"rendered":"http:\/\/attacktube.com\/?p=1603"},"modified":"2023-06-03T20:12:55","modified_gmt":"2023-06-03T11:12:55","slug":"%e3%80%90javascript%e3%80%91url%e3%81%ae%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/attacktube.com\/?p=1603","title":{"rendered":"\u3010JavaScript\u3011URL\u306e\u89e3\u6790"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u30d6\u30e9\u30a6\u30b6\u3067\u306eURL\u306e\u89e3\u6790\u65b9\u6cd5\u306fNode.js\u306e\u300cWHATWG URL\u300d\u3068\u540c\u3058\u3067\u3042\u308b\u3002<br>\u3053\u306eURL\u3092\u89e3\u6790\u3059\u308b\u30b3\u30fc\u30c9\u3092Node.js v18.15.0\u3067\u52d5\u304b\u3059\u3068\u30d6\u30e9\u30a6\u30b6\u3068\u540c\u3058\u7d50\u679c\u306b\u306a\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u305f\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<br>\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-3461056110605997\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3461056110605997\" data-ad-slot=\"3137443461\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<br>\n\n\n\n<pre><code>\n\nconst url = &#039;https:\/\/user:pass@sub.example.com:8080\/p\/a\/t\/h?query=100&amp;a=9#hash&#039;;\nconst myURL = new URL(url);\nconst whitespace = 2;\nconst result = [];\nconst names = [];\n\nlet stringLengthMax = 0;\nlet buf = &#039; &#039;;\nlet blanks = &#039;&#039;;\n\nconsole.log(&quot;\u30d6\u30e9\u30a6\u30b6\u3067\u306eURL\u306e\u89e3\u6790\u65b9\u6cd5\u306fNode.js\u306e\u300cWHATWG URL\u300d\u3068\u540c\u3058\u3067\u3042\u308b\u3002&quot;);\nconsole.log(&quot;\u3053\u306eURL\u3092\u89e3\u6790\u3059\u308b\u30b3\u30fc\u30c9\u3092Node.js v18.15.0\u3067\u52d5\u304b\u3059\u3068\u30d6\u30e9\u30a6\u30b6\u3068\u540c\u3058\u7d50\u679c\u306b\u306a\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u305f\u3002&quot;);\nconsole.log(&quot;&quot;);\nconsole.log(myURL);\nresult.push(url);\nresult.push(myURL.href);\nresult.push(myURL.origin);\nresult.push(myURL.protocol);\nresult.push(myURL.username);\nresult.push(myURL.password);\nresult.push(myURL.host);\nresult.push(myURL.port);\nresult.push(myURL.hostname);\nresult.push(myURL.pathname);\nresult.push(myURL.hash);\nresult.push(myURL.search);\n\nnames.push(&quot;url&quot;);\nnames.push(&quot;href&quot;);\nnames.push(&quot;origin&quot;);\nnames.push(&quot;protocol&quot;);\nnames.push(&quot;username&quot;);\nnames.push(&quot;password&quot;);\nnames.push(&quot;host&quot;);\nnames.push(&quot;port&quot;);\nnames.push(&quot;hostname&quot;);\nnames.push(&quot;pathname&quot;);\nnames.push(&quot;hash&quot;);\nnames.push(&quot;search&quot;);\n\n\/\/names\u914d\u5217\u306e\u4e2d\u306e\u6587\u5b57\u5217\u3067\u6700\u5927\u9577\u3092stringLengthMax\u306b\u683c\u7d0d\u3059\u308b\u3002\nnames.forEach(t =&gt; {if(t.length &gt; stringLengthMax) stringLengthMax = t.length;});\n\n\/\/buf\u306b\u683c\u7d0d\u3057\u305f\u6587\u5b57\u5217\u3092\u300cstringLengthMax + whitespace\u300d\u56de\u6570\u5206\u306e\u30b3\u30d4\u30fc\u3092\u542b\u3080\u65b0\u3057\u3044\u6587\u5b57\u5217\u3092\u4f5c\u308b\u3002\nblanks = buf.repeat(stringLengthMax + whitespace);\n\n\/\/URL\u306e\u89e3\u6790\u7d50\u679c\u3092\u51fa\u3059\u3002\nnames.forEach((t, u) =&gt; (console.log(t + &#039;:&#039; + blanks.slice(t.length) + result[u])));\n\nconsole.log(&quot;&quot;);\n\nconsole.log(&quot;URLSearchParams\u306b\u542b\u307e\u308c\u308b\u5024\u306fforEach()\u30e1\u30bd\u30c3\u30c9\u3067\u53d6\u308a\u51fa\u3057\u53ef\u80fd\u3067\u3042\u308b\u3002&quot;);\nmyURL.searchParams.forEach(function(value, key) {\n  console.log(key + &quot; = &quot; + value);\n});\n\n\/*\n\n\u30d6\u30e9\u30a6\u30b6\u3067\u306eURL\u306e\u89e3\u6790\u65b9\u6cd5\u306fNode.js\u306e\u300cWHATWG URL\u300d\u3068\u540c\u3058\u3067\u3042\u308b\u3002\n\u3053\u306eURL\u3092\u89e3\u6790\u3059\u308b\u30b3\u30fc\u30c9\u3092Node.js v18.15.0\u3067\u52d5\u304b\u3059\u3068\u30d6\u30e9\u30a6\u30b6\u3068\u540c\u3058\u7d50\u679c\u306b\u306a\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u305f\u3002\n\nURL { \nhref: &quot;https:\/\/user:pass@sub.example.com:8080\/p\/a\/t\/h?query=100&amp;a=9#hash&quot;, \norigin: &quot;https:\/\/sub.example.com:8080&quot;, \nprotocol: &quot;https:&quot;, \nusername: &quot;user&quot;, \npassword: &quot;pass&quot;, \nhost: &quot;sub.example.com:8080&quot;, \nhostname: &quot;sub.example.com&quot;, \nport: &quot;8080&quot;, \npathname: &quot;\/p\/a\/t\/h&quot;, \nsearch: &quot;?query=100&amp;a=9&quot; \n}\n\u200bhash: &quot;#hash&quot;\nhost: &quot;sub.example.com:8080&quot;\nhostname: &quot;sub.example.com&quot;\nhref: &quot;https:\/\/user:pass@sub.example.com:8080\/p\/a\/t\/h?query=100&amp;a=9#hash&quot;\norigin: &quot;https:\/\/sub.example.com:8080&quot;\npassword: &quot;pass&quot;\npathname: &quot;\/p\/a\/t\/h&quot;\nport: &quot;8080&quot;\nprotocol: &quot;https:&quot;\nsearch: &quot;?query=100&amp;a=9&quot;\nsearchParams: URLSearchParams { query \u2192 &quot;100&quot;, a \u2192 &quot;9&quot; }\nusername: &quot;user&quot;\n\nurl:       https:\/\/user:pass@sub.example.com:8080\/p\/a\/t\/h?query=100&amp;a=9#hash\nhref:      https:\/\/user:pass@sub.example.com:8080\/p\/a\/t\/h?query=100&amp;a=9#hash\norigin:    https:\/\/sub.example.com:8080\nprotocol:  https:\nusername:  user\npassword:  pass\nhost:      sub.example.com:8080\nport:      8080\nhostname:  sub.example.com\npathname:  \/p\/a\/t\/h\nhash:      #hash\nsearch:    ?query=100&amp;a=9\n\nURLSearchParams\u306b\u542b\u307e\u308c\u308b\u5024\u306fforEach()\u30e1\u30bd\u30c3\u30c9\u3067\u53d6\u308a\u51fa\u3057\u53ef\u80fd\u3067\u3042\u308b\u3002\nquery = 100\na = 9\n\n*\/\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u95a2\u9023\u8a18\u4e8b<br><a href=\"http:\/\/attacktube.com\/?p=1595\">\u3010Node.js\u3011URL\u306e\u89e3\u6790(\u300cWHATWG URL\u300d\u3068\u300cLegacy URL\u300d)\u30102023\u5e74\u3011 (attacktube.com)<\/a><br><br>\u53c2\u8003<br><a href=\"https:\/\/nodejs.org\/dist\/latest-v18.x\/docs\/api\/url.html#url-strings-and-url-objects\">URL | Node.js v18.15.0 Documentation (nodejs.org)<\/a> ExternalLink<\/p>\n\n\n\n<script type=\"text\/javascript\">\njQuery(function($){\n$(\".jp-video\").hide();\n});\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>\u30d6\u30e9\u30a6\u30b6\u3067\u306eURL\u306e\u89e3\u6790\u65b9\u6cd5\u306fNode.js\u306e\u300cWHATWG URL\u300d\u3068\u540c\u3058\u3067\u3042\u308b\u3002\u3053\u306eURL\u3092\u89e3\u6790\u3059\u308b\u30b3\u30fc\u30c9\u3092Node.js v18.15.0\u3067\u52d5\u304b\u3059\u3068\u30d6\u30e9\u30a6\u30b6\u3068\u540c\u3058\u7d50\u679c\u306b\u306a\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1603","post","type-post","status-publish","format-standard","hentry","category-javascript"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/1603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1603"}],"version-history":[{"count":8,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/1603\/revisions"}],"predecessor-version":[{"id":2757,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/1603\/revisions\/2757"}],"wp:attachment":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}