"use strict";

function convertToObjectPathArray(path, separator) {
    if (!path) {
        return "";
    }
    if (!separator) {
        separator = "/";
    }
    if (path.indexOf(separator) === 0) {
        path = path.substring(1);
    }
    return path.split(separator);
}

module.exports = {
    capitalizeFirstLetter: function (string) {
        return string.charAt(0).toUpperCase() + string.slice(1);
    },
    arrayInString: (strings, string) => {
        var i = 0;
        var inString = false;
        do {
            inString = string.indexOf(strings[i++]) !== -1;
        } while (!inString && i < strings.length);

        return inString;
    },
    convertToObjectPathArray: convertToObjectPathArray,
    convertToObjectPath: function(path, separator) {
        return convertToObjectPathArray(path, separator).join(".");
    },

    // dot has been removed to fix 16546, the issue in 15715 no longer occur in ES7
    escapeSpecialChar: (text) => {
        return text.replace(/[`~!@#$%^&*()_|+\-=?;:'",<>\{\}\[\]\\\/]/gi, '\\$&');
    }
};