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 🙏

© 2026 – Pkg Stats / Ryan Hefner

url-split

v1.0.0

Published

A lightweight URL parsing utility that splits a URL into its components (protocol, host, path, query, hash).

Readme

url-split

一个轻量的 URL 解析工具库,将 URL 拆分为协议、主机、路径、查询参数与 hash 等组成部分。无第三方依赖。

安装

npm install url-split

使用

import { parseUrl, parseQuery } from 'url-split';
// 或 CommonJS: const { parseUrl, parseQuery } = require('url-split');

const result = parseUrl('https://example.com:8080/a/b?x=1&y=2#frag');
// {
//   protocol: 'https',
//   host: 'example.com:8080',
//   hostname: 'example.com',
//   port: '8080',
//   path: '/a/b',
//   query: { x: '1', y: '2' },
//   queryString: 'x=1&y=2',
//   hash: 'frag'
// }

parseQuery('a=1&a=2&b=3');
// { a: ['1', '2'], b: '3' }

API

parseUrl(url)

将 URL 字符串解析为各组成部分。优先使用内置 WHATWG URL,解析失败(如相对路径)时回退到正则拆分。

  • url {string} 待解析的 URL。
  • 返回 {Object},包含 protocol、host、hostname、port、path、query、queryString、hash 字段。
  • 当 url 不是字符串时抛出 TypeError。

parseQuery(queryString)

将查询字符串解析为对象。允许带前导 ?;重复 key 自动合并为数组;无值 key 的值为空字符串。

  • queryString {string} 形如 a=1&b=2 的字符串。
  • 返回 {Object<string, string|string[]>}。

开发与构建

源码为 TypeScript,位于 lib/,通过 webpack 打包为 UMD 产物(经 ts-loader 做类型检查,babel 转译 ES6)。

npm install          # 安装依赖
npm run dev          # 开发构建(watch,未压缩,输出 dist/url-split.js)
npm run build        # 生产构建(压缩,输出 dist/url-split.min.js + 类型声明)
npm run type-check   # 仅类型检查
npm test             # 先 build 再运行测试

目录结构:

  • lib/ — 源码,按功能拆分:query.ts(解析查询串) / split.ts(正则回退拆分) / url.ts(解析 URL) / index.ts(统一导出)
  • build/ — webpack 配置:webpack.base.config.js(共用) / webpack.dev.config.js(开发) / webpack.prod.config.js(生产)

License

ISC