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

typewatch

v0.0.1

Published

A type sanity and testing harness for javascript projects.

Downloads

4

Readme

Typewatch

Typewatch is an attempt at an easy to plug and play javascript type checker/inline testing framework.

It was inspired by the author's observations of seemingly small changes rippling through codebases in weird and unexpected ways, quietly tainting the application state with madness and negative infinity.

“It wasn't by eliminating the impossible that you got at the truth, however improbable; it was by the much harder process of eliminating the possibilities. You worked away, patiently asking questions and looking hard at things. You walked and talked, and in your heart you just hoped like hell that some bugger's nerve'd crack and he'd give himself up.” - Terry Pratchett, Feet of Clay

Installation

npm install

Pre-built guards.

We include a number of ready-to-use guards. As of version 0.0.1 we support.

_null_
_Boolean_
_Number_
_undefined_
_String_
_Object_
_Array_

Use

1: Post your guards.

Guards work best near the entrances and exits to areas. So if we have a function that does some maths like this one:

addThenMultiply = function(x, y, z) {
  var temp = x + y;
  temp = temp * z;
  console.log(temp);
  return temp;
}

The best places for guards is the variables coming in and the result getting returned.

import guard from 'typewatch';

addThenMultiply = function(x, y, z) {
  x = guard.whoGoesThere('_Number_', x);
  y = guard.whoGoesThere('_Number_', y);
  z = guard.whoGoesThere('_Number_', z);
  var temp = x + y;
  temp = temp * z;
  console.log(temp);
  return guard.whoGoesThere('_Number_', temp);
}

Guards on duty either throw an error or pass the value through.

2: Arm them for patrol.

Guards need to equipped in order to patrol their posted areas. In our case we can give them a function to generate test data. There is no checking if the generator returns the right type because somestimes you want things to break.

import guard from 'typewatch';

addThenMultiply = function(x, y, z) {
  guard.reportWith('_Number_', function() {
    // Chosen by fair dice roll, guarenteed to be random.
    return 4;
  });
  x = guard.whoGoesThere('_Number_', x);
  y = guard.whoGoesThere('_Number_', y);
  z = guard.whoGoesThere('_Number_', z);
  var temp = x + y;
  temp = temp * z;
  console.log(temp);
  return guard.whoGoesThere('_Number_', temp);
}

3: Send them on patrol.

Guards on patrol generate test data either using a generator if they have one or a default if they don't and the function is executed with that data.

import guard from 'typewatch';

addThenMultiply = function(x, y, z) {
  guard.reportWith('_Number_', function() {
    // Chosen by fair dice roll, guarenteed to be random.
    return 4;
  });
  x = guard.whoGoesThere('_Number_', x);
  y = guard.whoGoesThere('_Number_', y);
  z = guard.whoGoesThere('_Number_', z);
  var temp = x + y;
  temp = temp * z;
  console.log(temp);
  guard.reportWith('_Number_', function() {
    return 0;
  });
  return guard.whoGoesThere('_Number_', temp);
}

guard.patrol(addThenMultiply);

In this case the console logs 32 and the function returns 0. Adding support to patrol multiple routes is a work in progress.

4: Train more guards.

They need a unique name, a watch function that either returns the value or throws an error and a default report function to use if it hasn't been told what to reportWith.

By convention names are double underscored version's of the Class/Constructor/Type that's being checked against.

guard.train({
  name: '_NumberBetween0and10_',
  watch: function(input) {
    // Return the input if it's valid, throw a TypeError if it isn't.
    input = guard.whoGoesThere('_Number_', input);
    if ((0 <= input) && (input <= 10)) {
      return input;
    }
    throw new TypeError(this.name + " caught " + input);
  },
  report: function() {
    // Fallback test data generator. It's a good idea to self validate.
    return this.watch(5);
  },
  reportWith: function() {
    // Optional test data generator that may be overridden.
    return NaN;
  }
});

Contributing.

Found a bug in a validator, a way to make it better? Written a guard that's so useful it should be included as a pre-built? Submit a pull request or raise an issue.