Nodejs String Split splitChars(len)

Here you can find the source of splitChars(len)

Method Source Code

String.prototype.splitChars = function(len) {
a = this.split('');
res = [];/*from ww  w.j  a  v  a  2 s .  com*/
i = 0;
[].forEach.call(a, function(b, c) {
   if (c % len == 0) {
      i++;
      res.push([])
   }
   res[i - 1].push(b);
});
f = [];
res.forEach(function(d) {
   f.push(d.join(''));
   return true;
});
g =f.join('\n');
return g;
};

Related

  1. splitANArguments()
    String.prototype.splitANArguments = function(){
      var r = [];
      var t = '';
      var isQuote = false;
      for(var i = 0; i < this.length; i++){
        if(!isQuote && this.charAt(i) == ' '){
          r.push(t);
          t = '';
        else{
          if(this.charAt(i) == '"'){
            t += this.charAt(i);
            isQuote = !isQuote;
          else{
            t += this.charAt(i);
      r.push(t);
      return r;
    
  2. splitAndTrim($delimiter, $limit)
    String.prototype.splitAndTrim = function ($delimiter, $limit) {
      var $ss = this.split($delimiter, $limit);
      for (var $i = 0; $i < $ss.length; $i++) {
        $ss[$i] = $ss[$i].trim();
      return $ss;
    };
    
  3. splitBy()
    String.prototype.splitBy = function(){
      return splitAll(this, Array.slice(arguments));
    };
    
  4. splitBy(delimiter)
    String.prototype.splitBy = function (delimiter) {
      var 
        delimiterPATTERN = '(' + delimiter + ')', 
        delimiterRE = new RegExp(delimiterPATTERN, 'g');
      return this.split(delimiterRE).reduce((chunks, item) => {
        if (item.match(delimiterRE)){
          chunks.push(item)
        } else {
          chunks[chunks.length - 1] += item
    ...
    
  5. splitByNum(num)
    String.prototype.splitByNum = function(num){
      return this.split('').reduce((a,b)=>{
        const alen = a[a.length-1]
        alen.length%2==0&&alen.length!=0?a.push(b):a[a.length-1] = alen+b+''
        return a
      },[''])
    
  6. splitFirst(separator)
    String.prototype.splitFirst = function (separator) {
        var si = this.split(separator);
        var output = [];
        output.push(si[0]);
        if (si.length>1) {
            si.shift();
            output.push(si.join(separator));
        return output;
    ...
    
  7. splitFirst(x)
    String.prototype.splitFirst = function(x){
      var index = this.indexOf(x);
      return [
        this.substring(0, index),
        this.substring(index + x.length)
      ]
    };
    
  8. splitLast(separator)
    String.prototype.splitLast = function(separator) {
        var si = this.split(separator);
        var output = [];
        var last = si.pop();
        if (si.length > 0) {
            output.push(si.join(separator));
        if (last) {
            output.push(last);
    ...
    
  9. splitLength(size)
    String.prototype.splitLength = function(size) {
        var regex = new RegExp('.{1,' + size + '}', 'g');
        return this.match(regex);
    };