
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Utility class that extends Array, works with node 10
npm i goku-array
OR
yarn add goku-array
import GokuArray from 'goku-array';
const arrayOfPrimitives = [1, 2, 2, 3, 3, 4, 1];
const arrayOfObjects = [
{
id: 1,
text: 'sample'
},
{
id: 1,
text: 'sample'
},
{
id: 2,
text: 'sample'
},
{
id: 1,
text: 'sample'
},
];
// make an array of primitives unique
const arr = new GokuArray(arrayOfPrimitives);
const newUniqueArray = arr.unique() // [1, 2, 3, 4]
// make an array of objects unique passing a function if given the right field to filter
const arr = new GokuArray(arrayOfObjects);
let newUniqueArray = arr.unique(({ id }) => id) // [{ id: 1, text: 'sample' }, { id: 2, text: 'sample' }]
newUniqueArray = arr.unique(({ text }) => text) // [{ id: 1, text: 'sample' }]
const arrayOne = [1, 2, 2, 3, 3, 4, 1];
const arrayTwo = [1, 3, 7, 2, 5];
// find the difference in 2 arrays
// result is an object
const arr = new GokuArray(arrayOne);
const objDiff = arr.diff(arrayTwo)
console.log(objDiff)
// {
// additional: [7, 5],
// missing: [4],
// common: [1, 2, 3]
// }
const arrayOne = [1, 2, 2, 3, 3, 4, 1];
const arrayTwo = [1, 3, 7, 2, 5];
// find the missing item in the second array
const arr = new GokuArray(arrayOne);
const arrDiff = arr.missingFrom(arrayTwo)
console.log(arrDiff)
// [4]
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve(true), ms * 1000));
}
const simpleArray = [1, 2, 3]
// await for the promises to resolve'
const arr = new GokuArray(simpleArray)
const newArr = await arr.asyncMap(item => timeout(item))
console.log(newArray)
// [true, true, true]
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve(ms), ms * 1000))
}
const simpleArray = [1, 2, 3]
// await for the promises to resolve
const arr = new GokuArray(simpleArray)
const newArr = await arr.asyncFilter(async item => {
const obj = await timeout(item)
return obj === item
})
console.log(newArr)
// [1, 2, 3]
const arrayOfMixed = [1, 2, { id: 'one', text: 'same' }, 3, 3, 4, 1]
const arrayOfObjects = [
{
id: 'one',
text: 'sample #1'
},
{
id: 'one',
text: 'sample #2'
},
{
id: 'one',
text: 'sample #3'
},
{
id: 'two',
text: 'sample #4'
},
{
__id: 'two',
text: 'sample #4'
}
]
let arr = new GokuArray(arrayOfMixed)
let newGroupedArray = arr.groupBy('id')
// newGroupedArray equals to {
// "one": [
// {
// "id": "one",
// "text": "same",
// },
// ],
// })
arr = new GokuArray(arrayOfObjects)
newGroupedArray = arr.groupBy('id')
// newGroupedArray equals to {
// "one": [
// {
// "id": "one",
// "text": "same",
// "text": "sample #1",
// }, {
// "id": "one",
// "text": "sample #2",
// },
// {
// "id": "one",
// "text": "sample #3",
// },
// ],
// "two": [
// {
// "id": "two",
// "text": "sample #4",
// },
// ],
// }
You may sort numbers, strings and objects
const arrayOfNumbers = [2, 1, 3]
const arrayOfStrings = ['a', 'c', 'b']
const arrayOfObjects = [{ id: 1, text: 'a' }, { id: 3, text: 'c' }, { id: 2, text: 'b' }]
// Numbers
// array of numbers ascending
let arr = new GokuArray(arrayOfNumbers)
arr.sortItems()
// [1, 2, 3]
arr = new GokuArray(arrayOfNumbers)
arr.sortItems({ ordering: 'ASC' })
// [1, 2, 3]
// array of numbers descending'
let arr = new GokuArray(arrayOfNumbers)
arr.sortItems({ ordering: 'DESC' })
// [3, 2, 1]
// Strings
// array of strings ascending
let arr = new GokuArray(arrayOfStrings)
arr.sortItems()
// ['a', 'b', 'c']
arr = new GokuArray(arrayOfStrings)
arr.sortItems({ ordering: 'ASC' })
// ['a', 'b', 'c']
// array of strings descending
let arr = new GokuArray(arrayOfStrings)
arr.sortItems({ ordering: 'DESC' })
// ['c', 'b', 'a']
// Objects
// array of objects ascending by field type of number
let arr = new GokuArray(arrayOfObjects)
arr.sortItems({ field: 'id' })
// [{ id: 1 }, { id: 2 }, { id: 3 }]
arr = new GokuArray(arrayOfObjects)
arr.sortItems({ ordering: 'ASC', field: 'id' })
// [{ id: 1 }, { id: 2 }, { id: 3 }]
// array of objects descending by field type of number
let arr = new GokuArray(arrayOfObjects)
arr.sortItems({ ordering: 'DESC', field: 'id' })
// [{ id: 3 }, { id: 2 }, { id: 1 }]
// array of objects ascending by field type of string
let arr = new GokuArray(arrayOfObjects)
arr.sortItems({ field: 'text' })
// [{ text: 'a' }, { text: 'b' }, { text: 'c' }]
arr = new GokuArray(arrayOfObjects)
arr.sortItems({ ordering: 'ASC', field: 'text' })
// [{ text: 'a' }, { text: 'b' }, { text: 'c' }]
// array of objects descending by field type of strings
let arr = new GokuArray(arrayOfObjects)
arr.sortItems({ ordering: 'DESC', field: 'text' })
// [{ text: 'c' }, { text: 'b' }, { text: 'a' }]
const array = [1, 2, 2, 3, 3, 4, 1];
// return plain array
const arr = new GokuArray(array);
arr.toArray() // will return native Array and pass deep equality check for Array
GokuArray inherits all Array built-in methods
const arrayOfPrimitives = [1, 2, 2, 3, 3, 4, 1];
const gokuArr = new GokuArray(arrayOfPrimitives);
console.log(Array.isArray(gokuArr)) // true
const arr = new GokuArray(arrayOfPrimitives);
const newArr = arr.filter(item => item === 1)
console.log(newArray) // [1, 1]
const array = [1, 2, 2, 3, 3, 4, 1];
// chain own methods
const arr = new GokuArray(array);
const uniqueSortedPlainArray = arr.unique().sortItems().toArray() // works
// chain onwn methods and array build-in methods
const arr = new GokuArray(array);
const uniqueSortedPlainArray = arr.unique().map(i => i).filter(i => !!i).sortItems().sort().toArray().sort() // works
const arr = new GokuArray(array);
// .map(), .filter(), .sort(), etc. => GokuArray
// .asyncMap(), .asyncFilter, .unique(), .missingFrom() => GokuArray
// .diff() => Object
// .toArray() => Array
arr.unique().map(i => i).sortItems() // works
arr.unique().map(i => i) // works
arr.unique().toArray().map(i => i) // works
arr.unique().toArray().unique(i => i) // does not work
const arr = new GokuArray(array, true);
// .map(), .filter(), .sort(), etc. => Array
// .asyncMap(), .asyncFilter, .unique(), .missingFrom() => GokuArray
// .diff() => Object
// .toArray() => Array
arr.unique().map(i => i).sortItems() // does not work
arr.unique().map(i => i) // works
arr.unique().toArray().map(i => i) // works
arr.unique().toArray().unique(i => i) // does not work
FAQs
Extended array
The npm package goku-array receives a total of 118 weekly downloads. As such, goku-array popularity was classified as not popular.
We found that goku-array 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.