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

arrgh.js

v0.0.1

Published

Painless dynamic function arguments

Readme

Arrgh.js - Painless dynamic function arguments

npm version build status browser testing

Do you know that pain?

Dynamic typing in JavaScript is great and the flexibility it provides to create API's is fantastic. However, without named parameters in ES5, and the rigid way JavaScript handles function arguments, it introduces a lot of code smell.

Look at this simple example:

function addDataAttribute(nodeList, attributeName, value) {
  // Type check on our dynamic argument... let's face it... ugly as hell
  if(typeof nodeList !== 'string' || 
      !Array.isArray(nodeList) || 
      !nodeList instanceof NodeList) {
    throw new Error('Invalid arguments!');
  }

  // Assuming nodeList is a query
  if(typeof nodeList === 'string') {
     nodeList = document.querySelectorAll(nodeList);
     // Query selectorAll with a parameter called nodeList? 
     // Hmmm... anyway let's continue
  }
  
  if(!Array.isArray(nodeList)) {
    // Trying to cast original node list or node list obtained from 
    // document (Arrgh! This is getting weird already) to array
    nodeList = Array.prototype.slice.call(nodeList);
  }
  
  // Okay let's not make it any more complicated...
  nodeList.forEach(function assignAttribute(node) {
    node.setAttribute('data-' + attributeName, value);
  });
}

Okay, we made the user of our function quite happy. He can pass a list of DOM nodes (node list or array) or a query string that will be used to query the document for DOM nodes matching the selector query. That's really the joy of dynamic typing in JavaScript. But look at the smelly code we've created to make this possible?

  • Type checking is nasty and usually handled with a bit condition and some exception being thrown
  • Arguments need to be converted and normalized depending on their type
  • The original name of the arguments have nothing to do with your code which is super confusing and a maintenance brain fuck
  • ES5 has no option for named arguments which would make things a lot easier
  • The way to handle variable argument lists in ES5 is simply ridiculous

Let's talk about Arrghuments!

coming soon...