1.1.1 • Published 8 years ago
node-type v1.1.1
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.
Field | Default | Description |
---|---|---|
writable | true | When the writable property attribute is set to false, the property is said to be “non-writable”. It cannot be reassigned. |
enumerable | true | The enumerable property attribute defines whether the property shows up in a for...in loop and Object.keys() or not. |
type | null | Defines the valid type of this property; Date, Boolean, Number, Array, String or Object |
name | null | The field name of the property (only needed if used in a property array) |
readonly | false | Will force the setter to deny new values. Store can be modified alltough through Type.__store__key |
value | undefined | The default value of the property |
Methods
Coming soon / TBD ...