Nodejs String Starts With startWith(s)

Here you can find the source of startWith(s)

Method Source Code

/**//  www  .  ja v  a 2 s .  co m
 * Created by Administrator on 2017/8/4.
 */
function convertParamsMapToUri(paramsMap) {
    var uri = "";
    var isFirst = true;
    for (var key in paramsMap) {
        var keyValue = key + "=" + paramsMap[key];
        if (isFirst) {
            isFirst = false;
        } else {
            uri += "&";
        }
        uri += keyValue;
    }
    return uri;
}

function openUrlInNewWindow(url) {
    if (url.startWith('http://')) {
        window.open(url);
    } else {
        window.open('http://' + url);
    }
}

String.prototype.startWith = function (s) {
    if (s == null || s == "" || this.length == 0 || s.length > this.length) {
        return false;
    }
    return this.substr(0, s.length) == s;
};

Related

  1. startswith(str)
    String.prototype.startswith = function(str)
      return this.slice(0, str.length) === str;
    };
    
  2. startswith(str)
    String.prototype.startswith = function(str) {
      return (this.substring(0, str.length) === str) ? true : false;
    
  3. startWith(pre)
    String.prototype.startWith = function(pre){
      return new RegExp("^("+pre+")(.*)").test(this);
    };
    
  4. startWith(s)
    String.prototype.startWith = function (s) {
        return this.indexOf(s) == 0
    
  5. startWith(s)
    String.prototype.startWith = function(s) {
      if (s === null || s === "" || this.length === 0 || s.length > this.length)
        return false;
      if (this.substr(0, s.length) == s)
        return true;
      else
        return false;
      return true;
    
  6. startWith(str)
    String.prototype.startWith = function(str){
      return this.indexOf(str) == 0;
    };
    
  7. startWith(str)
    String.prototype.startWith = function(str) {
      var reg = new RegExp("^" + str);
      return reg.test(this);
    };
    
  8. startWith(str)
    String.prototype.startWith = function (str) {
      var reg = new RegExp("^" + str);
      return reg.test(this);
    
  9. startWith(str)
    String.prototype.startWith=function(str){
    if(str==null||str==""||this.length==0||str.length>this.length)
      return false;
    if(this.substr(0,str.length)==str)
      return true;
    else
      return false;
    return true;