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

kid-gloves

v0.0.9

Published

🌐 Kid Gloves

Downloads

158

Readme

kid-gloves

🌐 Kid Gloves

Program with a gentler touch.

Kid Gloves patches a bunch of JS quirks that potentially throw errors and turns those into warnings. This is intended to be used as a learning tool and for debugging purposes and not meant to monkey patch live production software.

Note: This only aims to patch errors where the alternative outcome is obvious and doesn't change the existing behavior. So while functions like JSON.parse commonly error, there is no way to determine an appropriate return value without drastically changing behavior. document.querySelector on the other hand, already has a value for when the query fails to match an element and this makes a good alternative to throwing an error.

Installation:

Stick this url in a script tag just above the code you want to debug https://unpkg.com/kid-gloves/kid-gloves.js like so;

<!DOCTYPE html>
<html>
<body>
  <div></div>
  <script src="https://unpkg.com/kid-gloves/kid-gloves.js"></script>
  <script>
    document.querySelector(new Symbol('div')).innerHTML = 'Hello World';
  </script>
</body>
</html>

Normally this code would error and present a blank page but this runs and the errors are converted into warnings. https://raw.githubusercontent.com/Patrick-ring-motive/kid-gloves/refs/heads/main/example.png

Fixes So far:

Use new with BigInt and Symbol

Using the new keyword returns an Object wrapped version of BigInt and Sybmol while printing a warning to the console recommending to switch to not using it

Use Promise, Set, and Map

These objects can be called as a constructor without using the new keyword and prints a warning

Missing Map element

Attempting to access a Map element that does not exist prints a warning

document.querySelector

document.querySelector returns null even when given an invalid query and prints the typical error as a warning

document.querySelectorAll

document.querySelectorAll returns an empty NodeList even when given an invalid query and prints the typical error as a warning

document.getElementById

document.getElementById returns null even when given an invalid query and prints the typical error as a warning

document.getElementsById

document.getElementsById warns the user of a potential typo and returns document.querySelectorAll(`[id="${String(query)}"]`);

document.getElementsByTagName

document.getElementsBy(TagName|TagNameNS|ClassName|Name) returns an empty HTMLCollection even when given an invalid query and prints the typical error as a warning

Object.create

Gives a warning if the target prototype is not an object and attempts to coerce it into an object. If coercion fails then return Object.create(null)

parseFloat,parseInt,Number.parseFloat,Number.parseInt

Attempts to safely coerce a Symbol into a string before parsing. If parsing fails for any reason it will return NaN.

Symbol Coercion

Many functions that expect a string will attempt to coerce inputs into strings. The default coercion for Symbol into string throws an error. Many of these have been patched to do a safe coercion from Symbol to String and printing a warning to the console. The typical coercion takes the form of String(sym.description ?? sym)

Object Coercion

Some functions expect an object as input and will throw an error when passed a literal. That error is printed as a warning and the literal will be converted to an object using `Object()