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

check-your-js

v1.0.1

Published

Checkjs is a library for type checking and more!

Downloads

5

Readme

checkjs

A fast and lightweight library built to help with type checking in plain Javascript that works with new and old versions!

Installation

Local: download the library and include in the <head> section of your website. Link to library

With Node: npm i --save check-your-js

Usage

If you included locally, you can use the funcations as you normally would with an included script.

With Node: import * as CheckJS from 'check-your-js';

Usage Integer

This function is used to check if the passed param is of type Integer. Will throw error if not.

  Integer(42) // returns 42
  Integer('text') // throw error
  Integer(42.2) // throw error - cannot convert float to int

Usage Float

This function is used to check if the passed param is of type Float. Will throw error if not.

  Float(42.2) // returns 42.2
  Float({"name": "bob"}) // throw error
  Float(42) // throw error - cannot convert int to float

Usage String

This function is used to check if the passed param is of type String. Will throw error if not.

  String('text') // returns text
  String(42) // returns "42"
  String({"name": "bob"}) // throw error

Usage Object

This function is used to check if the passed param is of type Object. Will throw error if not.

  Object({"name": "bob"}) // return {"name": "bob"}
  Object('text') // throw error

Usage Boolean

This function is used to check if the passed param is of type Boolean. Will throw error if not.

  Object(false) // return false
  Object('text') // throw error

Usage Function

This function is used to check if the passed param is of type Function. Will throw error if not.

  Function(function(){}) // return function
  Function('text') // throw error

Usage Collection

In Checkjs we use a special "type" called a collection. This is the similar to other languages that have a type of Interface. Here, the Collection type is an array of any passed values / types. It is primarly used as a constructor to make an array that accepts any types. You can then run any other type checker on the Collection's items by passing them to another check function.

  Collection('text', 42, {"name": "bob"}) // returns ['text', 42, {"name": "bob"}]
  Collection() // throw error

To then check one of the values you can pass the Collection's item like so:

  var collection = Collection('text', 42, {"name": "bob"}); // new Collection
  var int = Integer(collection[1]) // returns true because the second item is an integer

Usage Not Empty

The NotEmpty function is used to check if the passed param is empty or not. Useful when you want to perform an action only if there is something in the variable.

  var word = 'text';
  var empty = {};
  NotEmpty(word) // returns true
  NotEmpty(empty) // returns false