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.1.4
  • 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.

Getting Started

Install the module with npm:

npm i digits --save

Or install with Bower:

bower install digits

Usage

var digits = require('digits');

var foo = 'path/to/010bar.md'
digits.pad(foo);
digits.strip(foo);

Methods

pad

Pad a string with numbers

var digits = require('digits');

var foo = 'path/to/010bar.md'
digits.strip(foo);
// => "bar.md"
pad options
digits

Type: Number Default: 4

The number of digits to pad. By default this is set to 4. Example 0001.

Example:

var digits = require('digits');
var arr = [1, 2, 3...1001];
console.log(digits.pad(arr, {digits: 6}));
// => 000001, 000002, 000003, 000004...
auto

Type: Number Default: undefined

Pass in the length of an array to automatically calculate the number of zeros to pad. If no length is passed in, the value from the digits option will be used.

Example:

var digits = require('digits');

var arr = [1, 2, 3...1001];
var len = arr.length;

console.log(digits.pad(arr, {auto: len}));
// => 0001, 0002, 0003, 0004...

stripleft

Strip leading numbers from a string.

var digits = require('digits');
console.log(digits.stripleft('010foo.md'));
// => "foo.md"

stripright

Strip trailing numbers from a string.

var digits = require('digits');
console.log(digits.stripright('bar010.md'));
// => "bar.md"

countleft

Count leading numbers in a string.

var digits = require('digits');
console.log(digits.countleft('010foo.md'));
// => "3"

countright

Count trailing numbers in a string.

var digits = require('digits');
console.log(digits.countright('bar010.md'));
// => "3"

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Author

License

Copyright (c) 2013 Jon Schlinkert Licensed under the MIT license.

Keywords

FAQs

Package last updated on 22 Jan 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