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

typesjs

v1.1.0

Published

Easy type checking, in Node & browsers.

Downloads

12

Readme

888                                                  d8b
888                                                  Y8P
888
888888  888  888  88888b.    .d88b.   .d8888b       8888 .d8888b
888     888  888  888 "88b  d8P  Y8b  88K           "888 88K
888     888  888  888  888  88888888  "Y8888b.       888 "Y8888b.
Y88b.   Y88b 888  888 d88P  Y8b.           X88  d8b  888      X88
 "Y888   "Y88888  88888P"    "Y8888   "88888P'  Y8P  888 "88888P'
             888  888                                888
        Y8b d88P  888                               d88P
         "Y88P"   888                             888P"

Installation

npm install typesjs   # Node
bower install typesjs # Browser

What can TypesJS do for me?

var t = require('typesjs');

t("String", String);
t(23, Number);
t([], Array);

t([], String); // Throws a TypeError.

If you need a variable to be a String, for example, typesjs can halt your code safely when it's not.

What if I dislike errors?

t.check('Lorem', String); // Returns true.
t.check(1999, String);    // Returns false.

check will return a boolean based on the match.

What if I do like errors?

try {
    t([], String);
} catch(e) {
    // ...
}

try/catch blocks are your friend here.

What if I make my own types?

function Message(text) {
	this.text = text;
}
var message = new Message('Lorem');
t(message, Message);

Custom types are fully supported.

What if a value is null or undefined?

t(undefined, String); // Throws a TypeError.

What if a value isn't required though?

t(undefined, String, false); // Returns true.

Just pass false or "optional" as the third parameter. This will allow for null and undefined values.

t(undefined, String, "optional"); // Returns true.

Passing "optional" is more verbose, but perhaps more readable.

What if I want to allow multiple types?

t("23", [Number, String]);

Just pass an array of types.

What if I want to disable typesjs, during runtime?

t.enabled = false;

When disabled, typesjs will always return true.

Note: This changes the global setting for all the code using TypesJS. Only use this in applications and never in libraries.


Feel free to make a GitHub issue, or pull request. Thanks.