【发布时间】:2012-11-10 00:12:15
【问题描述】:
我创建了一个可以像这样构建嵌套 url 的函数。我想知道是否存在一个更主流的库来构建这样的 urls / uris。我宁愿使用标准。
utility.urlConstruct({
"scheme": "https://",
"domain": "domain.com",
"path": "/login",
"query":{
"user":"thomasreggi",
"from":utility.urlConstruct({
"scheme": "https://",
"domain": "redirect.com",
"path": "/funstuff",
}),
}
});
吐出来
https://domain.com/login?user=thomasreggi&from=https%3A%2F%2Fredirect.com%2Ffunstuff
【问题讨论】:
-
我强烈建议您删除所有尾随逗号,因为有些浏览器讨厌它们,所以最后一个
},应该是} -
明白了,这是一个例子。无论如何我都不想使用上面的代码,我正在寻找替代方案。
-
在这里发布了我的模块github.com/reggi/schemejs
-
@ThomasReggi,感谢您分享您的 github 存储库。我发现 nodejs 有它自己的
url#parse方法。请参阅my answer to your other question 上的编辑 2
标签: javascript url uri