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

parseurl-fast

v1.2.0

Published

A fast url parser

Downloads

28

Readme

parseurl-fast

A fast url parser

NPM version Build Status

Parses an url with memoization using a single safe regex. Targets node only, so don't try to use in browser. Focuses on urls used at the server side.

Returns same parsing result as url.parse except:

  • Does not parse javascript URIs
  • Does not parse some schemes. Please check excludes in test/conformance.test.js

Usage

Install with

npm i -S parseurl-fast

Parse an Url with:

const parseurl = require('parseurl-fast')

const url = 'https://www.host.name:4000/path?query#hash'
const parsed = parseurl({url})
//> {
//>   protocol: 'https:',
//>   ...
//> }

Benchmarks

node v8.11.4

$ npm run benchmark

---- url ----

node url.parse   x 82,267 ops/sec ±1.70% (83 runs sampled)
parseurl         x 83,700 ops/sec ±1.10% (90 runs sampled)
parseurl-fast    x 231,092 ops/sec ±1.26% (91 runs sampled)
Fastest is parseurl-fast   

---- long url ~8000 chars ----

node url.parse   x 1,945 ops/sec ±0.49% (92 runs sampled)
parseurl         x 1,929 ops/sec ±0.34% (94 runs sampled)
parseurl-fast    x 10,051 ops/sec ±0.57% (90 runs sampled)
Fastest is parseurl-fast   

Security recommendations

This module can parse an infinite number of chars. To comply with RFC 7230 Section 3.1.1 which recommends a minimum of 8000 octets, you should limit the max. number of chars to such or even smaller extent (depends on your app). In such case respond with a 414 status code. The longer the urls the longer the parsing.

E.g. if using connect middlewares, do sth. like this:

const parseurl = require('parseurl-fast')

app.use((req, res, next) => {
  let err
  if (req.url.length <= 8000) {
    parseurl(req)
  } else {
    err = new Error('URI Too Long')
    err.status = 414
  }
  next(err)
})

This module uses Regular Expressions for parsing, which may be subject to ReDoS attacks. Anyhow those expressions implemented should not contain any nondeterministic/ harmful states. The redos tool, was used to trace irregularities during development - check with npm run redos.

License

MIT Licensed

References