You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@cliqz/url-parser

Package Overview
Dependencies
Maintainers
1
Versions
407
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cliqz/url-parser

A Fast URL parser implementation


Version published
Maintainers
1
Created

Readme

Source

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

FAQs

Package last updated on 18 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc