Nodejs String Split rsplit(sep, maxsplit)

Here you can find the source of rsplit(sep, maxsplit)

Method Source Code

String.prototype.rsplit = function(sep, maxsplit) {
    var split = this.split(sep);
    return maxsplit ? [ split.slice(0, -maxsplit).join(sep) ].concat(split.slice(-maxsplit)) : split;
}

var graphs = [];//from w  ww  .  j av a  2  s .c  om
var URL_SEP = "/";
var blank_uuid = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

function swapLastPart(url, lastPart) {
   return swapLastParts(url, [lastPart]);
}

function swapLastParts(url, newParts) {
   var nbParts = newParts.length;
   parts = url.rsplit(URL_SEP);
   // remove unwanted parts
   for (var i=0; i<nbParts ; i++) {
      parts.pop();
   }
   // join new parts
   for (var i=0; i<nbParts ; i++) {
      parts.push(newParts[i]);
   }
   return parts.join(URL_SEP);
}

var get_click_to_point_event = function (url) {
   return {
      click: function (e) { 
         window.location = swapLastPart(url, e.currentTarget.rid);
      }
   }
}

Related

  1. splitWord()
    String.prototype.splitWord = function () {
      return this.split(/(?=[A-Z])/).join(' ');
    };
    
  2. splitchunks(s)
    String.prototype.splitchunks = function(s) {
      return s.split(/\n\n+/) 
    
  3. splitenum(separator)
    String.prototype.splitenum = function(separator){
        var tokens = this.split(separator);
        var obj = {}
        for (var i=0; i< tokens.length; i++ ){
            obj[i] = tokens[i];
        return obj;
    
  4. splitlines(s)
    String.prototype.splitlines = function(s) {
      return s.split('\n') 
    
  5. rsplit(sep, maxsplit)
    String.prototype.rsplit = function(sep, maxsplit) {
      var split = this.split(sep);
      return maxsplit ? [ split.slice(0, -maxsplit).join(sep) ].concat(split.slice(-maxsplit)) : split;
    };