Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

typed

Version Badge Build Status Dependencies License File 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.

About

Statically typed properties for object literals

Topics

Resources

License

Packages

No packages published
You can’t perform that action at this time.