Nodejs String Justify rightj(n)

Here you can find the source of rightj(n)

Method Source Code

/*//from   w w w  . ja v a  2s .com
   
   Description:
      Returns the substring counting from right to left
   
   Syntax:
      String.right( n)
   
   Returns:
      The rightmost n characters
   
   Sample:
      "I am the best and girls love me!".right(8) == "love me!"
*/
String.prototype.right   = jCube.String.right   = function ( n) {
   return this.substring( this.length-n);
}

Related

  1. rjust( width, padding )
    String.prototype.rjust = function( width, padding ) {
      padding = padding || " ";
      padding = padding.substr( 0, 1 );
      if( this.length < width )
        return padding.repeat( width - this.length ) + this;
      else
        return this;
    
  2. rjust(length, padding)
    String.prototype.rjust = function (length, padding) {
      var paddedString = this.slice();
      while (paddedString.length < length) {
        paddedString = padding + paddedString;
      return paddedString;
    };
    function setDefaultInputDate (dateInputSelector) {
      var input = $(dateInputSelector);
    ...
    
  3. rjust(num, padding)
    String.prototype.rjust = function(num, padding){
        if(!padding) padding = ' ';
        var s = this.toString();
        if(1 != padding.length) throw new Error('Padding must be one character.');
        if(s.length >= num) return s;
        for(var i=0; i<=num-s.length; i++)
            s = padding + s;
        return s;
    };
    ...
    
  4. rjust(width, padding)
    String.prototype.rjust = function(width, padding) {
        padding = padding || " ";
        padding = padding.substr(0, 1);
        if (this.length < width) {
            return padding.repeat(width - this.length) + this;
        } else {
            return this;
    
  5. rightJustify( length, char )
    String.prototype.rightJustify = function( length, char ) {
      var fill = [];
      while ( fill.length + this.length < length ) {
        fill[fill.length] = char;
      return this + fill.join('');
    };