Support
Dynamic type checker for nodejs >= v4.0.0 It support only class syntax in order to have type checking all classes must be inherited from Type class
Type Inheritance
All class members must be defined in constructor super call otherwise if you try to assign member to initialized object Type object will throw an type error. After object initialization object is prevented from extension
{ super username: TypeSTRING password: TypeSTRING ; thisusername = name; thispassword = password; } { return thisusername; } { thisusername = user; }var user = 'Igor' 'Ivanovic';user; // Igoruser // Throws type erroruserassign = 1 // Throws type error , all members must be defined at super call with proper type// Predefined function inside of typeuser; // clear all references to initialized object
Constants
TypeOBJECT = "object";TypeSTRING = "string";TypeARRAY = "array";TypeREGEX = "regexp";TypeNUMBER = "number";TypeBOOLEAN = "boolean";TypeFUNCTION = "function";TypeDATE = "date";TypeUNDEFINED = "undefined";TypeNULL = "null";
Type Functions
Type.isNull(value)
Check if value is nullable
Type; // true
Type.isObject(value)
Check if value is object
Type; // trueType; // true
Type.isRegExp(value)
Check if value is regular expression object
Type; // falseType; // true
Type.isDate(value)
Check if value is date object
Type; // falseType; // true
Type.isFunction(value)
Check if value is function object
Type; // falseType; // true
Type.isArray(value)
Check if value is array object
Type; // falseType; // true
Type.isNumber(value)
Check if value is number
Type; // trueType; // trueType; // false
Type.isString(value)
Check if value is string
Type; // falseType; // true
Type.isBoolean(value)
Check if value is boolean
Type; // falseType; // true
Type.isUndefined(value)
Check if value is undefined
Type; // falseType; // true
Type.isInitialized(value)
Check if value is initialized, null is not considered as initialized
Type; // falseType; // false
Type.getType(value)
Get type of value
Type; // nullType; // undefinedType; // objectType; // array
Type.assert(type, value)
Get type of value. Type should be valid type constant
Type; // trueType; // falseType; // trueType; // true