
if (typeof String.prototype.startsWith != 'function') {
    String.prototype.startsWith = function (str){
        return this.slice(0, str.length) == str;
    };
}

if (typeof String.prototype.endsWith != 'function') {
    String.prototype.endsWith = function (str){
        return this.slice(-str.length) == str;
    };
}

function path_build() {

    var path = [];

    for (a = 0; a < arguments.length; a++) {

        var arg = arguments[a];

        // Remove trailing slash if not slash itself
        if (arg.length > 1 && arg.endsWith('/')) {
            arg = arg.substr(0, arg.length-1);
        }

        // Remove starting slash if not the first argument
        if (a > 0) {
            if (arg.startsWith('/')) {
                arg = arg.substr(1);
            }
        }

        path.push(arg);
    }

    // Join by slash and remove double slash if any
    return path.join('/').replace('//', '/');
}

