all files / workbook/common/ internalization.js

100% Statements 33/33
96.97% Branches 32/33
100% Functions 3/3
100% Lines 33/33
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   10411× 10411× 9783×   628× 569× 14×   569×   569×   569× 11×   569× 20×     608×   279× 279× 279× 279× 279× 279× 365× 103×     262×     365× 249×     279×      
define(["require", "exports", "../common/index", "@syncfusion/ej2-base"], function (require, exports, index_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function checkIsNumberAndGetNumber(cell, locale, groupSep, decimalSep, currencySym) {
        var cellValue = cell.value;
        if (index_1.isNumber(cellValue)) {
            return { isNumber: true, value: cellValue };
        }
        if (cellValue && typeof cellValue === 'string') {
            if (currencySym && cellValue.includes(currencySym) && (cell.format.includes(currencySym) || cell.format.includes('$'))) {
                cellValue = cellValue.replace(currencySym, '').trim();
            }
            if (groupSep && cellValue.includes(groupSep) && parseThousandSeparator(cellValue, locale, groupSep, decimalSep)) {
                cellValue = cellValue.split(groupSep).join('').trim();
            }
            if (!decimalSep) {
                decimalSep = ej2_base_1.getNumericObject(locale).decimal;
            }
            if (decimalSep !== '.' && cellValue.includes(decimalSep)) {
                cellValue = cellValue.replace(decimalSep, '.').trim();
            }
            if (index_1.isNumber(cellValue)) {
                return { isNumber: true, value: cellValue };
            }
        }
        return { isNumber: false, value: cellValue };
    }
    exports.checkIsNumberAndGetNumber = checkIsNumberAndGetNumber;
    function parseThousandSeparator(value, locale, groupSep, decimalSep) {
        var isParsed = false;
        var number = 123456;
        var parsedNum = number.toLocaleString(locale);
        var splitedNum = parsedNum.split(groupSep).reverse();
        var splitedValue = value.split(decimalSep)[0].split(groupSep);
        for (var i = 0; i < splitedValue.length; i++) {
            if (i === splitedValue.length - 1) {
                isParsed = splitedValue[i].length === splitedNum[0].length;
            }
            else {
                isParsed = !ej2_base_1.isUndefined(splitedNum[1]) && (i === 0 ? splitedValue[i].length <= splitedNum[1].length :
                    splitedValue[i].length === splitedNum[1].length);
            }
            if (!isParsed) {
                break;
            }
        }
        return isParsed;
    }
    exports.parseThousandSeparator = parseThousandSeparator;
});