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 🙏

© 2025 – Pkg Stats / Ryan Hefner

vok

v0.0.2

Published

Value OK? Shorthand validity check.

Downloads

21

Readme

Introduction

Writing defensive code in Javascript is good practice. But checking that an object/item exists before operating on it, checking if it's undefined, null, the expected type or something else (repeatedly) before even doing anything is boring. This is where the ever dependable Underscore.JS is a great time saver. But even though that gives you a fantastic arsenal of validation tools, you may still have to combine multiple function calls to confirm the existence of an otherwise expected object and it's type. That gets boring, so I produced vok (Value OK?), to do just this (piggybacking off Underscore.JS) but in one function call.

Installation

  npm install vok

Usage

vok([OBJECT TO TEST],[PATH TO TEST],[EXPECTED TYPE OF LAST CHILD],[DEBUG?]);

vok accepts 4 simple parameters. The last two are entirely optional!

  • [OBJECT TO TEST] should be replaced with an object you want to validate.
  • [PATH TO TEST] should be a string of the path through the object you want to test exists.
  • [EXPECTED TYPE OF LAST CHILD] - optional! If you're expecting the very end of your tested path to be an array, null, number... whatever, you can have this checked for also! If there's an equivalent Underscore.JS 'is' test for it, then you should be able to define a type to check to match (e.g 'null' effectively calls the _.isNull function, 'array' calls _.isArray etc. etc.)
  • [DEBUG?] - optional! False by default, if you specify true then additional information about any failing tests will be console log'ed for your perusal.

Here's a typical use case. Imagine you have an object that looks like this :

var testme = {
	thingy: {
		thongy: {
			wibble: null,
			wobble: [1,2,3]
		}
	}
}

...and you want to update the value of 'wibble'. Being super-defensive and using Underscore.JS you would check that each stage in the object actually exists, and that 'wibble' was the null value you were expecting like :

if(!_.isUndefined(testme.thingy) && !_.isUndefined(testme.thingy.thongy) && !_.isUndefined(testme.thingy.thongy.wibble) && _.isNull(testme.thingy.thongy.wibble)) {
	testme.thingy.thongy.wibble = 123;
}

All that validation simply confirms that the testme object matches the structure assumed, because if you attempted to work with a value like 'testme.thingy.thingy.wibble' and this path structure was different, your app may crash. vok compresses this into the shorthand of :

if(vok(testme,'testme.thingy.thongy.wibble','null')) {
	testme.thingy.thingy.wibble = 123;
}

Given the testme object, and a structured path you'd like to confirm is legit, this will validate the presence of each stage in the given path, and then with the optional third parameter check that the item at the end of this path matches the given type. In this case, it's confirming that the wibble element = null.

Does it work with arrays? You betcha!

if(vok(testme,'testme.thingy.thongy.wobble[2]')) {
	testme.thingy.thingy.wobble[2] = 99;
}