string-pad-start-x

2.1.2 • Public • Published

Travis status Dependency status devDependency status npm version jsDelivr hits bettercodehub score Coverage Status

string-pad-start-x

Pads a string with another string (repeated, if needed).

module.exports(string, targetLength, [padString])string

This method pads the current string with another string (repeated, if needed) so that the resulting string reaches the given length. The padding is applied from the start (left) of the current string.

Kind: Exported function
Returns: string - A String of the specified length with the pad string applied from the start.
Throws:

  • TypeError If target is null or undefined.
Param Type Description
string string The string to pad.
targetLength number The length of the resulting string once the current string has been padded. If the value is lower than the current string's length, the current string will be returned as is.
[padString] string The string to pad the current string with. If this string is too long to stay within the target length, it will be truncated and the left-most part will be applied. The default value for this parameter is " " (U+0020).

Example

import padStart from 'string-pad-start-x';
 
console.log(padStart('a', 3, 'b')); // 'bba'
console.log(padStart('a', 3)); // '  a'
console.log(padStart('a', 2, 'bc')); // 'ba'

Package Sidebar

Install

npm i string-pad-start-x

Weekly Downloads

104

Version

2.1.2

License

MIT

Unpacked Size

253 kB

Total Files

11

Last publish

Collaborators

  • xotic750