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

urlparamify

v1.1.5

Published

Simply parse urls, no matter how stupid it looks. Focuses on coverage rather than features

Downloads

35

Readme

urlparamify

Parse all kinds of urls, simple or otherwise. Returns a modifiable JSON object that can be converted to a string.

NPM

Build Status Coverage Status

The why

Primary goal: Keep urls modifiable, without worrying about anything else. Allow for modifying urls, and generating a neat url with accomodated changes.

Often you might be parsing urls, modifying some parameter using strings, and the whole system looks messy. urlparamify seeks to solve that problem. Just give it a string, which is converted into JSON modifiable form. Mess up any way you want to with the parameters, playing around with the params, and just call a Url.toString() to get your modified url.

Now you don't need to worry about google.com, http://google.com, /path?search=data, urlparamify has got you covered.

One of the legit feedbacks I received on reddit was how is this module any different from the core url module ?

Unlike the core url, urlparamify accepts any kind of url like mentioned above, whereas url works only when a url of the format http://google.com is provided. I started off working on a task with url itself, but the multiple fallacies in url (url.parse('http://google.com') for instance, along with multiple urls mentioned in this test suite) and other interactions suggested me to make a url suited to these requirements. An instance of this module's sturdiness can be seen in Usage and examples below.

Find a url that breaks this module ? Let me know.

Installation

$ npm install urlparamify

Structure

Each url is broken down into the following components:

  • href : The original input string
  • protocol : http / https request protocol
  • host : what website / localhost ip,port combination
  • baseurl : The base url of the url to be queried.
  • path : Path section of the URL
  • query : The query part of the url, unaltered
  • queryParams : A json object to modify/add to your query

Apart from this, each url object has the following functions:

  • getBaseurl(): Get the latest baseurl parameter
  • toString() : Convert our url object into a neatly formatted string.

Usage and examples

> var Url = require('urlparamify');
> var h = Url('http://google.com/path1?q=data&d=sad#hash');

> h
{ href: 'http://google.com/path1/?q=data&d=sad#hash',
protocol: 'http',
host: 'google.com',
baseurl: 'http://google.com',
path: 'path1',
query: 'q=data&d=sad',
queryParams: { q: 'data', d: 'sad' },
hash: 'hash',
getBaseurl: [Function],
toString: [Function] }

> h.toString();
'http://google.com/path1?q=data&d=sad#hash'

// let's put a smile on that face
> h.queryParams.d = 'happy';
> h.toString();
'http://google.com/path1?q=data&d=happy#hash'

// let's try adding new query parameters
> h.queryParams.new = 'wow';
> h.toString();
'http://google.com/path1?q=data&d=happy&new=wow#hash'

// I don't like hashtags. Get rid of it
> h.hash = "";
> h.toString();
'http://google.com/path1?q=data&d=sad&new=wow'

// But what if I want to add things that were never there to begin with ?
// With urlparamify, you can not only modify, but also add new parameters with ease
> var g = Url('google.com')
> g.toString()
'google.com'
> g.path = 'somepath'
> g.toString()
'google.com/somepath'
> g.queryParams.search = 'data'
> g.toString()
'google.com/somepath?search=data'

Tests

npm test
npm run cover
istanbul cover test/test.js // The results are stored in coverage/

The source files are in src, and the distribution files are in dist. Transpiled the code for ease.

A little reminder for myself: When ready to deploy, at a clean git history,

npm version patch -m "Version %s - add sweet badges"
major.minor.patch : 1.1.0

If you want to publish your own module, this article on Medium is a great place to start.

License

MIT © Kaustubh Hiware