all files / base/ util.js

100% Statements 54/54
85.45% Branches 47/55
100% Functions 4/4
100% Lines 54/54
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84   931× 528×   403× 403× 403×   30× 30× 30×     19× 19× 19×   22× 22× 22×   22×     17× 17× 15×         17×   18× 18× 18×   17×   17× 17× 17×     280× 280×   403×   830× 198×   632× 24×   608× 40×   38×     632×   16× 16× 764×   16×      
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var intl = new ej2_base_1.Internationalization();
    function parseValue(type, val, model) {
        if (ej2_base_1.isNullOrUndefined(val) || val === '') {
            return '';
        }
        var result;
        var tempFormat;
        switch (type) {
            case 'Color': {
                var hex = val;
                result = (hex.length > 7) ? hex.slice(0, -2) : hex;
                break;
            }
            case 'Date':
                tempFormat = model.format;
                result = intl.formatDate(val, { format: tempFormat, type: type, skeleton: ej2_base_1.isBlazor() ? 'd' : 'yMd' });
                break;
            case 'DateRange': {
                tempFormat = model.format;
                var date = val;
                result = intl.formatDate(date[0], { format: tempFormat, type: type, skeleton: ej2_base_1.isBlazor() ? 'd' : 'yMd' }) + ' - '
                    + intl.formatDate(date[1], { format: tempFormat, type: type, skeleton: ej2_base_1.isBlazor() ? 'd' : 'yMd' });
                break;
            }
            case 'DateTime':
                tempFormat = model.format;
                if (ej2_base_1.isNullOrUndefined(tempFormat) || tempFormat === '') {
                    result = intl.formatDate(val, { format: tempFormat, type: type, skeleton: ej2_base_1.isBlazor() ? 'd' : 'yMd' }) + ' '
                        + intl.formatDate(val, { format: tempFormat, type: type, skeleton: ej2_base_1.isBlazor() ? 't' : 'hm' });
                }
                else {
                    result = intl.formatDate(val, { format: tempFormat, type: type, skeleton: ej2_base_1.isBlazor() ? 'd' : 'yMd' });
                }
                break;
            case 'Time':
                tempFormat = model.format;
                result = intl.formatDate(val, { format: tempFormat, type: type, skeleton: ej2_base_1.isBlazor() ? 't' : 'hm' });
                break;
            case 'Numeric': {
                tempFormat = ej2_base_1.isNullOrUndefined(model.format) ? 'n2' :
                    model.format;
                var tempVal = ej2_base_1.isNullOrUndefined(val) ? null : (typeof (val) === 'number' ? val : intl.parseNumber(val));
                result = intl.formatNumber(tempVal, { format: tempFormat });
                break;
            }
            default:
                result = val.toString();
                break;
        }
        return result;
    }
    exports.parseValue = parseValue;
    function getCompValue(type, val) {
        if (ej2_base_1.isNullOrUndefined(val) || val === '') {
            return val;
        }
        if ((type === 'Date' || type === 'Time' || type === 'DateTime') && typeof (val) === 'string') {
            val = new Date(val);
        }
        else if (type === 'DateRange') {
            if (typeof (val) === 'object' && typeof (val[0]) === 'string') {
                val = [new Date(val[0]), new Date(val[1])];
            }
            else if (typeof (val) === 'string') {
                var temp = val.split('-');
                val = [new Date(temp[0]), new Date(temp[1])];
            }
        }
        return val;
    }
    exports.getCompValue = getCompValue;
    function encode(value) {
        var data = [];
        for (var i = value.length - 1; i >= 0; i--) {
            data.unshift(['&#', value[i].charCodeAt(0), ';'].join(''));
        }
        return data.join('');
    }
    exports.encode = encode;
});