export function substring(str, start, end) {
    if (start <= end) {
        return str.substring(start, end);
    }
    return '';
}
export function replaceSubstring(str, start, end, replacer) {
    var prefix = str.substring(0, start);
    var suffix = str.substring(end + 1);
    if (suffix[0] !== ' ') {
        suffix = " " + suffix;
    }
    var prefixAndContent = "" + prefix + replacer;
    return {
        value: "" + prefixAndContent + suffix,
        caret: prefixAndContent.length + 1,
    };
}
export function isWhiteSpace(c) {
    return /^\s$/.test(c);
}
export function getInputNodeForTrigger(node) {
    if (!node || node.nodeType === Node.TEXT_NODE) {
        return null;
    }
    var elem = node;
    var tagName = elem.tagName;
    if (tagName === 'INPUT' || tagName === 'TEXTAREA') {
        return elem;
    }
    return elem.querySelector('input') || elem.querySelector('textarea') || null;
}
export function getMenuListItems(suggestions, notFoundContent) {
    if (!suggestions || suggestions.length === 0) {
        return [
            {
                content: notFoundContent,
                value: '',
                disabled: true,
            },
        ];
    }
    return suggestions.map(function (item) {
        if (typeof item === 'string' || typeof item === 'number') {
            return {
                content: item,
                value: item,
            };
        }
        return item;
    });
}
