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

url-parse-utility

v1.1.0

Published

A simple RegEx based utility for parsing each part of the URL. This would help to get the different constituents of the URL.

Downloads

25

Readme

Url-Parser

A simple solution for parsing complex URL's. This utility is based on the native url module exposed by node js. This is made while keeping Node in mind so as to provide an easy access to URL constituents anyone who uses it. There are utility functions in this module that is handy while using it along with other node modules.

Installation

It's pretty easy to install. Just type the following in order to get this as a dependency.

$ npm install url-parser -D

After this you can import this in any project and create a new instance & pass the URL as the parameter that you would like to parse. This can be done as follows:-

var URL = require('url-parser');
var urlObj = new URL(YOUR_URL);
//After this step you can use the urlObj and call the functions that you want. The list is mentioned below

API

This utility has multiple function exposing each part of the URL. Namely this can constitute of the following parts:-

  1. Protocol
  2. Slashes
  3. Auth
  4. Host
  5. Port
  6. Hostname
  7. Hash
  8. Search
  9. Query
  10. Pathname
  11. Path
  12. Href

getProtocol()

Gives you the protocol of the URL that is passes as the argument in the constructor for example:-

//This will return http: or https:
urlObj.getProtocol();

getSlashes()

Tells you whether the URL ends with a trailing slash or not

/*This will give you a boolean variable true/false letting you know whether there is a trailing slash or not*/
urlObj.getSlashes();

getAuth()

This tells whether the URL carries Auth or not. If not the value will be null

urlObj.getAuth();

getHost()

Gives you the host from the URL. This would represent the Host along with the port if available.

urlObj.getHost();

getPort()

Gets the port Number. If there is no port number it would be null or undefined. You can consider it to be 80 in such cases. If the protocol is https or if the site is SSL enabled then you can consider it as 443

urlObj.getPort();

getHostname()

This will give you just the domain name from the URL.

urlObj.getHostname();

getSearch()

Gets you query parameters along with the ? symbol.

urlObj.getSearch();

getQuery()

Gets you the query parameters only without the ? symbol.

urlObj.gerQuery();

getPathname()

Gets the context path from the URL.

urlObj.getPathname();

getPath()

Gets the entire path along with the context path excluding the hostname.

urlObj.getPath()

getHref()

Returns the full URL that is being queried for or the URL that is being passed as the parameter to the constructor.

urlObj.getHref()

License

MIT License

Copyright (c) 2016 Shiv Kumar Ganesh