npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pad-left

v2.1.0

Published

Left pad a string with zeros or a specified string. Fastest implementation.

Downloads

800,587

Readme

pad-left NPM version NPM downloads Build Status

Left pad a string with zeros or a specified string. Fastest implementation.

You might also be interested in word-wrap.

Install

Install with npm:

$ npm install pad-left --save

Usage

var pad = require('pad-left');
pad(  '4', 4, '0') // 0004
pad( '35', 4, '0') // 0035
pad('459', 4, '0') // 0459

Benchmarks

Benchmarks for node.js v6.1.0 versus left-pad.

# benchmark/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)

# benchmark/fixtures/10.js (32 bytes)
  pad-left x 13,305,123 ops/sec ±1.53% (84 runs sampled)
  left-pad x 6,979,536 ops/sec ±1.13% (84 runs sampled)

# benchmark/fixtures/100-custom-char.js (38 bytes)
  pad-left x 14,227,637 ops/sec ±1.41% (81 runs sampled)
  left-pad x 1,352,240 ops/sec ±1.51% (86 runs sampled)

# benchmark/fixtures/100.js (34 bytes)
  pad-left x 15,664,561 ops/sec ±0.99% (83 runs sampled)
  left-pad x 1,247,316 ops/sec ±0.96% (87 runs sampled)

# benchmark/fixtures/1000-custom-char.js (40 bytes)
  pad-left x 15,210,294 ops/sec ±1.15% (87 runs sampled)
  left-pad x 159,958 ops/sec ±1.01% (88 runs sampled)

# benchmark/fixtures/1000.js (35 bytes)
  pad-left x 14,157,425 ops/sec ±1.10% (88 runs sampled)
  left-pad x 143,805 ops/sec ±1.08% (87 runs sampled)

Benchmarks for node.js v6.1.0 versus stevemao/left-pad.

# 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:

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:

$ npm install verb && npm run docs

Or, if verb is installed globally:

$ verb

Running tests

Install dev dependencies:

$ 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.