1 | /**
|
2 | * Pad space to fit length.
|
3 | * @function pad
|
4 | * @param {string} text - Text to space.
|
5 | * @param {number } len - Text length to fill.
|
6 | * @param {object} options - Optional settings.
|
7 | * @param {string} [option.space=' '] - Space letter to fill.
|
8 | * @returns {string} - Padded text.
|
9 | */
|
10 |
|
11 | ;
|
12 |
|
13 | var argx = require('argx');
|
14 |
|
15 | /** @lends pad */
|
16 | function pad(text, len, options) {
|
17 | var padding = '';
|
18 | var args = argx(arguments);
|
19 | text = args.shift('string');
|
20 | len = args.shift('number');
|
21 | options = args.pop('object') || {};
|
22 | var space = options.space || ' ';
|
23 | while (text.length + padding.length < len) {
|
24 | padding += space;
|
25 | }
|
26 | return text + padding;
|
27 | }
|
28 |
|
29 | module.exports = pad;
|