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

js-url

v2.3.0

Published

A simple, lightweight url parser for JavaScript (~1.7 Kb minified, ~0.7Kb gzipped).

Downloads

6,278

Readme

url()

A simple, lightweight url parser for JavaScript (~1.7 Kb minified, ~0.7Kb gzipped).

Also available for Node.js.

Bower Install

> bower install js-url

Notes

For path(1) and path(-1) will always act as if the path is in the form /some/path/ regardless of whether the original path was /some/path or some/path/.

Tld

There are two versions, url.min.js and url-tld.min.jd. The tld version contains a list of valid tld's making the file about 2kb larger. If you don't need support for it just use domain parts arguments (url('-1')) to get the tld pieces you need.

Examples

http://rob:[email protected]/path/index.html?query1=test&silly=willy&field[0]=zero&field[2]=two#test=hash&chucky=cheese
url();            // http://rob:[email protected]/path/index.html?query1=test&silly=willy&field[0]=zero&field[2]=two#test=hash&chucky=cheese
url('tld');       // co.uk
url('domain');    // example.co.uk
url('hostname');  // www.example.co.uk
url('sub');       // www
url('.0')         // undefined
url('.1')         // www
url('.2')         // example
url('.-1')        // uk
url('auth')       // rob:abcd1234
url('user')       // rob
url('pass')       // abcd1234
url('port');      // 80
url('protocol');  // http
url('path');      // /path/index.html
url('file');      // index.html
url('filename');  // index
url('fileext');   // html
url('1');         // path
url('2');         // index.html
url('3');         // undefined
url('-1');        // index.html
url(1);           // path
url(2);           // index.html
url(-1);          // index.html
url('query');     // query1=test&silly=willy
url('?');         // {query1: 'test', silly: 'willy', field: ['zero', undefined, 'two']}
url('?silly');    // willy
url('?poo');      // null
url('field[0]')   // zero
url('field')      // ['zero', undefined, 'two']
url('hash');      // test=hash&chucky=cheese
url('#');         // {test: 'hash', chucky: 'cheese'}
url('#chucky');   // cheese
url('#poo');      // undefined

Also supports mailto.

url('protocol', 'mailto:[email protected]'); // mailto
url('email', 'mailto:[email protected]');    // [email protected]

We can also pass a url in and use all the same options on it:

url('hostname', 'test.www.example.com/path/here');          // test.www.example.com
url('protocol', 'www.example.com/path/here');               // http
url('path', 'http://www.example.com:8080/some/path');       // /some/path
url('port', 'http://www.example.com:8080/some/path');       // 8080
url('protocol', 'https://www.example.com:8080/some/path');  // https
etc...

jQuery

Also include is a jQuery version of the plugin that can be called via $.url() with all the same options. If you're already using jQuery it may be better to use the jQuery version to avoid namespacing issues.

Grunt.js

If you want to use Grunt you will need to install the required plugins locally using npm install in the root folder of your project. If you need to setup Grunt on your system you can follow my Setting up Grunt.js guide.

Resources

License

MIT licensed

Copyright (C) 2011-2012 Websanova http://www.websanova.com