Lea*_*ner 3 relative-path absolute-path relative-url node.js
我有这样的网址:
http://example.com/path/to/css/../../images/test.jpg
我想将其转换为绝对值,如下所示:
http://example.com/path/images/test.jpg
我正在寻找Nodejs中的模块来执行相同的操作。模块,路径执行相同的操作。但是(path.resolve)也带有目录路径。
我正在寻找类似的东西,但网址。
您可以使用URL模块。https://nodejs.org/docs/latest/api/url.html
const { URL } = require('url');
new URL('path/images/test.jpg', 'http://example.com/')
URL {
href: 'http://example.com/path/images/test.jpg',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/path/images/test.jpg',
search: '',
searchParams: URLSearchParams {},
hash: '' }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4565 次 |
| 最近记录: |