left-pad-logarithmic

String left pad, logarthimic time

Usage no npm install needed!

<script type="module">
  import leftPadLogarithmic from 'https://cdn.skypack.dev/left-pad-logarithmic';
</script>

README

Summary

String left pad.

This behaves exactly like the famed left-pad, but it runs in O(lg n). Useful for left-padding in larger, web-scale situations.

Install

$ npm install left-pad-logarithmic

Usage

leftpad = require('left-pad-logarithmic')

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

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

leftpad(1, 2, 0)
// => "01"

leftpad('foo', 15)
// => "            foo"