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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ghostery/url-parser

v1.1.6

Published

A Fast URL parser implementation

Downloads

13

Readme

Ghostery 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 @ghostery/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

| Environment | Use case | Reference: urls/s | Ghostery parser: urls/s | Speedup | | --- | --- | --: | --: | --- | | Node 11 | new URL() | 149,514 | 1,577,711 | 10.5x faster | Node 11 | searchParams | 140,544 | 198,340 | 1.4x faster | Firefox 69 | new URL() | 268,066 | 1,043,877 | 3.9x faster | Firefox 69 | searchParams | 119,207 | 354,793 | 3.0x faster | Chrome 75 | new URL() | 366,294 | 1,721,903 | 4.7x faster | Chrome 75 | searchParams | 144,309 | 283,956 | 2.0x faster | Safari 12 | new URL() | 656,930 | 1,525,078 | 2.3x faster | Safari 12 | searchParams | 264,481 | 437,738 | 1.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