mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
789 B
32 lines
789 B
9 years ago
|
var createPadding = require('./_createPadding'),
|
||
|
toString = require('./toString');
|
||
10 years ago
|
|
||
|
/**
|
||
|
* Pads `string` on the left side if it's shorter than `length`. Padding
|
||
|
* characters are truncated if they exceed `length`.
|
||
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
|
* @category String
|
||
|
* @param {string} [string=''] The string to pad.
|
||
|
* @param {number} [length=0] The padding length.
|
||
|
* @param {string} [chars=' '] The string used as padding.
|
||
|
* @returns {string} Returns the padded string.
|
||
|
* @example
|
||
|
*
|
||
9 years ago
|
* _.padStart('abc', 6);
|
||
10 years ago
|
* // => ' abc'
|
||
|
*
|
||
9 years ago
|
* _.padStart('abc', 6, '_-');
|
||
10 years ago
|
* // => '_-_abc'
|
||
|
*
|
||
9 years ago
|
* _.padStart('abc', 3);
|
||
10 years ago
|
* // => 'abc'
|
||
|
*/
|
||
9 years ago
|
function padStart(string, length, chars) {
|
||
|
string = toString(string);
|
||
|
return createPadding(string, length, chars) + string;
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
module.exports = padStart;
|