What is pad-left?
The pad-left npm package is a utility that allows you to pad the left side of a string with a specified character or set of characters until the string reaches a desired length. This can be useful for formatting output, aligning text, or ensuring consistent string lengths.
What are pad-left's main functionalities?
Basic Padding
Pads the left side of the string '123' with spaces until the total length is 5.
const padLeft = require('pad-left');
const result = padLeft('123', 5);
console.log(result); // ' 123'
Custom Padding Character
Pads the left side of the string '123' with the character '0' until the total length is 5.
const padLeft = require('pad-left');
const result = padLeft('123', 5, '0');
console.log(result); // '00123'
Padding with Multiple Characters
Pads the left side of the string '123' with the string 'abc' repeated until the total length is 7.
const padLeft = require('pad-left');
const result = padLeft('123', 7, 'abc');
console.log(result); // 'abca123'
Other packages similar to pad-left
left-pad
The left-pad package provides similar functionality to pad-left, allowing you to pad the left side of a string with a specified character or set of characters. It is widely known and used in the JavaScript community.
string-pad
The string-pad package offers more comprehensive padding options, including both left and right padding. It allows for more flexibility in padding strings compared to pad-left.
pad
The pad package provides both left and right padding functionalities. It is a versatile package that can be used for various string padding needs, making it a more general-purpose tool compared to pad-left.
pad-left
Left pad a string with zeros or a specified string. Fastest implementation.
Install with npm
npm i pad-left --save
Usage
var pad = require('pad-left');
pad('abc', 10);
pad('abc', 10, '~');
Related projects
Other awesome node.js libraries for padding and aligning strings.
- align-text: Align the text in a string.
- center-align: Center-align the text in a string.
- justified: Wrap words to a specified length and justified the text.
- pad-right: Right pad a string with zeros or a specified string. Fastest implementation.
- repeat-string: Repeat the given string n times. Fastest implementation for repeating a string.
- right-align: Right-align the text in a string.
- word-wrap: Wrap words to a specified length.
Running tests
Install dev dependencies:
npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Author
Jon Schlinkert
License
Copyright (c) 2014-2015 Jon Schlinkert
Released under the MIT license.
This file was generated by verb-cli on April 27, 2015.