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.
Object aggregation for node! This lib will essentially combine objects so long as they are overlapping within a single process tick.
Node.js
var aggr = require('aggr')
Browser
<script src="aggr.min.js"></script>
namespace
- String namespace to prevent collisionsdata
- Data to aggregate, default type is object unless custom iterator
is usedoptions
- Change the default behavior of aggr (optional)callback
- Invoked when aggregation is completedextra
- custom callback to use in place of all callbacks after the first (default, false
)noop
- ignore all callbacks after the first (default, false
)iterator
- custom function to deal with each data aggregation (default, extend
)duration
- set a time duration for when to stop aggregating (default, 0)debounce
- if using duration, set to reset the timer each call (default, false
)If using a custom iterator
, note that the very first argument will be undefined
.
The default iterator
is an object extend function, and it is assumed that objects
are being passed in unless this option is set.
var ns = 'adding'
function add(a, b) {
// First execution, `a` === `undefined`
return (a || 0) + b
}
// This will be called 3 times with the final `total`
function done(total) {
// total === `10`
}
var opt = {iterator: add}
aggr(ns, 4, opt, done)
aggr(ns, 5, opt, done)
aggr(ns, 1, opt, done)
Sometimes only a single callback is needed, you can enable this behavior by passing
in noop
in the options, or an extra
function to handle this.
var ns = 'no-operations'
, opt = {noop: true}
// This function will only be called once
function done(all) {
// all === {one: 1, two: 2, three: 3}
}
aggr(ns, {one: 1}, opt, done) // Uses the callback
aggr(ns, {two: 2}, opt, done) // No operation callback
aggr(ns, {three: 3}, opt, done) // No operation callback
var ns = 'test'
// This will be called 4 times, one for each aggr call
function done(obj) {
// combined data sent to callback
// obj === {a: 'a', b: 'b', c: 10}
}
aggr(ns, {a: 'a'}, done)
aggr(ns, {b: 'b'}, done)
aggr(ns, {c: 'c'}, done)
aggr(ns, {c: 10}, done)
You can create a shortcut method to use for aggregation by using aggr.wrap
,
this will return a function that takes a single data
argument. By default
it has noop
set to true, which seems to make more sense since you only pass
a callback once.
// By default this will only be called once
function done(obj) {
// obj === {dark: 'coffee', is: 'good'}
}
var wrapped = aggr.wrap('lettuce', done)
wrapped({dark: 'coffee'})
wrapped({is: 'good'})
With npm
npm install aggr
(The MIT License)
Copyright (c) 2013 Beau Sorensen mail@beausorensen.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
Object aggregation for node
We found that aggr 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.