Left pad a string with zeros or a specified string. Fastest implementation.
npm install pad-leftLeft pad a string with zeros or a specified string. Fastest implementation.
You might also be interested in word-wrap.
Install with npm:
``sh`
$ npm install pad-left --save
`js`
var pad = require('pad-left');
pad( '4', 4, '0') // 0004
pad( '35', 4, '0') // 0035
pad('459', 4, '0') // 0459
Benchmarks for node.js v6.1.0 versus left-pad.
`shbenchmark/fixtures/10-custom-char.js (37 bytes)
pad-left x 14,940,947 ops/sec ±0.81% (87 runs sampled)
left-pad x 7,901,604 ops/sec ±1.17% (86 runs sampled)
Benchmarks for node.js v6.1.0 versus stevemao/left-pad.
`sh
benchmark/fixtures/10-custom-char.js (37 bytes)
pad-left x 13,251,037 ops/sec ±1.40% (84 runs sampled)
left-pad x 10,745,530 ops/sec ±1.18% (86 runs sampled)benchmark/fixtures/10.js (32 bytes)
pad-left x 13,644,357 ops/sec ±1.33% (87 runs sampled)
left-pad x 20,107,245 ops/sec ±1.00% (88 runs sampled)benchmark/fixtures/100-custom-char.js (38 bytes)
pad-left x 15,650,330 ops/sec ±1.01% (86 runs sampled)
left-pad x 9,706,877 ops/sec ±1.13% (87 runs sampled)benchmark/fixtures/1000-custom-char.js (40 bytes)
pad-left x 17,255,593 ops/sec ±0.99% (88 runs sampled)
left-pad x 6,312,637 ops/sec ±1.16% (87 runs sampled)benchmark/fixtures/1000.js (35 bytes)
pad-left x 15,679,410 ops/sec ±0.99% (90 runs sampled)
left-pad x 6,439,580 ops/sec ±1.08% (86 runs sampled)
`Related projects
You might also be interested in these projects:
* align-text: Align the text in a string. | homepage
* center-align: Center-align the text in a string. | homepage
* justified: Wrap words to a specified length and justified the text. | homepage
* pad-right: Right pad a string with zeros or a specified string. Fastest implementation. | homepage
* repeat-string: Repeat the given string n times. Fastest implementation for repeating a string. | homepage
* right-align-keys: Right align the keys of an object. | homepage
* right-align-values: Right align the values of a given property for each object in an array. Useful… more | homepage
* right-align: Right-align the text in a string. | homepage
* right-pad-keys: Right pad the keys of an object. | homepage
* right-pad-values: Right pad the values of a given property for each object in an array. Useful… more | homepage
* word-wrap: Wrap words to a specified length. | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
Generate readme and API documentation with verb:
`sh
$ npm install verb && npm run docs
`Or, if verb is installed globally:
`sh
$ verb
`Running tests
Install dev dependencies:
`sh
$ npm install -d && npm test
``Jon Schlinkert
* github/jonschlinkert
* twitter/jonschlinkert
Copyright © 2016, Jon Schlinkert.
Released under the MIT license.
*
_This file was generated by verb, v0.9.0, on May 07, 2016._