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

backbone-typed

v0.1.4

Published

Run-time type support for backbone models

Readme

backbone-typed Build Status

Run-time type support for backbone models

Backbone-Typed extends the Backbone model and provides an optional Type system on top of the default models. The system is provided in run time, and is optimistic, if the value can be converted to the needed type it will, if not, it will be nulled and logged

Examples writtein in Coffee-Script but source is compiled to JS so no need to have CS installed at run time.

Installation

npm install backbone-typed

Usage

typed = require 'backbone-typed'
TypedModel = typed.TypedModel
Types = typed.Types

Features


enumLike : {
	"OPTION_1"
	"OPTION_2"
	"OPTION_3"
	"OPTION_4"
}

class MyTypedModel extends TypedModel
	defaults : { 
		param1: null, 
		param2: null, 
		param3: null 
	}
	types : {
		param1: Types.String, 
		param2: Types.Integer, 
		param3: Types.Enum(enumLike)
	}


myTypedModel = new MyTypedModel({param1: "im a string", param2: "1337", param3: enumLike.OPTION_1})

console.log myTypedModel.toJSON()
=> { param1: "im a string", param2: 1337, param3: "OPTION_1" }

# now things get interesting...

myTypedModel2 = new MyTypedModel({param1: 100, param2: "bzzzz", param3: "NOT A REAL OPTION"})

console.log myTypedModel2.toJSON()
=> backbone-typed :: 2012-9-13 20:10:3.235 :: ERROR :: backbone-typed nulled value of:"param2" value:"bzzzz" type:"Integer"
=> backbone-typed :: 2012-9-13 20:10:3.235 :: ERROR :: backbone-typed nulled value of:"param3" value:"NOT A REAL OPTION" type:"Enum"
=> { param1: "100", param2: null, param3: null }

Creating your own type!

Sometimes its useful to have your own method that validates input and returns some output. Backbone-typed provides a method that "signs" the passed function, so that we know its there in purpose, and will even return its name if the ".toString()" of said function is called.

# we sign the function
myType = typed.signTypeFunction "Custom",(param)->
	return if param is "its me!" then "yes"  else null

# now use it in a model
class CustomTyped extends TypedModel
	defaults : {  testMe : null }
	types : { testMe : myType }

More examples in specs.

Future

Libraries of additional types

License

MIT