lib/sequelize-types.js
function assertValidFieldType(pojoName, fieldName, pojo, expectedType) {
    var value = pojo[fieldName];
    var actualType = typeof value;
    if (value === undefined || value === null) {
        return;
    }
    switch (expectedType) {
        case BOOLEAN_TYPE:
            if (actualType !== BOOLEAN_TYPE && actualType !== NUMBER_TYPE) {
                err();
            }
            pojo[fieldName] = Boolean(value);
            return;
        case NUMBER_TYPE:
            if (actualType === NUMBER_TYPE) {
                return;
            }
            if (actualType === STRING_TYPE) {
                var newValue = parseFloat(value);
                if (isNaN(newValue)) {
                    err();
                }
                pojo[fieldName] = newValue;
            }
            return;
        case STRING_TYPE:
            if (actualType !== STRING_TYPE) {
                pojo[fieldName] = value.toString();
            }
            return;
        case DATE_EXPECTED_TYPE:
            var getTime = value.getTime;
            if (typeof getTime === FUNCTION_TYPE) {
                var timeValue = value.getTime();
                if (isNaN(timeValue)) {
                    err();
                }
                if (!(value instanceof Date)) {
                    pojo[fieldName] = new Date(timeValue);
                }
                return;
            }
            if (actualType === STRING_TYPE) {
                var newDate = new Date(value);
                if (!isNaN(newDate.getTime())) {
                    pojo[fieldName] = newDate;
                    return;
                }
            }
            err();
            return;
        case BUFFER_EXPECTED_TYPE:
            if (!BUFFER_EXISTS) {
                return;
            }
            if (!(value instanceof Buffer)) {
                err();
            }
            return;
    }
    // one pojo of array of array of pojos?
    if (expectedType.length > 3 && expectedType.substr(expectedType.length - 2, 2) === '[]') {
        var individualPojoType = expectedType.substr(0, expectedType.length - 6);
        var asserter_1 = asserters[individualPojoType];
        if (typeof asserter_1 !== FUNCTION_TYPE) {
            err();
        }
        if (isNaN(value.length)) {
            err();
        }
        for (var i = 0; i < value.length; i++) {
            try {
                asserter_1(value[i], true);
            }
            catch (e) {
                err('Error at index \'' + i + '\': ' + e.message);
            }
        }
        // all instances valid
        return;
    }
    var asserter = asserters[expectedType.substr(0, expectedType.length - 4)];
    if (typeof asserter !== FUNCTION_TYPE) {
        expectedTypeErr();
    }
    try {
        asserter(value, true);
    }
    catch (e) {
        err(e.message);
    }
    function err(extraMessage) {
        var message = 'Invalid ' + pojoName + ' provided. Field \'' + fieldName + '\' with value \'' + safeValue(value) + '\' is not a valid \'' + expectedType + '\'.';
        if (extraMessage !== undefined) {
            message += ' ' + extraMessage;
        }
        throw new Error(message);
    }
    function expectedTypeErr() {
        throw new Error('Cannot validate \'' + pojoName + '\' field \'' + fieldName + '\' since expected type provided \'' + expectedType + '\' is not understood.');
    }
}
function assertValidFieldType(pojoName, fieldName, pojo, expectedType) {
    var value = pojo[fieldName];
    var actualType = typeof value;
    if (value === undefined || value === null) {
        return;
    }
    switch (expectedType) {
        case BOOLEAN_TYPE:
            if (actualType !== BOOLEAN_TYPE && actualType !== NUMBER_TYPE) {
                err();
            }
            pojo[fieldName] = Boolean(value);
            return;
        case NUMBER_TYPE:
            if (actualType === NUMBER_TYPE) {
                return;
            }
            if (actualType === STRING_TYPE) {
                var newValue = parseFloat(value);
                if (isNaN(newValue)) {
                    err();
                }
                pojo[fieldName] = newValue;
            }
            return;
        case STRING_TYPE:
            if (actualType !== STRING_TYPE) {
                pojo[fieldName] = value.toString();
            }
            return;
        case DATE_EXPECTED_TYPE:
            var getTime = value.getTime;
            if (typeof getTime === FUNCTION_TYPE) {
                var timeValue = value.getTime();
                if (isNaN(timeValue)) {
                    err();
                }
                if (!(value instanceof Date)) {
                    pojo[fieldName] = new Date(timeValue);
                }
                return;
            }
            if (actualType === STRING_TYPE) {
                var newDate = new Date(value);
                if (!isNaN(newDate.getTime())) {
                    pojo[fieldName] = newDate;
                    return;
                }
            }
            err();
            return;
        case BUFFER_EXPECTED_TYPE:
            if (!BUFFER_EXISTS) {
                return;
            }
            if (!(value instanceof Buffer)) {
                err();
            }
            return;
    }
    // one pojo of array of array of pojos?
    if (expectedType.length > 3 && expectedType.substr(expectedType.length - 2, 2) === '[]') {
        var individualPojoType = expectedType.substr(0, expectedType.length - 6);
        var asserter_1 = asserters[individualPojoType];
        if (typeof asserter_1 !== FUNCTION_TYPE) {
            err();
        }
        if (isNaN(value.length)) {
            err();
        }
        for (var i = 0; i < value.length; i++) {
            try {
                asserter_1(value[i], true);
            }
            catch (e) {
                err('Error at index \'' + i + '\': ' + e.message);
            }
        }
        // all instances valid
        return;
    }
    var asserter = asserters[expectedType.substr(0, expectedType.length - 4)];
    if (typeof asserter !== FUNCTION_TYPE) {
        expectedTypeErr();
    }
    try {
        asserter(value, true);
    }
    catch (e) {
        err(e.message);
    }
    function err(extraMessage) {
        var message = 'Invalid ' + pojoName + ' provided. Field \'' + fieldName + '\' with value \'' + safeValue(value) + '\' is not a valid \'' + expectedType + '\'.';
        if (extraMessage !== undefined) {
            message += ' ' + extraMessage;
        }
        throw new Error(message);
    }
    function expectedTypeErr() {
        throw new Error('Cannot validate \'' + pojoName + '\' field \'' + fieldName + '\' since expected type provided \'' + expectedType + '\' is not understood.');
    }
}
function assertValidFieldType ( pojoName , fieldName , pojo , expectedType ) { var value = pojo [ fieldName ] ; var actualType = typeof value ; if ( value === undefined || value === null ) { return ; } switch ( expectedType ) { case BOOLEAN_TYPE : if ( actualType !== BOOLEAN_TYPE && actualType !== NUMBER_TYPE ) { err ( ) ; } pojo [ fieldName ] = Boolean ( value ) ; return ; case NUMBER_TYPE : if ( actualType === NUMBER_TYPE ) { return ; } if ( actualType === STRING_TYPE ) { var newValue = parseFloat ( value ) ; if ( isNaN ( newValue ) ) { err ( ) ; } pojo [ fieldName ] = newValue ; } return ; case STRING_TYPE : if ( actualType !== STRING_TYPE ) { pojo [ fieldName ] = value . toString ( ) ; } return ; case DATE_EXPECTED_TYPE : var getTime = value . getTime ; if ( typeof getTime === FUNCTION_TYPE ) { var timeValue = value . getTime ( ) ; if ( isNaN ( timeValue ) ) { err ( ) ; } if ( ! ( value instanceof Date ) ) { pojo [ fieldName ] = new Date ( timeValue ) ; } return ; } if ( actualType === STRING_TYPE ) { var newDate = new Date ( value ) ; if ( ! isNaN ( newDate . getTime ( ) ) ) { pojo [ fieldName ] = newDate ; return ; } } err ( ) ; return ; case BUFFER_EXPECTED_TYPE : if ( ! BUFFER_EXISTS ) { return ; } if ( ! ( value instanceof Buffer ) ) { err ( ) ; } return ; } // one pojo of array of array of pojos?
 if ( expectedType . length > 3 && expectedType . substr ( expectedType . length - 2 , 2 ) === '[]' ) { var individualPojoType = expectedType . substr ( 0 , expectedType . length - 6 ) ; var asserter_1 = asserters [ individualPojoType ] ; if ( typeof asserter_1 !== FUNCTION_TYPE ) { err ( ) ; } if ( isNaN ( value . length ) ) { err ( ) ; } for ( var i = 0 ; i < value . length ; i ++ ) { try { asserter_1 ( value [ i ] , true ) ; } catch ( e ) { err ( 'Error at index \'' + i + '\': ' + e . message ) ; } } // all instances valid
 return ; } var asserter = asserters [ expectedType . substr ( 0 , expectedType . length - 4 ) ] ; if ( typeof asserter !== FUNCTION_TYPE ) { expectedTypeErr ( ) ; } try { asserter ( value , true ) ; } catch ( e ) { err ( e . message ) ; } function err ( extraMessage ) { var message = 'Invalid ' + pojoName + ' provided. Field \'' + fieldName + '\' with value \'' + safeValue ( value ) + '\' is not a valid \'' + expectedType + '\'.' ; if ( extraMessage !== undefined ) { message += ' ' + extraMessage ; } throw new Error ( message ) ; } function expectedTypeErr ( ) { throw new Error ( 'Cannot validate \'' + pojoName + '\' field \'' + fieldName + '\' since expected type provided \'' + expectedType + '\' is not understood.' ) ; } }
in node exists, in js not, so only validate in node
in node exists in js not so only validate in node