time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

repl.txt (2168B)


      1 
      2 {{alias}}( str, len[, options] )
      3     Pads a `string` such that the padded `string` has length `len`.
      4 
      5     Any padding which does not evenly divide available space is trimmed such
      6     that the returned string length is always `len`.
      7 
      8     If `len < str.length`, the input string is trimmed.
      9 
     10     Parameters
     11     ----------
     12     str: string
     13         Input string.
     14 
     15     len: integer
     16         Output string length.
     17 
     18     options: Object (optional)
     19         Options.
     20 
     21     options.lpad: string (optional)
     22         String used to left pad.
     23 
     24     options.rpad: string (optional)
     25         String used to right pad.
     26 
     27     options.centerRight: boolean (optional)
     28         Boolean indicating whether to center right in the event of a tie.
     29         Default: `false` (i.e., center left).
     30 
     31     Returns
     32     -------
     33     out: string
     34         Padded string.
     35 
     36     Examples
     37     --------
     38     // Standard usage:
     39     > var out = {{alias}}( 'a', 5 )
     40     'a    '
     41 
     42     // Left pad:
     43     > out = {{alias}}( 'a', 10, { 'lpad': 'b' })
     44     'bbbbbbbbba'
     45 
     46     // Right pad:
     47     > out = {{alias}}( 'a', 12, { 'rpad': 'b' })
     48     'abbbbbbbbbbb'
     49 
     50     // Center an input string:
     51     > var opts = { 'lpad': 'a', 'rpad': 'c' };
     52     > out = {{alias}}( 'b', 11, opts )
     53     'aaaaabccccc'
     54 
     55     // Left center:
     56     > opts.centerRight = false;
     57     > out = {{alias}}( 'b', 10, opts )
     58     'aaaabccccc'
     59 
     60     // Right center:
     61     > opts.centerRight = true;
     62     > out = {{alias}}( 'b', 10, opts )
     63     'aaaaabcccc'
     64 
     65     // Output string always length `len`:
     66     > opts = { 'lpad': 'boop', 'rpad': 'woot' };
     67     > out = {{alias}}( 'beep', 10, opts )
     68     'boobeepwoo'
     69 
     70     // Pad right, trim right:
     71     > out = {{alias}}( 'beep', 2 )
     72     'be'
     73 
     74     // Pad left, trim left:
     75     > opts = { 'lpad': 'b' };
     76     > out = {{alias}}( 'beep', 2, opts )
     77     'ep'
     78 
     79     // Pad both, trim both:
     80     > opts = { 'lpad': '@', 'rpad': '!' };
     81     > out = {{alias}}( 'beep', 2, opts )
     82     'ee'
     83 
     84     // Pad both, trim both starting from left:
     85     > out = {{alias}}( 'abcdef', 3, opts )
     86     'cde'
     87 
     88     // Pad both, trim both starting from right:
     89     > opts.centerRight = true;
     90     > out = {{alias}}( 'abcdef', 3, opts )
     91     'bcd'
     92 
     93     See Also
     94     --------
     95