2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JavaScriptAdvent Calendar 2024

Day 23

相対パスを絶対パスに変換する

Last updated at Posted at 2024-12-22

この記事は『JavaScript Advent Calendar 2024』シリーズ1 23日目の記事です

タイトルのとおりです
稀によく需要が発生するので、簡潔な回答を示しておきます。

結論

そういうことができるURL.parse()というメソッドがあります

詳細

URL.parse()は以下のように引数を指定することができます。

URL.parse(url, base)

返り値はURLオブジェクトなので、URL:toString()とかを使って文字列に変換すればOK

URL.parse("./../d.txt", "https://example.com/a/b/c.txt").toString()
// Expected Eval Value : <string> "https://example.com/a/d.txt"

Q. それだけ?
A. それだけ

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?