Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including left-pad with all npm packages installed. Try it out:

const leftPad = require('left-pad') leftPad('foo', 4)

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

left-pad v1.3.0

String left pad


String left pad

Build Status


$ npm install left-pad


const leftPad = require('left-pad')

leftPad('foo', 5)
// => "  foo"

leftPad('foobar', 6)
// => "foobar"

leftPad(1, 2, '0')
// => "01"

leftPad(17, 5, 0)
// => "00017"

NOTE: The third argument should be a single char. However the module doesn't throw an error if you supply more than one chars. See #28.

NOTE: Characters having code points outside of BMP plan are considered a two distinct characters. See #58.


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free