dist/modules/type.js
function castType(val, type, def) {
    function cast() {
        if (!is_1.isValue(val))
            return to_1.toDefault(null, def);
        // If no type specified try to get automatically.
        type = type || getType(val);
        if (is_1.isArray(type)) {
            return to_1.toArray(val)
                .map(function (v, i) { return castType(v, type[i] || type[i - 1] || type[0]); });
        }
        else if (is_1.isFunction(type)) {
            val = to_1.toArray(val);
            return type.apply(void 0, val);
        }
        else if (is_1.isString(type)) {
            type = type.toLowerCase();
            var func = toMap[type];
            if (func)
                return func(val);
            return to_1.toDefault(null, def);
        }
        else {
            return val;
        }
    }
    return function_1.tryWrap(cast)(def);
}
function castType(val, type, def) {
    function cast() {
        if (!is_1.isValue(val))
            return to_1.toDefault(null, def);
        // If no type specified try to get automatically.
        type = type || getType(val);
        if (is_1.isArray(type)) {
            return to_1.toArray(val)
                .map(function (v, i) { return castType(v, type[i] || type[i - 1] || type[0]); });
        }
        else if (is_1.isFunction(type)) {
            val = to_1.toArray(val);
            return type.apply(void 0, val);
        }
        else if (is_1.isString(type)) {
            type = type.toLowerCase();
            var func = toMap[type];
            if (func)
                return func(val);
            return to_1.toDefault(null, def);
        }
        else {
            return val;
        }
    }
    return function_1.tryWrap(cast)(def);
}
function castType ( val , type , def ) { function cast ( ) { if ( ! is_1 . isValue ( val ) ) return to_1 . toDefault ( null , def ) ; // If no type specified try to get automatically. type = type || getType ( val ) ; if ( is_1 . isArray ( type ) ) { return to_1 . toArray ( val ) . map ( function ( v , i ) { return castType ( v , type [ i ] || type [ i - 1 ] || type [ 0 ] ) ; } ) ; } else if ( is_1 . isFunction ( type ) ) { val = to_1 . toArray ( val ) ; return type . apply ( void 0 , val ) ; } else if ( is_1 . isString ( type ) ) { type = type . toLowerCase ( ) ; var func = toMap [ type ] ; if ( func ) return func ( val ) ; return to_1 . toDefault ( null , def ) ; } else { return val ; } } return function_1 . tryWrap ( cast ) ( def ) ; }
Cast Type
Attempts to cast to specified type.

@param val the value to be cast.
@param type the type to cast to.
@param def optional default value to return on null.
Cast Type Attempts to cast to specified type .