Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Module for returning arrays with a specific length by padding values.
var pad = require('array-pad');
var arr = pad([], 3, null); // => [null, null, null]
arr = pad(arr, 5, 0); // => [null, null, null, 0, 0];
To install array-pad
in a Node application use npm.
$ npm install array-pad
No tests available for the browser but you may try using it via webpack.
$ webpack index.js array-pad.js
To run tests use npm.
$ npm install
$ npm test
Padding an array
is simple as passing the desired length
and an optional value
to pad with. If no value
is given, padded items will be set to undefined
by default.
var array = pad([], 2); // => [undefined, undefined]
pad(array, 4, null); // => [undefined, undefined, null, null]
pad(array, 1, false); // => [undefined, undefined, null, null]
Pad, by default, pads value
s to the right side of the array
via the .push()
method. To pad left, perform .unshift()
, pass then length
as a negative integer.
pad([1,2,3], -5, 0); // => [0, 0, 1, 2, 3]
Pad will always create a new instance of the array
passed in. If augmentation to the original instance is required, pass the first parameter as true
.
var arr = [];
var res = pad(true, arr, 3);
res === arr; // => true
Copyright (c) 2015 Christopher Turner
FAQs
Module for returning arrays with a specific length by padding values.
The npm package array-pad receives a total of 1,720 weekly downloads. As such, array-pad popularity was classified as popular.
We found that array-pad 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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.