
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Allow perform every, filter, find, findIndex, forEach, map, reduce, reduceRight and some on array using Async callback
Purpose of this package is to provide async/await
callbacks for every
, filter
, find
, findIndex
, forEach
, map
, reduce
, reduceRight
and some
methods in Array.
const { AsyncRay } = require('async-ray');
async function dummy(element, needle) {
return Promise.resolve(element > needle);
}
const inputArray = [10, 20, 30, 40];
// Call Every method
const output = await AsyncRay(inputArray).aEvery(
async (i, index, collection) => {
// Dummy async function
return await dummy(i, 5);
}
);
console.log(output);
// Output is true
async function dummy(element, needle) {
return Promise.resolve(element > needle);
}
const inputArray = [1, 2, 3, 4];
// Call Filter method
const filterArray = await AsyncRay(inputArray).aFilter(
async (i, index, collection) => {
// Dummy async function
return await dummy(i, 2);
}
);
console.log(filterArray);
// Output is [3, 4]
Find will return the found value or undefined
async function dummy(element, needle) {
return Promise.resolve(element === needle);
}
const inputArray = [1, 2, 3, 4];
// Call Find method
const outputElement = await AsyncRay(inputArray).aFind(
async (i, index, collection) => {
return await dummy(i, 2);
}
);
console.log('Output is ', outputElement);
// Output is 2
FindIndex will return the index of found value or -1
async function dummy(element, needle) {
return Promise.resolve(element === needle);
}
const inputArray = [1, 2, 3, 4];
// Call Find method
const outputIndex = await AsyncRay(inputArray).aFindIndex(
async (i, index, collection) => {
return await dummy(i, 2);
}
);
console.log('Output is ', outputIndex);
// Output is 1
async function dummy(element) {
return Promise.resolve(element);
}
const inputArray = [1, 2, 3, 4];
const outputArray = [];
// Call ForEach method
await AsyncRay(inputArray).aForEach(async (i, index, collection) => {
outputArray.push(await dummy(i));
});
console.log('Output is ', outputArray);
// Output is [1, 2, 3, 4]
async function dummy(element) {
return Promise.resolve(element);
}
const inputArray = [1, 2, 3, 4];
// Call Map method
const mappedArray = await AsyncRay(inputArray).aMap(
async (i, index, collection) => {
// Dummy async function
return await dummy(i);
}
);
console.log(mappedArray);
// Output is [1, 2, 3, 4]
async function dummy(element) {
return Promise.resolve(element);
}
const inputArray = [10, 20, 30, 40];
// Call Reduce method
const output = await AsyncRay(inputArray).aReduce(
async (acc, i, index, collection) => {
return acc + (await dummy(i));
},
1
);
console.log('Output is ', output);
// Output is 101
async function dummy(element) {
return Promise.resolve(element);
}
const inputArray = [10, 20, 30, 40];
// Call Reduce method
const output = await AsyncRay(inputArray).aReduceRight(
async (acc, i, index, collection) => {
return acc + (await dummy(i));
},
1
);
console.log('Output is ', output);
// Output is 101
async function dummy(element, needle) {
return Promise.resolve(element > needle);
}
const inputArray = [10, 20, 30, 40];
// Call Some method
const output = await AsyncRay(inputArray).aSome(
async (i, index, collection) => {
// Dummy async function
return await dummy(i, 30);
}
);
console.log(output);
// Output is true
.aFilter
and .aMap
may be chained together.Make sure to put before each AsyncRay method call an await
(or call .then(...)
) since a Promise is returned by the async methods.
await(await AsyncRay([1,2,3])
.aFilter(...))
.Map(...)
.aEvery
, .aFilter
, .aFind
,.aFindIndex
, .aForEach
, .aMap
, aReduce
, aReduceRight
and .aSome
can be chained with other Array methods.
aMap
and filter
async function dummy(ele) {
return Promise.resolve(ele);
}
const inputArray = [1, 2, 3, 4];
const chainedValue = (await AsyncRay(inputArray).aMap(
async (ele) => await dummy(ele * 10)
)).filter((ele) => ele > 20);
console.log('Output is ', chainedValue);
// Output is [30, 40]
aMap
and find
async function dummy(ele) {
return Promise.resolve(ele);
}
const inputArray = [1, 2, 3, 4];
const chainedValue = (await AsyncRay(inputArray).aMap(
async (ele) => await dummy(ele * 10)
)).find((ele) => ele === 20);
console.log('Output is ', chainedValue);
// Output is 20
aMap
and reduce
async function dummy(ele) {
return Promise.resolve(ele);
}
const inputArray = [1, 2, 3, 4];
const chainedValue = (await AsyncRay(inputArray).aMap(
async (ele) => await dummy(ele * 10)
)).reduce((acc, ele) => acc + ele), 1);
console.log('Output is ', chainedValue);
// Output is 101
FAQs
Allow perform every, filter, find, findIndex, forEach, map, reduce, reduceRight and some on array using Async callback
The npm package async-ray receives a total of 365 weekly downloads. As such, async-ray popularity was classified as not popular.
We found that async-ray 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.