What is left-pad?
The left-pad npm package is a simple utility that allows you to pad a string with characters to ensure it reaches a certain length. It is primarily used to add padding to the left side of a string.
What are left-pad's main functionalities?
String Padding
This feature allows you to pad a string with spaces or any other character to a certain length. It is useful for aligning text or ensuring that strings fit into a fixed-width layout.
"hello".padStart(10, ' '); // results in ' hello'
Other packages similar to left-pad
string-padding
This package offers similar functionality to left-pad, allowing for padding on both the left and right sides of a string. It provides more flexibility compared to left-pad.
pad
The pad package is another alternative that provides both left and right padding of strings. It is more versatile than left-pad as it supports padding on either side.
pad-left
Pad-left is specifically focused on left padding, similar to left-pad. However, it might have different implementation details or additional options.
left-pad
String left pad
Install
$ npm install left-pad
Usage
const leftPad = require('left-pad')
leftPad('foo', 5)
leftPad('foobar', 6)
leftPad(1, 2, '0')
leftPad(17, 5, 0)
NOTE: The third argument should be a single char
. However the module doesn't throw an error if you supply more than one char
s. See #28.
NOTE: Characters having code points outside of BMP plan are considered a two distinct characters. See #58.