Left pad a string with zeros or a specified string. Fastest implementation.
Installations
npm install pad-left
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=0.10.0
Node Version
5.5.0
NPM Version
3.6.0
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
jonschlinkert
Download Statistics
Total Downloads
51,639,512
Last Day
40,131
Last Week
173,208
Last Month
765,488
Last Year
11,128,625
GitHub Statistics
44 Stars
38 Commits
8 Forks
3 Watching
1 Branches
5 Contributors
Package Meta Information
Latest Version
2.1.0
Package Id
pad-left@2.1.0
Size
3.03 kB
NPM Version
3.6.0
Node Version
5.5.0
Publised On
07 May 2016
Total Downloads
Cumulative downloads
Total Downloads
51,639,512
Last day
2%
40,131
Compared to previous day
Last week
-8.8%
173,208
Compared to previous week
Last month
14.9%
765,488
Compared to previous month
Last year
-6%
11,128,625
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
6
pad-left
![Build Status](https://img.shields.io/travis/jonschlinkert/pad-left.svg?style=flat)
Left pad a string with zeros or a specified string. Fastest implementation.
You might also be interested in word-wrap.
Install
Install with npm:
1$ npm install pad-left --save
Usage
1var pad = require('pad-left'); 2pad( '4', 4, '0') // 0004 3pad( '35', 4, '0') // 0035 4pad('459', 4, '0') // 0459
Benchmarks
Benchmarks for node.js v6.1.0 versus left-pad.
1# benchmark/fixtures/10-custom-char.js (37 bytes) 2 pad-left x 14,940,947 ops/sec ±0.81% (87 runs sampled) 3 left-pad x 7,901,604 ops/sec ±1.17% (86 runs sampled) 4 5# benchmark/fixtures/10.js (32 bytes) 6 pad-left x 13,305,123 ops/sec ±1.53% (84 runs sampled) 7 left-pad x 6,979,536 ops/sec ±1.13% (84 runs sampled) 8 9# benchmark/fixtures/100-custom-char.js (38 bytes) 10 pad-left x 14,227,637 ops/sec ±1.41% (81 runs sampled) 11 left-pad x 1,352,240 ops/sec ±1.51% (86 runs sampled) 12 13# benchmark/fixtures/100.js (34 bytes) 14 pad-left x 15,664,561 ops/sec ±0.99% (83 runs sampled) 15 left-pad x 1,247,316 ops/sec ±0.96% (87 runs sampled) 16 17# benchmark/fixtures/1000-custom-char.js (40 bytes) 18 pad-left x 15,210,294 ops/sec ±1.15% (87 runs sampled) 19 left-pad x 159,958 ops/sec ±1.01% (88 runs sampled) 20 21# benchmark/fixtures/1000.js (35 bytes) 22 pad-left x 14,157,425 ops/sec ±1.10% (88 runs sampled) 23 left-pad x 143,805 ops/sec ±1.08% (87 runs sampled)
Benchmarks for node.js v6.1.0 versus stevemao/left-pad.
1# benchmark/fixtures/10-custom-char.js (37 bytes) 2 pad-left x 13,251,037 ops/sec ±1.40% (84 runs sampled) 3 left-pad x 10,745,530 ops/sec ±1.18% (86 runs sampled) 4 5# benchmark/fixtures/10.js (32 bytes) 6 pad-left x 13,644,357 ops/sec ±1.33% (87 runs sampled) 7 left-pad x 20,107,245 ops/sec ±1.00% (88 runs sampled) 8 9# benchmark/fixtures/100-custom-char.js (38 bytes) 10 pad-left x 15,650,330 ops/sec ±1.01% (86 runs sampled) 11 left-pad x 9,706,877 ops/sec ±1.13% (87 runs sampled) 12 13# benchmark/fixtures/1000-custom-char.js (40 bytes) 14 pad-left x 17,255,593 ops/sec ±0.99% (88 runs sampled) 15 left-pad x 6,312,637 ops/sec ±1.16% (87 runs sampled) 16 17# benchmark/fixtures/1000.js (35 bytes) 18 pad-left x 15,679,410 ops/sec ±0.99% (90 runs sampled) 19 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:
1$ npm install verb && npm run docs
Or, if verb is installed globally:
1$ verb
Running tests
Install dev dependencies:
1$ npm install -d && npm test
Author
Jon Schlinkert
License
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb, v0.9.0, on May 07, 2016.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
Found 3/28 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 5 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More