npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

url-plus

v1.0.0

Published

url-plus ========

Readme

url-plus

url 辅助工具,可以组合带参数、hash的 url,还可以返回 url 的相关信息

同时支持浏览器客户端和node.js

安装

直接下载,或通过 npm 安装

npm install url-plus --save

引用

AMD/CMD 或 CommonJs(Node)

var urlplus = require('url-plus');

浏览器端引用

	<script src="./url-plus/index.js></script>
	<script>
	urlplus.normalize(...);
	</script>

方法

normalize(url)

规范化字符串路径,解释'//'、'../' 和 `'./' 部分

  • 多个斜杠会被替换成一个;
  • 路径末尾的斜杠会被保留;
  • ../ 会被解释成上级目录
  • ./ 会被解释成同级目录
urlplus.normalize('http://www.domain.com/foo/bar//baz/asdf/quux/..');
// returns
'http://www.domain.com/foo/bar/baz/asdf/'

resolve(from, ...to)

把 to 解析为一个以 http、https 或 / 开头的绝对 url,返回的结果会被规范化。

urlplus.resolve('http://www.domain.com/a/', 'foo/bar', '..', 'a/../subfile');
// returns
'http://www.domain.com/a/foo/subfile'

注意,如果 to 中某个参数以 / 开头,该参数将会变成根路径。

下面示例的 /root/file/ 会把前面的 /a/ 和 /foo/bar 替代:

urlplus.resolve('http://www.domain.com/a/, 'foo/bar', '/root/file/', '..', 'a/../subfile');
// returns
'http://www.domain.com/root/subfile'

对于参数,可以使用 ? 表示,如:

urlplus.resolve('http://www.domain.com/', 'a', 'b/c.html', '?d=e&f');
// returns
'http://www.domain.com/a/b/c.html?d=e&f'
urlplus.resolve('http://www.domain.com/a/b/c.html?d=e&f#g', '?d=h');
// returns
'http://www.domain.com/a/b/c.html?d=h&f#g'

若需要清空原 url 中的所有参数,请使用强制替换规则:?!&,如:

urlplus.resolve('http://www.domain.com/a/b/c.html?d=e&f#g', '?!&g=h');
// returns
'http://www.domain.com/a/b/c.html?g=h#g'

root(url)

返回 url 的根

urlplus.root('http://www.domain.com/a/b/c.html?d=e&f#g');
// returns
'http://www.domain.com/'

domain(url)

返回 url 的域名部分

urlplus.domain('http://www.domain.com/a/b/c.html?d=e&f#g');
// returns
'www.domain.com'

pathname(url)

返回 url 中的 pathname 部分

urlplus.pathname('http://www.domain.com/a/b/c.html?d=e&f#g');
// returns
a/b/c.html

query(url)

返回 url 的参数部分。

urlplus.query('http://www.domain.com/a/b/c.html?d=e&f#g');
// returns
{
  d: 'e',
  f: null
}

queryString(url)

返回 url 的参数拼接的字符串。

urlplus.queryString('http://www.domain.com/a/b/c.html?d=e&f#g');
// returns
'd=e&f'

hash(url)

返回 url 的 hash 部分

urlplus.hash('http://www.domain.com/a/b/c.html?d=e&f#g');
// returns
'g'

extname(url)

返回 url 中文件的扩展名, 在从最后一部分中的最后一个'.'到字符串的末尾。

如果在 pathname 的最后一部分没有'.',就返回一个空字符串。

urlplus.extname('http://www.domain.com/a/b/c.html?d=e&f#g');
// returns
'.html'

isAbsolute(url)

判定 url 是否为绝对路径。

一个绝对路径总是以 http、https 或 / 开头。

urlplus.isAbsolute('http://www.domain.com/a/');
// returns
true
urlplus.isAbsolute('./a/');
// returns
false

License

MIT