JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 85
  • Score
    100M100P100Q72495F

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.

Package Exports

  • digits

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (digits) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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 install digits

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.