just-left-pad
TypeScript icon, indicating that this package has built-in type declarations

3.2.0 • Public • Published

just-left-pad

Part of a library of zero-dependency npm modules that do just do one thing. Guilt-free utilities for every occasion.

🍦 Try it

npm install just-left-pad
yarn add just-left-pad

Add characters to the left of a string such that its total length is n

import leftPad from 'just-left-pad';

leftPad('hello', 9); // '    hello'
leftPad('hello', 3); // 'hello'
leftPad('hello', 9, '.'); // '....hello'
leftPad('hello', 9, '..'); // '....hello'
leftPad('hello', 10, 'ab'); // 'bababhello'
leftPad('hello', 9, '\uD83D\uDC04'); // '🐄🐄🐄🐄hello'
leftPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // '🐄🐑🐄🐑🐄hello'
leftPad('hello', 7, '🐄'), // '🐄🐄hello'
leftPad(null, 7); // throws
leftPad([], 4, '*'); // throws
leftPad('hello', 4, true); // throws
leftPad('hello', -4, true); // throws  
leftPad('hello', 2.3, true); // throws    

Package Sidebar

Install

npm i just-left-pad

Weekly Downloads

57

Version

3.2.0

License

MIT

Unpacked Size

8.54 kB

Total Files

10

Last publish

Collaborators

  • angus-c