Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

digits

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

digits

Pad numbers with zeros. Automatically pad the number of digits based on the length of the array, or explicitly pass in the number of digits to use.

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24
decreased by-60.66%
Maintainers
1
Weekly downloads
 
Created
Source

digits NPM version

Pad numbers with zeros. Automatically pad the number of digits based on the length of the array, or explicitly pass in the number of digits to use.

Install with npm

npm i digits --save

Run tests

npm test

Usage

var digits = require('digits');

API

digits

Left pad the given value with the specified number of zeros or alternate character.

  • value {String}
  • number {String}
  • returns {String} character
digits('abc', 10);
//=> '0000000000abc'

digits('abc', 10, '~');
//=> '~~~~~~~~~~abc'

.each

Pad left pad each value in the given array to align with the longest item/number in the array. Zeros are used by default, but a custom character can be passed as the second argument.

  • arr {Number}: The array of values to pad.
  • len {Number}: Amount to pad the number.
  • returns {String}: Padded number

Example

digits.each([1, 100, 1000])
//=> ['0001', '0100', '1000']

digits.each([a, bb, ccc], ' ')
//=> ['  a', ' bb', 'ccc']

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert
Released under the MIT license


This file was generated by verb on December 05, 2014. To update, run npm i -g verb && verb.

Keywords

FAQs

Package last updated on 05 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc