@cliqz/url-parser

中文文档
1.1.5发布于 2023/07/18MPL-2.0TypeScriptESM + CJS近 30 天下载 4924

A Fast URL parser implementation

此软件包已被标记为弃用

This project has been renamed to @ghostery/url-parser. Install using @ghostery/url-parser instead

原始使用文档
文档目录4 节
  1. Install
  2. Usage
  3. Performance
  4. License

Cliqz Url Parser

A Fast implementation of url parsing, mostly API-compatible with the standard URL class while being on average 2-3 times faster. Evaluation of URL components is lazy, so this implementation should be fast for all read use-cases.

Known differences to standard URL:

  • Parameters returned via URL.searchParams.entries() are decoded only with decodeURIComponent. This differs to standards parsing in some subtle ways.
  • You can iterate a URL parameters array directly via URL.searchParams.params. This is around 20% faster than using an iterator.
  • Parameter strings (; sepearated key/value pairs) are parsed, and accessible via URL.parameters.
  • Domain parsing with tldts is built in. The URL.domainInfo attribute returns output from tldts' parseHost method.
  • Hostname validation is not done on initial parse. The isValidHost() method is provided for this purpose.
  • All URLs with a valid authority are given an origin, regardless of the protocol scheme. This differs from the standard that only does so for a set of known schemes.

Install

npm install @cliqz/url-parser

Usage

const parsed = new URL('https://www.example.com');
parsed.hostname // == 'www.example.com'

Performance

We benchmark against a list of 250,000 URLs collected from popular sites, as previously used in our adblocker benchmark. We compare two use-cases:

  1. URL object creation: new URL(url)
  2. Query string parsing: new URL(url).searchParams.entries()

We compare to a reference implementation on each platform:

  • Node: URL class from the url library
  • Firefox: window.URL
  • Chrome: window.URL
  • Safari: window.URL
EnvironmentUse caseReference: urls/sCliqz parser: urls/sSpeedup
Node 11new URL()149,5141,577,71110.5x faster
Node 11searchParams140,544198,3401.4x faster
Firefox 69new URL()268,0661,043,8773.9x faster
Firefox 69searchParams119,207354,7933.0x faster
Chrome 75new URL()366,2941,721,9034.7x faster
Chrome 75searchParams144,309283,9562.0x faster
Safari 12new URL()656,9301,525,0782.3x faster
Safari 12searchParams264,481437,7381.7x faster

All benchmarks were run on a Mid 2015 Macbook Pro, 2.5 GHz Intel Core i7, 16GB.

License

Mozilla Public License 2.0

版本与发布记录

@cliqz/url-parser 共发布 407 个版本,首次发布于 2019/07/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.5latest2023/07/183 年前
1.1.5--canary.534.1e47aa70698f5db47e1a6d83785d1f81e3fbc972.0canary2021/03/125 年前
1.1.5--canary.533.b1788b51cfc219fb7e28d117caba69ac10b69666.02021/03/115 年前
1.1.5--canary.532.66af33a92613440398a8aa1119588d185f099b63.02021/03/105 年前
1.1.5--canary.531.01f237bdde0527de60748559210110f8104c6570.02021/03/105 年前
1.1.5--canary.530.1d6a353fea6a5e8f6fced3340c6ee943cfbc2b31.02021/03/105 年前

关于 @cliqz/url-parser 的常见问题

@cliqz/url-parser 是什么?

A Fast URL parser implementation注意:该包已被作者标记为弃用——This project has been renamed to @ghostery/url-parser. Install using @ghostery/url-parser instead

如何安装 @cliqz/url-parser?

在项目目录运行 npm install @cliqz/url-parser,或使用 pnpm add / yarn add / bun add。

@cliqz/url-parser 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cliqz/url-parser 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cliqz/url-parser 可以商用吗?

@cliqz/url-parser 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@cliqz/url-parser 的下载量有多少?

根据 npm 官方下载统计,@cliqz/url-parser 在 2026/10/10 – 2026/11/08 这 30 天内被下载 4,924 次,日均约 164 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cliqz/url-parser 还在维护吗?

最新版本 1.1.5 发布于 2023/07/18(3 年前);至今共发布 407 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/07/02。作者已将其标记为弃用,新项目建议寻找替代方案。