Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@antoniovdlc/reduce
Advanced tools
Custom reduce functions.
This package is distributed via npm:
npm install @antoniovdlc/reduce
Reducing arrays to a single value is a common operation in JavaScript. This library abstracts away some of the most common reduce operations.
You can use this library either as an ES module or a CommonJS package:
import { sum, average, groupBy } from "@antoniovdlc/reduce";
- or -
const { sum, average, groupBy } = require("@antoniovdlc/reduce");
All reduce functions can be used out of the box for computing single values as follows:
import { sum } from "@antoniovdlc/reduce";
const arr = [1, 2, 2, 13, 20, 4];
arr.reduce(sum); // 42
All reduce functions provide a .on("key")
function which allows to compute single values from arrays of objects by nested fields:
const arr = [
{ name: "Bob", age: 25 },
{ name: "Alice", age: 38 },
{ name: "Tom", age: 60 },
{ name: "Candice", age: 45 },
];
arr.reduce(average.on("age")); // 42
Note that if you are using TypeScript, you need to pass an initialization value:
arr.reduce(average.on("age"), 0); // 42
Here is a list of provided reduce functions:
Computes the sum of all the elements in an array.
Computes the average of all the elements in an array.
Generates an object from an array of objects, where the keys correspond to the values of the first argument, and the value corresponds to the object itself.
MIT
FAQs
Custom reduce functions.
The npm package @antoniovdlc/reduce receives a total of 7 weekly downloads. As such, @antoniovdlc/reduce popularity was classified as not popular.
We found that @antoniovdlc/reduce 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.