Statically typed properties for object literals
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist
src
test
.babelrc
.editorconfig
.eslintrc
.gitattributes
.gitignore
.travis.yml
README.md
UNLICENSE
gulpfile.babel.js
package.json

README.md

typed

GitHub version Build Status Size

Statically typed properties for object literals

Usage

Map properties to a native data type:

const object = typed({
    foo: String,
    bar: Number 
});

object.foo = 'foo';
object.bar = 123;

Constrain a property to a user-defined constructor:

function Foo() {}

const object = typed({
    foo: Foo
});

object.foo = new Foo();

If a value of the wrong type is assigned to a property, a TypeError will be thrown:

const object = typed({
    foo: String
});

object.foo = 123 // throws: Invalid value assignment on "foo", expected: String, actual: Number

Installation

Typed is CommonJS and AMD compatible with no dependencies. You can download the development or minified version, or install it in one of the following ways:

npm install ryanmorr/typed

bower install ryanmorr/typed

Tests

Run unit tests by issuing the following commands:

npm install
npm install -g gulp
gulp test

License

This project is dedicated to the public domain as described by the Unlicense.