快速了解
完整资料
资料已展开关于 URI.js
URI.js是一个处理url的javascript库。它提供了一个“jquery风格”的API(连贯接口、方法链接)来读写所有常规组件和许多方便的方法,并且提供了简单而强大的方法来处理查询字符串,它有许多uri标准化函数和转换相对/绝对路径。使用URI.js不需要jQuery
栗子
js
复制代码
// mutating URLs
URI("http://example.org/foo.html?hello=world")
.username("rodneyrehm")
// -> http://rodneyrehm@example.org/foo.html?hello=world
.username("")
// -> http://example.org/foo.html?hello=world
.directory("bar")
// -> http://example.org/bar/foo.html?hello=world
.suffix("xml")
// -> http://example.org/bar/foo.xml?hello=world
.hash("hackernews")
// -> http://example.org/bar/foo.xml?hello=world#hackernews
.fragment("")
// -> http://example.org/bar/foo.xml?hello=world
.search("") // alias of .query()
// -> http://example.org/bar/foo.xml
.tld("com")
// -> http://example.com/bar/foo.xml
.search({ foo: "bar", hello: ["world", "mars"] });
// -> http://example.com/bar/foo.xml?foo=bar&hello=world&hello=mars
查询参数字符串
js
复制代码
URI("?hello=world")
.addSearch("hello", "mars")
// -> ?hello=world&hello=mars
.addSearch({ foo: ["bar", "baz"] })
// -> ?hello=world&hello=mars&foo=bar&foo=baz
.removeSearch("hello", "mars")
// -> ?hello=world&foo=bar&foo=baz
.removeSearch("foo")
// -> ?hello=world
查询路劲
js
复制代码
URI("/relative/path")
.relativeTo("/relative/sub/foo/sub/file")
// -> ../../../path
.absoluteTo("/relative/sub/foo/sub/file");
// -> /relative/path
url模板
js
复制代码
URI.expand("/foo/{dir}/{file}", {
dir: "bar",
file: "world.html"
});
// -> /foo/bar/world.html
适合的使用方向
栗子
URI.js是一个处理url的javascript库
查询参数字符串
它提供了一个“jquery风格”的API(连贯接口、方法链接)来读写所有常规组件和许多方便的方法,并且提供了简单而强大的方法来处理查询字符串,它有许多uri标准化函数和转换相对/绝对路径
查询路劲
使用URI.js不需要jQuery
收录线索
链接截取Http链接处理API / 云服务
资料说明
内容根据公开资料整理;版本、兼容性与服务状态请以官网最新说明为准。
