Nodejs String Insert insert(start, new_string)

Here you can find the source of insert(start, new_string)

Method Source Code

/*//from  www  .j  av a2  s.  c  o m
   Native type extentions.
   Niels Groot Obbink

   Extend some native JavaScript types with useful methods.
*/



// Insert a string at the [start] character position.
String.prototype.insert = function(start, new_string)
{
   return this.slice(0, start) + new_string + this.slice(start);
};


// Remove [length] characters from [start] and insert [insert] at position [start].
String.prototype.splice = function(start, length, insert)
{
   return this.substring(0, start) + insert + this.substring(start + length);
};


// Copy properties from [other] to [this] object.
Object.prototype.extend = function(other)
{
   let property;

   for (property in other)
   {
      if( other.hasOwnProperty(property) && other[property] != null )
      {
         this[property] = other[property];
      }
   }

   return this;
};

Related

  1. insert(index, string)
    String.prototype.insert = function (index, string) {
      if (index > 0)
        return this.substring(0, index) + string + this.substring(index, this.length);
      else
        return string + this;
    };
    
  2. insert(index, string)
    Object.size = function(obj) {
        var size = 0, key;
        for (key in obj) {
            if (obj.hasOwnProperty(key)) size++;
        return size;
    };
    String.prototype.insert = function (index, string) {
      if (index > 0)
    ...
    
  3. insert(index, string)
    String.prototype.insert = function (index, string) {
      if (index > 0) {
        return this.substring(0, index) + string + this.substring(index, this.length);
      else {
        return string + this;
    };
    
  4. insert(start, new_string)
    String.prototype.insert = function(start, new_string)
      return this.slice(0, start) + new_string + this.slice(start);
    };
    String.prototype.splice = function(start, length, insert)
      return this.substring(0, start) + insert + this.substring(start + length);
    };
    Object.prototype.extend = function(other)
    ...
    
  5. insert(start, new_string)
    String.prototype.insert = function(start, new_string)
      return this.slice(0, start) + new_string + this.slice(start);
    };
    String.prototype.splice = function(start, length, insert)
      return this.substring(0, start) + insert + this.substring(start + length);
    };
    
  6. insert(text,at)
    String.prototype.insert = function(text,at) {
        if(at == null || at > this.length)
            at = this.length;
        else if(at < 0)
            at = 0;
        return this.substring(0,at)+text+this.substring(at);
    
  7. insert(value, position)
    String.prototype.insert = String.prototype.insert || function (value, position) {
      if (!value) return this;
      position = position === 'end' ? this.length : position === 'start' ? 0 : position || 0
      return this.slice(0, position) + value + this.slice(position)