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

decompose-url

v0.1.2

Published

A quick and easy URL decomposer for breaking URLs into their constituent parts.

Downloads

18

Readme

decompose-url

NPM version Bower version Build Status Coverage Status

A quick and easy URL decomposer for breaking URLs into their constituent parts.

Install

NPM

$ npm install decompose-url

Bower

bower install --save decompose-url

Node.js

var decomposeUrl = require('decompose-url')

var decomposedUrl = decomposeUrl('http://test.example.com:8000/one/two/three?value=abc&value2=123#david-rules');
// `decomposedUrl` now contains the decomposed values from the url that was passed. See [Url](#url-model) for the structure.

var decomposedUrlWithParams = decomposeUrl('http://test.example.com:8000/one/two/three?value=abc&value2=123#david-rules', '/:value1/:value2/:value3');
// `decomposedUrlWithParams` now contains the decomposed values from the url that was passed and now decomposedUrlWithParams.params is populated with a map of the path parameters that were passed and their values. See [Url](#url-model) for the structure.

Browser

<script type="text/javascript" src="decompose-url.js"></script>
<script type="text/javascript">
var decomposedUrl = decomposeUrl('http://test.example.com:8000/one/two/three?value=abc&value2=123#david-rules');
// `decomposedUrl` now contains the decomposed values from the url that was passed. See [Url](#url-model) for the structure.

var decomposedUrlWithParams = decomposeUrl('http://test.example.com:8000/one/two/three?value=abc&value2=123#david-rules', '/:value1/:value2/:value3');
// `decomposedUrlWithParams` now contains the decomposed values from the url that was passed and now decomposedUrlWithParams.params is populated with a map of the path parameters that were passed and their values. See [Url](#url-model) for the structure.
</script>

Url Model

  • protocol - The protocol in the URL, null if none. (eg. 'http')
  • username - The username in the URL, null if none. (eg. 'david')
  • password - The password in the URL, null if none. (eg. 'l33t5auce#!')
  • hostname - The full hostname in the URL, null if none. (eg. 'mail.google.com')
  • host - An array of the domain names in the URL, null if none. (eg. ['mail', 'google'])
  • tld - The top level domain in the URL, null if none. (eg. 'com')
  • port - The port in the URL. Default: 80, if there is a host (eg. '80')
  • path - An array of the path parts in the URL, null if none. (eg. ['mail', 'u', '0'])
  • params - A map of the path parameters (only populated if a template was passed) in the URL, null if no template was passed. (eg. { 'user' : 0 })
  • search - The full search part in the URL, null if none. (eg. 'ui=1&pli=1')
  • query - A map of the query parameters in the URL, null if none. (eg. { 'ui': '1', 'pli': '1' })
  • hash - The full hash in the URL, null if none. (eg. 'inbox')
  • hash - The original URL that was decomposed (eg. 'http://david:l33t5auce#[email protected]/mail/u/0?ui=2&pli=1#inbox')

Benchmark

$ npm run-script bench
  
  > [email protected] bench decompose-url
  > node benchmark/index.js
  
  > node benchmark\absolute-url.js
  
    Parsing URL http://test.example.com:8000/one/two/three?value=abc&value2=123#david-rules
  
    1 test completed.
    2 tests completed.
    3 tests completed.
    4 tests completed.
  
    decomposeUrl  x 184,267 ops/sec ±0.35% (197 runs sampled)
    nativeUrl     x  33,648 ops/sec ±0.56% (192 runs sampled)
    parseUrl      x  50,891 ops/sec ±0.26% (196 runs sampled)
    fastUrlParser x 218,160 ops/sec ±0.23% (197 runs sampled)
  
  > node benchmark\document-relative-url.js
  
    Parsing URL one/two/three?value=abc&value2=123#david-rules
  
    1 test completed.
    2 tests completed.
    3 tests completed.
    4 tests completed.
  
    decomposeUrl  x 290,588 ops/sec ±0.14% (197 runs sampled)
    nativeUrl     x  52,087 ops/sec ±0.51% (195 runs sampled)
    parseUrl      x  93,881 ops/sec ±0.29% (196 runs sampled)
    fastUrlParser x 244,401 ops/sec ±0.17% (196 runs sampled)
  
  > node benchmark\full-url.js
  
    Parsing URL http://username:[email protected]:8000/one/two/three?value=abc&value2=123#david-rules
  
    1 test completed.
    2 tests completed.
    3 tests completed.
    4 tests completed.
  
    decomposeUrl  x 175,061 ops/sec ±0.18% (196 runs sampled)
    nativeUrl     x  31,373 ops/sec ±0.46% (195 runs sampled)
    parseUrl      x  40,676 ops/sec ±1.89% (194 runs sampled)
    fastUrlParser x 199,756 ops/sec ±0.24% (196 runs sampled)
  
  > node benchmark\protocol-relative-url.js
  
    Parsing URL //test.example.com/one/two/three?value=abc&value2=123#david-rules
  
    1 test completed.
    2 tests completed.
    3 tests completed.
    4 tests completed.
  
    decomposeUrl  x 195,416 ops/sec ±0.22% (194 runs sampled)
    nativeUrl     x  51,650 ops/sec ±0.91% (192 runs sampled)
    parseUrl      x  85,423 ops/sec ±0.30% (194 runs sampled)
    fastUrlParser x 227,996 ops/sec ±0.29% (197 runs sampled)
  
  > node benchmark\root-relative-url.js
  
    Parsing URL /one/two/three?value=abc&value2=123#david-rules
  
    1 test completed.
    2 tests completed.
    3 tests completed.
    4 tests completed.
  
    decomposeUrl  x 261,973 ops/sec ±1.30% (193 runs sampled)
    nativeUrl     x  48,762 ops/sec ±1.45% (184 runs sampled)
    parseUrl      x  82,902 ops/sec ±1.40% (190 runs sampled)
    fastUrlParser x 218,049 ops/sec ±1.56% (188 runs sampled)

License

MIT