
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
(c)Bumblehead, 2014 MIT-license
Accumulate values asynchronously.
When looping through values in an array to perform async operations, you may be using boilerplate like this:
function collectAsync (arr, fn) {
var newarr = [];
(function next (x) {
if (!x--) return fn(null, newarr);
requestDataForElem(arr[x], function (err, res) {
if (err) return fn(err);
newarr.push(res);
next(x);
});
}(arr.length));
}
But usually more boilerplate is necessary. The function is called frequently and to avoid exeeding stack limits a setTimeout
. Some logic is added to throw an error when the given array is invalid. The order of array traversal is changed. With more boilerplate the role of the function is harder to understand.
With accumasync
some of the boilerplate is removed traversal order is easily changed and an error is thrown for an invalid array. The function above becomes this:
function collectAsync (arr, fn) {
accumasync.arr(arr, [], function (elem, index, accumarr, next) {
requestDataForElem(elem, function (err, res) {
if (err) return fn(err);
accumarr.push(res);
next(null, accumarr);
});
}, fn);
}
accumasync
traverses array elements, object keys and number sequences.
accumasync
methods share the same implementation and interface details. The following parameters are passed to accumulator methods:
startvals= Array | Object | Number target element for the animation
accumvals= * the reference to this value is passed to each callback function it may be redefined with the accumulated values
fn= Function function is called for each item and the body of it may perform an async operation to obtain new values
the fn function is called like this:
fn(elem, index, accumvals, nextfn)
exitfn= Function
function is called at the end of traversal and may be called to prematurely end traversal
the exitfn function is called like this:
exitfn(err, accumvals)
accumasync.arr( arr, accum, fn, exitfn )
traverse array elements in reverse order
accumasync.arr(arr, [], function (elem, index, accumarr, next) {
requestDataForElem(elem, function (err, res) {
if (err) return next(err);
accumarr.push(res);
next(null, accumarr);
});
}, exitfn);
accumasync.arrf( arr, accum, fn, exitfn )
traverse array elements in forward order
accumasync.arrf(arr, [], function (elem, index, accumarr, next) {
requestDataForElem(elem, function (err, res) {
if (err) return next(err);
accumarr.push(res);
next(null, accumarr);
});
}, exitfn);
accumasync.obj( arr, accum, fn, exitfn )
traverse object keys in reverse order
accumasync.obj(obj, [], function (elem, index, accumarr, next) {
requestDataForElem(obj[elem], function (err, res) {
if (err) return next(err);
accumarr.push(res);
next(null, accumarr);
});
}, exitfn);
accumasync.objf( arr, accum, fn, exitfn )
traverse object keys in forward order
accumasync.obj(obj, [], function (elem, index, accumarr, next) {
requestDataForElem(obj[elem], function (err, res) {
if (err) return next(err);
accumarr.push(res);
next(null, accumarr);
});
}, exitfn);
accumasync.num( arr, accum, fn, exitfn )
traverse numbers in reverse order
accumasync.num(num, [], function (elem, index, accumarr, next) {
requestDataForElem(num, function (err, res) {
if (err) return next(err);
accumarr.push(res);
next(null, accumarr);
});
}, exitfn);
accumasync.numf( arr, accum, fn, exitfn )
traverse numbers in forward order
accumasync.numf(num, [], function (elem, index, accumarr, next) {
requestDataForElem(num, function (err, res) {
if (err) return next(err);
accumarr.push(res);
next(null, accumarr);
});
}, exitfn);
accumasync
may be downloaded directly or installed through npm
.
$ npm install accumasync
$ git clone https://github.com/iambumblehead/accumasync.git
to run tests, use npm test
from a shell.
$ npm test
(The MIT License)
Copyright (c) 2014 Bumblehead chris@bumblehead.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
accumulate values asynchronously
The npm package accumasync receives a total of 1 weekly downloads. As such, accumasync popularity was classified as not popular.
We found that accumasync 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
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.