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 🙏

© 2026 – Pkg Stats / Ryan Hefner

location-util

v1.2.0

Published

Utilities of location (URL) for browser and node. It has no dependencies

Downloads

9

Readme

location-util NPM version Build Status

Utilities of location (URL) for browser and node. It has no dependencies.

Synopsis

var l = new LocationUtil('http://example.com:3000/foo?bar=buz#frag');
l.protocol();    // => 'http'
l.host();        // => 'example.com'
l.port();        // => 3000
l.search();      // => {'bar': 'buz'}
l.paramString(); // => '?bar=buz'
l.hash();        // => 'frag'
l.path();        // => '/foo'
l.url();         // => '/foo?bar=buz#frag'
l.origin();      // => 'http://example.com:3000'

l.url('/user?id=123#name').absUrl();               // => 'http://example.com:3000/user?id=123#name'
l.path('/entry').absUrl();                         // => 'http://example.com:3000/entry?id=123#name'
l.search('date', '20140401', 'id', null).absUrl(); // => 'http://example.com:3000/entry?date=20140401#name'
l.hash('').absUrl();                               // => 'http://example.com:3000/entry?date=20140401'

Methods

  • new Locationutil(url)

Creates an instance. It takes url as string.

  • absUrl()

This method provides getter only.

It returns full URL.

  • protocol()

This method provides getter only.

It returns protocol (e.g. http). If protocol is empty, it returns blank string.

  • host()

This method provides getter only.

It returns the part of host.

  • port()

This method provides getter only.

It returns port number. If port number is empty, it returns null.

  • search([queries])

This method provides getter and setter.

If you use this method without any arguments, this method behave as getter. It returns the query as object (e.g. {'bar': 'buz'}). If query is empty, it returns blank object.

The another case, this method behave as setter. It changes query according to arguments and returns changed instance. If value of queries is null, the property specified via the first argument will be deleted.

var l = new LocationUtil('http://example.com?foo=bar');
l.search(); // => {'foo': 'bar'}
l.search('buz', 'qux');
l.search(); // => {'foo': 'bar', 'buz': 'qux'}
l.search('foo', null);
l.search(); // => {'buz': 'qux'}
  • paramString()

This method provides getter only.

This method returns query parameter string like a ?foo=bar&buz=qux. This method doesn't ensure the order of key-values.

var l = new LocationUtil('http://example.com?foo=bar');
l.paramString(); // => '?foo=bar'
l.search('buz', 'qux');
l.paramString(); // => '?foo=bar&buz=qux'
  • path(pathString)

This method provides getter and setter.

If you use this method without any arguments, this method behave as getter. It returns the part of path (e.g. /foo/bar). If path is empty, it returns '/'.

The another case, this method behave as setter. It changes path according to arguments and returns changed instance. Path should always begin with forward slash ('/'), this method will add the forward slash if it is missing.

var l = new LocationUtil('http://example.com/foo');
l.path(); // => '/foo'
l.path('/bar/buz');
l.path(); // => '/bar/buz'
  • hash(hashString)

This method provides getter and setter.

If you use this method without any arguments, this method behave as getter. It returns the part of hash fragment. If hash is empty, it returns blank string.

The another case, this method behave as setter. It changes hash fragment according to arguments and returns changed instance.

var l = new LocationUtil('http://example.com#foo');
l.hash(); // => 'foo'
l.hash('bar');
l.hash(); // => 'bar'
  • url(urlString)

This method provides getter and setter.

If you use this method without any arguments, this method behave as getter. It returns the URL (e.g. /foo?bar=buz#frag). If URL is empty, it returns blank string.

The another case, this method behave as setter. It changes URL according to arguments and returns changed instance. URL should always begin with forward slash ('/'), this method will add the forward slash if it is missing.

var l = new LocationUtil('http://example.com/foo?bar=buz#frag');
l.url(); // => '/foo?bar=buz#frag'
l.url('/user?id=123#name');
l.url(); // => '/user?id=123#name'
  • origin()

This method provides only getter.

This method returns a string like so <protocol>://<host>:<port>. If underlying URL doesn't have protocol or port, it will omit them from result.

var l = new LocationUtil('http://example.com:3000/foo?bar=buz#frag');
l.origin(); // => 'http://example.com:3000'

l = new LocationUtil('http://example.com/foo?bar=buz#frag');
l.origin(); // => 'http://example.com'

Author

moznion ([email protected])

License

MIT