Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aggregate-base

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aggregate-base

Base class for aggregate operation, sush as http request, write file.

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
34
decreased by-8.11%
Maintainers
1
Weekly downloads
 
Created
Source

aggregate-base

Base class for aggregate operation, sush as http request, write file.

NPM version build status Test coverage David deps Known Vulnerabilities NPM download

Usage

npm i aggregate-base --save

You can wrap Class for aggregate operation, if you have a Logger that write log to file.

class Logger {
  info(log) {
    this.writeToFile(log);
  }

  writeToFile() {
    // your implementation
  }
}

However, it has bad performance that write file system every function call, so you can use this module to merge the operations.

const { wrap } = require('aggregate-base');

class Logger {
  info(log) {
    this.writeToFile(log);
  }

  flush(logs) {
    this.writeToFile(logs.join('\n'));
  }

  writeToFile() {
    // your implementation
  }
}

const WrapLogger = wrap(Logger, {
  interval: 1000,
  intercept: 'info',
  flush: 'flush',
});

The module will create a loop (configured by interval), it will collect data by intercepting the specified intercept method, and call flush method after interval with all collected data.

Options

  • interval: the time between flush
  • intercept: the intercept method name of class, the method will not be run.
  • interceptTransform: the function that can tranform the arguments of intercept method, if it return false, it won't cache this data
  • flush: the flush method name of class.
  • close: the close method name of class, it should be a async function.

License

MIT

FAQs

Package last updated on 26 Aug 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc