Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
A library for array functions in Array.prototype
npm install array-lib
const arrayLib = require("array-lib");
clone
deep copy an array
let arr = [1,2,3];
let clone_arr = arr.clone();
print
arr.print();//=> [1,2,3]
"hello".print();// =>hello
(123).print();//=>123
{a:12}.print();//=>{a:12}
max
Retrun max value from array
arr.max().print();
maxIndex
Returns index of max value in array:
arr.maxIndex().print()
remove
Removes element at the specified position
arr.remove(0);
arr.print()//=> [2,3]
removeVal
Removes first or all values from array
let a = [1,2,3,4,4,5,5];
let remove_all_elements = true;
a.removeVal(4,remove_all_elements);
a.print();//=> [1,2,3,5,5];
count
Count how much times a element is in an array
let b = ["a","b","b","c","b"];
console.log(b.count("b"));//=> 3
replace
Replace elements in array
let c = [1,2,3,3,3,4,6,6,9];
c.replace(3,"d");
c.print();//=>[1,2,"d","d","d",4,6,6,9]
addUp
Add up all numbers in array
let d = [1,2,3,4,5];
d.addUp().print();//=> 15
matrix
Create a 2d array
let arr = Array.matrix(2,3,"fill")
arr.print();
//=>
//[
// [ 'fill', 'fill', 'fill' ],
// [ 'fill', 'fill', 'fill' ]
// ]
vector
Create an array
let arr = Array.vector(6,"fill");
arr.print();//=> ['fill', 'fill', 'fill','fill', 'fill', 'fill']
toArray
Create an array from a string
"hello ,world ,how ,are ,you".toArray().print();//=>
//[ 'hello', 'world', 'how', 'are', 'you' ]
multiplyMatrices
let b = [[1,2],[3,4]]
b.multiplyMatrices([[1,4],[6,7]]).print()
//=>[ [ 13, 18 ], [ 27, 40 ] ]
isMatrix
check if an array is a 2d matrix
let matrix = [
[0,1,2],
[3,4,5],
[6,7,8]
];
matrix.isMatrix().print()// => true
avrage
get Avrage from array
[1,2,3,4,5].avrage().print();//=> 3
pos
return first position of element in an array
[1,2,3,4,5].pos(4).print();//=>3
[1,2,3,4,5].pos(9).print();//=>false
getAllPos
Get all positions of element in array
let arr = [1,3,4,4,8,7,5,3,4];
b.getAllPos(4).print();//=> [2,3,8]
shuffle
shuffle an array
[1,2,3,4,5,6,7,8,9].shuffle().print();
//=> [ 7, 2, 9, 1, 6, 8, 3, 5, 4 ]
range
A function to create flexibly-numbered lists of integers
Array.range(10);
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Array.range(1, 11);
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Array.range(0, 30, 5);
//=> [0, 5, 10, 15, 20, 25]
Array.range(0, -10, -1);
//=> [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
Array.range(0);
//=> []
without
Returns a copy of the array with all instances of the values removed.
let a = [1,2,3,1,2,31,2,31,1,2,3,]
let b = a.without(1,2);
b.print();
//=>[ 3, 31, 31, 3 ]
FAQs
A library for array functions in Array.prototype
The npm package array-lib receives a total of 66 weekly downloads. As such, array-lib popularity was classified as not popular.
We found that array-lib 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.