export const setString = (str, len) => {
    let StrLen = 0;
    let s = '';
    for (let i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) > 128) {
            StrLen += 2;
        }
        else {
            StrLen++;
        }
        s += str.charAt(i);
        if (StrLen >= len) {
            return `${s}...`;
        }
    }
    return s;
};
export const OptionFormat = GetOptions => {
    let options = '{';
    for (let n = 0; n < GetOptions.length; n++) {
        options = `${options}'${GetOptions[n].option_name}':'${GetOptions[n].option_value}'`;
        if (n < GetOptions.length - 1) {
            options += ',';
        }
    }
    return JSON.parse(`${options}}`);
};
export const HovercUnique = (arr) => {
    const n = {};
    const r = [];
    for (let i = 0; i < arr.length; i++) {
        if (!n[arr[i]]) {
            n[arr[i]] = true;
            r.push(arr[i]);
        }
    }
    return r;
};
export const getJsonLength = jsonData => {
    return Object.keys(jsonData).length;
};
export const getResponseData = (data, error) => {
    const res = {
        data,
    };
    if (error) {
        const err_code = error.code;
        res.error = {
            code: err_code,
            message: error.message,
        };
    }
    return res;
};
