1.1.1 • Published 8 years ago

node-type v1.1.1

Weekly downloads
33
License
MIT
Repository
-
Last release
8 years ago

Introduction

Node Type let you easily work with types and its core possibilities such as enumerability, writability and readonly settings. Properties can be declared with a specific type and a livetime validator.

Usage

Properties

var Human = Type.create({
    properties: {
        id: {
            type: Number,
            enumerable: false,
            readonly: true,
            value: generateHumanID()
        }
        name: String,
        age: Number,
        birhtday: Date,
        children: {
            type: Array,
            value: []
        }
    }
});

Human.name = 10;    // TypeError: Need string but got number
Human.age = '35';   // TypeError: Need number but got string
Human.id = 10;      // ReadOnly Error: Can't set
Human.children;     // Array []
API
Type.create(Object)

Contains an object with properties and methods for the type to set.

var returnValue = Type.create({
    properties: {
        // props goes here
    },
    methods: {
        // funcs goes here
    }
});
Property

A property can have fields such as enumerable, writable, value, type, name and readonly. A short explenation can be found in the table below.

FieldDefaultDescription
writabletrueWhen the writable property attribute is set to false, the property is said to be “non-writable”. It cannot be reassigned.
enumerabletrueThe enumerable property attribute defines whether the property shows up in a for...in loop and Object.keys() or not.
typenullDefines the valid type of this property; Date, Boolean, Number, Array, String or Object
namenullThe field name of the property (only needed if used in a property array)
readonlyfalseWill force the setter to deny new values. Store can be modified alltough through Type.__store__key
valueundefinedThe default value of the property

Methods

Coming soon / TBD ...