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

missing.js

v2.0.0

Published

The missing prototype utility functions for JavaScript

Downloads

3

Readme

missing.js missing.js

Provides common prototypes with 'missing' functionality, such as the abilty to clone and merge objects, evaluate the type of an object, and the ability to convert an object of one type to another type. The properties, once defined on the various prototypes, cannot be redefined, which makes this perfectly safe to use, so long as you dont include a library with similar ideas along side of missing.js.

####Introduction

/*Without missing.js*/
function (a, b, c) {
	if(parseInt(a) !== a && !isNaN(a)) {
		throw new Error("`a` must be an integer");
	}
	else if(b.constructor !== String) {
		throw new Error("`b` must be a string");
	}
	else if(c !== null && (typeof c == 'object')) {
		throw new Error("`c` must be an object");
	}

	return $.extend(c, {a: a, b: b});
}

/*With missing.js*/
function (a, b, c) {
	if(!a.is.int) {
		throw new Error("`a` must be an integer");
	}
	else if(!b.is.string) {
		throw new Error("`b` must be a string");
	}
	else if(!c.is.object) {
		throw new Error("`c` must be an object");
	}

	return c.merge({a: a, b: b});
}

Getting set up is easy. ####Browser

<script src="missing.js"></script>

####Node

npm install missing
require('missing');

##Object ####Object.clone() Creates a deep copy of the object

var original = {arr: [0,2,3], b:{}, c: "hello"};
var copy = Object.clone(original);

####Object.merge(target, obj) Assimilates obj into target, deep copying any complex values of obj before merging them in. Modifies the original object, and returns the original object after the merger.

var original = {a: 1, b: 2, c: 3};
var other = {a: "existing key", d: "new key"};

var result = Object.merge(original, other);
result === original; //true
original; // {a: "existing key", b: 2, c: 3, d: "new key"}

##Object.prototype ####Object.stringify([replacer, space]) Essentially the same as calling JSON.stringfy(this, [replacer, space])

({a: 5}).stringify(); // "{'a': 5}"

##Array.prototype ####Array.toString()

['a', 2, 'b'].toString(); // "['a', 2, 'b']"
//you will get a similar result if concatenating to a string
var str = "Hello" + ['there', 'world']; // "Hello ['there', 'world']"

####Array.remove(obj) Removes the first instance of obj from the array, and returns it. If nothing was found, returns false. ####Array.removeAll(obj) Removes all instances of obj from the array, and returns them as an array. If nothing was found, returns an empty array. ####Array.contains(obj) Returns true if the object passed is inside of the array

##String.prototype ####String.parse([reviver]) Essentially the same as JSON.parse(this, [reviver])

##to Conversion Included in missing.js is a small object which attaches itself to Object.prototype called to. This object allows you to easily retrieve the value of a variable as another type. This will leave the original object intact. Think of to as a more fully fledged toString() or toFixed(), without the method call. ####to.string Converts the object to a useful string

var array = [1,2,3];
console.log(array.to.string); // "[1, 2, 3]"

var number = 52.332
console.log(number.to.string); // "52.332"

var object = {a: 5, b: {c: 0}};
console.log(object.to.string); //Pretty print + stringified

####to.int Converts the object to an int, or NaN if it cannot be parsed

var string = "1235";
string.to.int; // 1235

var num = 123.4442;
num.to.int; // 123

####to.num Converts the object to a number, possibly with decimals

##is Evaluation Similar to to, you may use is to determine if one object 'is' a certain type. Available properties are listed below.

var something = "50.2";
something.is.int //false		
something.is.number //false
something.is.string //true
something.is.function //false
something.is.object //false
something.is.numeric //true
something.is.NaN //false
something.is.undefined //false
something.is.null //false
something.is.num //false