Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
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.
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 the module with npm:
npm i digits --save
Or install with Bower:
bower install digits
var digits = require('digits');
var foo = 'path/to/010bar.md'
digits.pad(foo);
digits.strip(foo);
Pad a string with numbers
var digits = require('digits');
var foo = 'path/to/010bar.md'
digits.strip(foo);
// => "bar.md"
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...
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...
Strip leading numbers from a string.
var digits = require('digits');
console.log(digits.stripleft('010foo.md'));
// => "foo.md"
Strip trailing numbers from a string.
var digits = require('digits');
console.log(digits.stripright('bar010.md'));
// => "bar.md"
Count leading numbers in a string.
var digits = require('digits');
console.log(digits.countleft('010foo.md'));
// => "3"
Count trailing numbers in a string.
var digits = require('digits');
console.log(digits.countright('bar010.md'));
// => "3"
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.
Copyright (c) 2013 Jon Schlinkert Licensed under the MIT license.
FAQs
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.
The npm package digits receives a total of 12 weekly downloads. As such, digits popularity was classified as not popular.
We found that digits demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.